Content originally posted in LPCWare by expressouser on Sat Jul 12 05:29:17 MST 2014
Hi,
I am having some problem with TIMER, PCLK divider doesn't seem to work. Even if I set the pclk divider to a value different than that of the default value, it seems like the timer uses the default value.
Here is the part where I configure the timer:
pclk_tick = ((double) 1/ ( SystemFrequency/4) ) * 1000; //ms per PCLK tick. SystemFrequency is at 100MHz.
// pclk_tick = ((double) 1/ ( SystemFrequency) ) * 1000; // this part doesnt work.
counter = ((uint32_t) timer->interval) / pclk_tick ;//desired timer interval, in ms, in my code, this is 1.
PowerUp_Peripheral(PCTIMER0);
//Set_Bit(&(LPC_SC->PCLKSEL0), 2); Clear_Bit(&(LPC_SC->PCLKSEL0), 3); //This part doesnt work.
LPC_TIM0->PR = counter; //this will increment the TC everytime the timer->interval expires.
LPC_TIM0->CTCR &= ~(0x3); //TIMER MODE.
and here's the part where I am 'waiting for a delay':
void wait_for_timer(int whichTimer, uint32_t howLong) {
switch (whichTimer) {
case (TIMER_0):
LPC_TIM0->TCR = 0x03;
LPC_TIM0->TCR &= ~(1 << 1);
while (LPC_TIM0->TC != howLong);
LPC_TIM0->TCR = 0x00;
break;
.......
.......
}
So if I say:
wait_for_timer(TIMER_0, (1000 * 60) ) ;
with PCLK = 0 , (that is dividided by 4), the function returns after 1 minute.
but with PCLK = 1 (that is divided by 1, and with all those parts of the code marked as this part doesn't work), the function returns after 4 minutes (looks like PCLK is still divided by 4).
Any idea what am I doing wrong?
I dont see this problem in RIT.
Thanks.