TIMER16 Prescale Error

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

TIMER16 Prescale Error

294 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by jagweb on Sat Mar 31 06:12:54 MST 2012
This is my first post so please be gentle.  I have been working with the 16 bit timers using the LPC1114 and the driver library provided in version 4.2.0 Build 264.  My timing was off by around 2% and was having some difficulty finding the root cause.  I searched way too long to find out it was an off by one error.  The problem is with the MHZ_PRESCALE define in the timer16.h driver code.  When you set the prescaler to 48 you are actually dividing by 49 because the prescaler by design is off by 1.   so the define should be (TIMER _CLOCKFREQ/1000000-1).  I really hope this helps someone else. It would be nice to see this fix incorporated on the next version or build. 

In general, I think the LPCXpresso is a great tool :) and appreciate free tools for evalution and small projects.  The example projects are nice and get you running very fast.  My general impression of the M0 parts is they are simple to use (this is not always the case with other vendors).  Keep up the good work.
0 Kudos
6 Replies

280 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by researchinnovation on Thu Apr 12 02:09:22 MST 2012
[SIZE=4][B][COLOR=Blue]Hi...!!!
I want to take/read file(.txt format doc format) continuously as an input for one of my application on I2C.
But when I use FILE *file and file =fopen("filename.txt","r"); it is   showing error and I tried few more things but it is showing error.
I have used #include "debug_printf.h" , #include "stdlib.h" and other required driver files, but still error is coming.

Please guide me on this or share any document available on c functions for LPCxpresso.

Thanks....:)[/COLOR][/B][/SIZE]
0 Kudos

280 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Sun Apr 08 04:30:59 MST 2012
Link of #3 in this thread shows an example :)

It's generating a 1 microsecond Interrupt at 48MHz with prescaler 48 :eek:

So what do you think, can you try to calculate a solution yourself?
0 Kudos

280 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by galih on Sun Apr 08 03:12:07 MST 2012
Hi, all.

How to set Timer16 Prescale value and MR0 value to get 1 second (from start until interrupt)?
Thanks.
0 Kudos

280 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Rob65 on Sat Mar 31 12:26:27 MST 2012
No idea what I did just a few hours ago ...

0 == div by 1
1 == div by 2

so indeed there should be a -1.
A simple formula in the user manual instead of the descriptive text would explain this much nicer ( Timer clock = PCLK / (PR + 1) )

I'm not sure if this will be fixed in the next version.
There have been multiple 'bug fixes' in other drivers and examples that are still not implemented in the new examples.

As you figured out by now: never trust the examples (or an engineer telling you they are correct ;)).

Still LPCXpresso (the eclipse IDE with compiler and debugger) is indeed a great tool and the LPCXpresso boards are great targets to start development and for most applications you don't need anything else.
But take care when using the LPCXpresso examples: these are mainly delivered 'as is' - they do work but may include some 'bugs' like a slightly wrong timing, no error handling etc.
Use them as examples to base your own drivers and application code on and you'll find them quite handy.

Regards,[INDENT]Rob
[/INDENT]
0 Kudos

280 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Sat Mar 31 07:23:08 MST 2012

Quote: jagweb
This is my first post so please be gentle. :)



Of course you are right :), a lot of samples here show the same prescale setting:

http://knowledgebase.nxp.com/showthread.php?t=2815
0 Kudos

280 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Rob65 on Sat Mar 31 07:10:41 MST 2012
welcome,

why do you think the prescaler is by design offset by 1 ?

If I read the user manual (section 15.7.5 Prescale Counter) I read:

Quote:

When it reaches the value stored in the Prescale Register,
the Timer Counter is incremented, and the Prescale Counter is reset on the next PCLK.
This causes the TC to increment on every PCLK when PR = 0, every 2 PCLKs when
PR = 1, etc.



So there is no offset by 1 as far as I can see. With a 12 MHZ clock setting the prescaler to 12 will divide by 12 resulting in a 1 MHz resolution of the timer.
But I could be wrong - it's been a while since I've actually used my lpc1114 board.

Regards,
[INDENT]Rob
[/INDENT]
0 Kudos