Community
cancel
Showing results for 
Search instead for 
Did you mean: 
978 Views

Quark D2000 Timers

I've been having an issue trying to get 2 Timers on the D2000 CRB working at the same time. I can get either working independently but not both together. I've based my code on the QMSI 1.1 BSP samples. The code acts as though an interrupt is missing. Below is a code snippet which demonstrates the issue I'm having. Any suggestions would be greatly appreciated.

int main(void) {

InitializeTimer0();

qm_pwm_start(QM_PWM_0, QM_PWM_ID_0);

InitializeTimer1();

qm_pwm_start(QM_PWM_0, QM_PWM_ID_1);

return 0;

}

static void timerCB0() {

static int ticks = 0;

QM_PRINTF("Timer0-%d\n", ticks++);

}

static void timerCB1() {

static int ticks = 0;

QM_PRINTF("Timer1-%d\n", ticks++);

}

static void InitializeTimer0(void) {

qm_pwm_config_t wr_cfg;

wr_cfg.hi_count = 0x2000000;

wr_cfg.lo_count = 0x2000000;

wr_cfg.mode = QM_PWM_MODE_TIMER_COUNT;

wr_cfg.mask_interrupt = false;

wr_cfg.callback = timerCB0;

wr_cfg.callback_data = NULL;

clk_periph_enable(CLK_PERIPH_PWM_REGISTER | CLK_PERIPH_CLK);

qm_pwm_set_config(QM_PWM_0, QM_PWM_ID_0, &wr_cfg);

qm_irq_request(QM_IRQ_PWM_0, qm_pwm_isr_0);

}

static void InitializeTimer1(void) {

qm_pwm_config_t wr_cfg;

wr_cfg.hi_count = 0x2000000;

wr_cfg.lo_count = 0x2000000;

wr_cfg.mode = QM_PWM_MODE_TIMER_COUNT;

wr_cfg.mask_interrupt = false;

wr_cfg.callback = timerCB1;

wr_cfg.callback_data = NULL;

clk_periph_enable(CLK_PERIPH_PWM_REGISTER | CLK_PERIPH_CLK);

qm_pwm_set_config(QM_PWM_0, QM_PWM_ID_1, &wr_cfg);

qm_irq_request(QM_IRQ_PWM_0, qm_pwm_isr_0);

}

0 Kudos
1 Reply
91 Views

I believe that I've found the answer to my question in the data sheet. It looks like there's only a single Timer Interrupt so the callback has to check which timer fired, ex:

static void timerCB(void *data, uint32_t timer_int) {

static int ticks0 = 0;

static int ticks1 = 0;

if (timer_int & BIT(QM_PWM_ID_0)) {

QM_PRINTF("Timer0-%d\n", ticks0++);

}

if (timer_int & BIT(QM_PWM_ID_1)) {

QM_PRINTF("Timer1-%d\n", ticks1++);

}

}

Sadly this means that if you have separate, totally unrelated pieces of code each using a different Timer they need to share a common callback routine.

Reply