|
|
View previous topic :: View next topic |
Author |
Message |
art
Joined: 21 May 2015 Posts: 181
|
EX_STWT1.C questions |
Posted: Fri Jul 14, 2017 11:38 pm |
|
|
Hi,
I'm trying to understand EX_STWT1.C example.
1) I would like to know why the value for INTS_PER_SECOND is 19 ?
Code: |
#define INTS_PER_SECOND 19 // (20000000/(4*4*65536))
|
2) What does it mean by (4*4*65536) ? What does 4*4 means ?
3) If I change the clock=48000000 , Is the INTS_PER_SECOND = (48000000/(4*4*65536)) =45.77 ?
4) Timer 1 overflow value is it fixed to 65535 ? Can we change it to other value ?
Code: |
#INT_TIMER1 // This function is called every time
void clock_isr() { // timer 1 overflows (65535->0), which is
// approximately 19 times per second for
if(--int_count==0) { // this program.
++seconds;
int_count = INTS_PER_SECOND;
}
}
|
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19496
|
|
Posted: Sat Jul 15, 2017 1:09 am |
|
|
4*4 is 4 times 4.....
If you read the PIC data sheet, you will find that on the standard PIC's, the 'timer' is fed from Fosc/4 (master oscillator/4). There is then a programmable 'prescaler'. This is set to /4 (T1_DIV_BY_4). The timer then counts 65536.
No, you can't change the overflow value on these timers. There are things you can do, like set the timer 'forwards', but they all introduce slight errors. Timer2, has a programmable overflow, larger prescalers, and a postscaler, so if you are not using the PWM, this is a great way of having a timer at a 'human nice' interval.
Look in the code library. There is an accurate RTC there, that shows how you can still have an accurate time with timers counting with odd values like 45.776* per second. Yes, this is how often the interrupt would tick with a 48Mhz master clock.
<http://www.ccsinfo.com/forum/viewtopic.php?t=26177> |
|
|
art
Joined: 21 May 2015 Posts: 181
|
|
Posted: Sat Jul 15, 2017 4:34 am |
|
|
Dear Ttelmah
Thanks for the explanation. |
|
|
|
|
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
|
Powered by phpBB © 2001, 2005 phpBB Group
|