timer16 counts

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

timer16 counts

1,809 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by tbelo on Fri Jan 03 00:56:28 MST 2014
Hi all,

I have used the "selfwakeup" example which uses the TIMER16B0_MAT0.
For my application I need 86400 counts but timer16 can only count 2^16=65536.

Will the PC (prescale counter) do that job or should I use the TIMER32B0_MATx ?

Best regards,
Theodore


Below is the code for Timer16 Driver for the self wake up example.
/* Turn on 16-bit Timer 0 and IOCON, in case it hasn't already been turned on */
LPC_SYSCON->SYSAHBCLKCTRL|=(1<<7) | (1<<16);

/* Disable and Reset Timer */
LPC_TMR16B0->TCR = (1<<1);

/* Setup Timer prescaler */
LPC_TMR16B0->PR=prescaler;

/* Match Reg 0: Interrupt Disabled, Reset Enabled, Do not Stop */
LPC_TMR16B0->MCR =(1<<1);

/* Match Reg 0 value */
LPC_TMR16B0->MR0 =match;

/* External Match; Clear output and set on match */
LPC_TMR16B0->EMR =(0x2<<4);

/* Enable MAT0 onto IOCON: CT16BO_MAT0: PIO0_8 */
LPC_IOCON->PIO0_8 = (2<<0);
Labels (1)
0 Kudos
Reply
6 Replies

1,795 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by tbelo on Thu Jan 09 04:39:00 MST 2014
Hi,

Before I read through your calculations I need to remind you the use of deep-sleep mode (self-wakeup example) where the watchdog oscillator can be active and not the IRC.

Best regards,
Theodore
0 Kudos
Reply

1,795 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by MarcVonWindscooting on Wed Jan 08 16:04:11 MST 2014
Hi Theodore,

I understand your calculation. Yet you have the theoretical (?) +- 40% WDOSC (in)accuracy.

You don't have to put up with that, assume 12MHz IRC:
Maximum system clock prescaler = 255 => 47.059..kHz
Maximum 16bit PR=65535 => 0.72..Hz (The true max is 65536 I admit)
1 day * 0.72..Hz = 62041.4..  (<=65535)
Calculation error < 9ppm.

That means, you may use the IRC (accuracy +- 1.5%) and still be able to use the 16-bit timer for a precise 1 day
interrupt by selecting SYSAHBCLKDIV=255, PR=65535, MR0=62041-1.

However, now I can see, there is a problem of using the 16-bit timer: I limits the system clock to something around 50kHz at most. That may be advantageous in terms of power consumption but on the other hand limits your peak computing power. It is easily increased by setting SYSAHBCLKDIV=1 which in turn taints the 16-bit clock within a few seconds if not turned off.
If you did use a 32-bit timer you were free in choosing system clock between 47kHz and full speed.

But honestly, alarms in the range of hours don't need a pure hardware solution, do they? A software 32bit value + an increment by a ISR every second would provide more than enough range and precision. It allows to run the core at full or reduced speed, yet you would prefer the to sleep in between the interrupts thus considerably lowering power consumption - let's say - by 50%. And your peripherals are still active!

EDIT: I just calculated what 1.5% means: 21.6minutes / day. Pretty much |(
That system would not be usable as an alarm clock at all for waking up the programmer in the morning in order to go to work. What a pity!
0 Kudos
Reply

1,795 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by tbelo on Mon Jan 06 12:18:58 MST 2014
Hi,

If beforehand I have -24% error means 24 hrs-24% ~= 5,76 hrs.
The next time I will activate the timer I will need +5,76 hrs to equilibrate the error. Means that I will need 24%+24% count times.

I think that the +-40% WDOSC inaccuracy is a big problem. Don't make it harder with timer restrictions.

Anyway my 24 hrs self wake-up test end-up with 23:45 which is acceptable.
Of course the power supply  was stable and with room temperature.

Best regards,
Theodore
0 Kudos
Reply

1,795 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by MarcVonWindscooting on Mon Jan 06 06:28:43 MST 2014
WDOSC is very inaccurate +-40%. :O

86400 * (100% - 40%) / 100% = 51840 < 65536.

or the other way round:

65536 = 86400 - 24%

So why bother about the limitation of MR0 (65536) if you're willing to use a timer, that generates a much greater error?
Pretty questionable.
0 Kudos
Reply

1,795 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by tbelo on Sun Jan 05 11:25:23 MST 2014
Thanks for your reply but after tests I came to the following:

with wdt oscillator setup as     LPC_SYSCON->WDTOSCCTRL = (0x1<<5) | 0x1F;
timer16B0 max count is 2^16=65536
with PR=65535 and MR0=1      I get ~5,5 seconds
with PR=55833 and MR0=10    I get 60 seconds

So this way I managed to have 1 day with PR=55833 and MR0=14400.

I currently test it not to overflow.
I will come with the results...

Best regards,
Theodore
0 Kudos
Reply

1,795 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by MarcVonWindscooting on Fri Jan 03 15:11:54 MST 2014
Hi Theodore,

yes the prescaler will do the trick, as long as 86400/(PR+1) is an integral number.
Otherwise you will get a small error - if that matters at all.
86400 sound like one day, measured in seconds, so I would use PR=60-1, MR0=24*60
or PR=3600-1, MR0=24 in your case ;-)
0 Kudos
Reply