I tried to count the second but its not working.
I just take a look on some examples that is given in the CCS compiler but my program does not count the second properly. It becomes slow.
How can I count the exact value for ...
INTS_PER_SECOND
???
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
Posted: Sun Jul 12, 2009 7:26 am
You didn't mention which CCS example program you used as a starting point but searching the directory I found only ex_stwt.c to have INTS_PER_SECOND defined as 76.
Now, if you look into the program you will see the following line:
Where:
- 20000000 is the clock speed of the processor
- 4 is the number of clocks to execute a single instruction. Always 4 for the PIC10 to PIC18 processors.
- The last two numbers 256 come from the line:
- An 8 bit counter counts up to 256 before restarting at 0.
- A post divider of 256 decreases the number of interrupts by 256.
Assuming you have an 8MHz clock your calculation for the number of interrupts would become:
8000000 / (4 * 256 * 256) = 30.51
Set the number of interrupts to 30 or 31. You will get an error of 1.6% or 23 minutes/day. For most applications this is no problem.
For higher accuracy you could change the post divider to 128, this will give you:
8000000 / (4 * 256 * 128) = 61.04
Setting the number of interrupts per second to 61 reduces the error to 0.04% = 56seconds/day.
Depending on your actual clock rate you can play a bit with the numbers to get a more exact clock but I recommend to keep the number of interrupts below 200 or the interrupt overhead will become too high.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum