how to chain timers

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

how to chain timers

544 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by kevin_liu on Mon Jul 28 16:55:10 MST 2014
Hi,

I am trying to chain 2 timers together in my code: let timer2 to take timer1's match output. However, I cannot get it work.  The following is my code.

I can get each timer work independently,

by toggling the lines controlling timer1 interrupt:
Chip_TIMER_MatchDisableInt(LPC_TIMER1, 3);
//Chip_TIMER_MatchEnableInt(LPC_TIMER1, 3);

and commenting out the line
  Chip_TIMER_TIMER_SetCountClockSrc(LPC_TIMER2, TIMER_CAPSRC_RISING_CAPN, 3);
  
However, I cannot chain them together.

/* Setup a chained timer. Timer2 will take input from Timer1's match 3.*/
static void setupChainTimer(void) {
Chip_TIMER_Init(LPC_TIMER1);
Chip_RGU_TriggerReset(RGU_TIMER1_RST);
while (Chip_RGU_InReset(RGU_TIMER1_RST)) {
}

Chip_TIMER_PrescaleSet(LPC_TIMER1, 0);

Chip_TIMER_Reset(LPC_TIMER1);
Chip_TIMER_ClearMatch(LPC_TIMER1, 3);
Chip_TIMER_SetMatch(TIMER_NUMBER, 3, 4);
Chip_TIMER_ResetOnMatchEnable(LPC_TIMER1, 3);
Chip_TIMER_MatchDisableInt(LPC_TIMER1, 3);
//Chip_TIMER_MatchEnableInt(LPC_TIMER1, 3);

Chip_TIMER_Enable(LPC_TIMER1);
NVIC_EnableIRQ(TIMER1_IRQn);
NVIC_ClearPendingIRQ(TIMER1_IRQn);

Chip_TIMER_Init(LPC_TIMER2);
Chip_RGU_TriggerReset(RGU_TIMER2_RST);
while (Chip_RGU_InReset(RGU_TIMER2_RST)) {
}

LPC_GIMA->CAP0_IN[2][3] = 0x1<<1|0x1<<2|0x2<<4;

Chip_TIMER_Reset(LPC_TIMER2);
Chip_TIMER_TIMER_SetCountClockSrc(LPC_TIMER2, TIMER_CAPSRC_RISING_CAPN, 3);
Chip_TIMER_ClearMatch(LPC_TIMER2, 1);
Chip_TIMER_SetMatch(LPC_TIMER2, 1, 1);
Chip_TIMER_MatchEnableInt(LPC_TIMER2, 1);
Chip_TIMER_ResetOnMatchEnable(LPC_TIMER2, 1);
Chip_TIMER_Enable(LPC_TIMER2);

NVIC_EnableIRQ(TIMER2_IRQn);
NVIC_ClearPendingIRQ(TIMER2_IRQn);
}

//*****

void TIMER1_IRQHandler(void) {
static bool On = false;
static int count = 0;
count++;
if (Chip_TIMER_MatchPending(LPC_TIMER1, 3)) {
Chip_TIMER_ClearMatch(LPC_TIMER1, 3);
On = (bool) !On;
Board_LED_Set(6, On);
}
}

void TIMER2_IRQHandler(void) {
static bool On = false;
static int count = 0;
count++;

if (Chip_TIMER_MatchPending(LPC_TIMER2, 1)) {
Chip_TIMER_ClearMatch(LPC_TIMER2, 1);
On = (bool) !On;
Board_LED_Set(5, On);
}
}
Labels (1)
0 Kudos
1 Reply

444 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Pacman on Sun Aug 31 01:25:59 MST 2014
Sorry for the late reply.
Just something that came to mind: I think you may need to hardwire them.
Or try using T3_MAT0 and CTIN_1 or T3_MAT1 and CTIN_0 or T3_MAT2 and CTIN_2. I believe setting the pin function to be T3_MAT1 might work.
-I have no idea if this will work, just a thought.
0 Kudos