CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

EX_STWT1.C questions

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
art



Joined: 21 May 2015
Posts: 181

View user's profile Send private message

EX_STWT1.C questions
PostPosted: Fri Jul 14, 2017 11:38 pm     Reply with quote

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: 19195

View user's profile Send private message

PostPosted: Sat Jul 15, 2017 1:09 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Jul 15, 2017 4:34 am     Reply with quote

Dear Ttelmah

Thanks for the explanation.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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