Hi,
I'm using Mbed and trying to use CAP2.0 events (rising and falling edges) to increment timer2, instead of the PCLK rising edge. I've connected an external signal to pin p30 (CAP2.0/p0.4). I've configured register CTCR according to user manual, but it still doesn't work. Am I missing anything?
It's rather hard to debug using Mbed so I'm reseting the counter every 108 usec (using PWM interrupt- which works perfectly) and sending the value timer2 TC register using serial comunication. the results are showing that the PCLK is still used to increment the TC.
here's my code, I also used CMSIS package functions:
//Config P0.4 and P0.5 as CAP2.0,CAP2.1
PinCfg.Funcnum = 3;
PinCfg.OpenDrain = 0;
PinCfg.Pinmode = 0;
PinCfg.Portnum = 0;
PinCfg.Pinnum = 4;
PINSEL_ConfigPin(&PinCfg);
PinCfg.Pinnum = 5;
PINSEL_ConfigPin(&PinCfg);
//config timer2 for capture int counter mode
CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCTIM2, ENABLE); //enable timer 2 clk
CLKPWR_SetPCLKDiv (CLKPWR_PCLKSEL_TIMER2, CLKPWR_PCLKSEL_CCLK_DIV_1); //select PCLK=72MHz
LPC_TIM2->TC =0;
LPC_TIM2->PC =0;
LPC_TIM2->PR =0;
LPC_TIM2->CTCR = 0x3;//
TIM_ResetCounter(LPC_TIM2);
TIM_Cmd(LPC_TIM2,ENABLE);
Any ideas?
Hi,
I'm using Mbed and trying to use CAP2.0 events (rising and falling edges) to increment timer2, instead of the PCLK rising edge. I've connected an external signal to pin p30 (CAP2.0/p0.4). I've configured register CTCR according to user manual, but it still doesn't work. Am I missing anything?
It's rather hard to debug using Mbed so I'm reseting the counter every 108 usec (using PWM interrupt- which works perfectly) and sending the value timer2 TC register using serial comunication. the results are showing that the PCLK is still used to increment the TC.
here's my code, I also used CMSIS package functions:
//Config P0.4 and P0.5 as CAP2.0,CAP2.1
PinCfg.Funcnum = 3;
PinCfg.OpenDrain = 0;
PinCfg.Pinmode = 0;
PinCfg.Portnum = 0;
PinCfg.Pinnum = 4;
PINSEL_ConfigPin(&PinCfg);
PinCfg.Pinnum = 5;
PINSEL_ConfigPin(&PinCfg);
//config timer2 for capture int counter mode
CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCTIM2, ENABLE); //enable timer 2 clk
CLKPWR_SetPCLKDiv (CLKPWR_PCLKSEL_TIMER2, CLKPWR_PCLKSEL_CCLK_DIV_1); //select PCLK=72MHz
LPC_TIM2->TC =0;
LPC_TIM2->PC =0;
LPC_TIM2->PR =0;
LPC_TIM2->CTCR = 0x3;//
TIM_ResetCounter(LPC_TIM2);
TIM_Cmd(LPC_TIM2,ENABLE);
Any ideas?