Page 1 of 1

1 second interupt and prescaler question

Posted: Tue Jul 21, 2009 7:54 pm
by DanDMan
I am using a 16hv616 chip and I want to have a counter that increments every second. I plan to use the internal oscillator, but flow code 4 does not have internal as an option in chip configure options... Is this a problem?

Re: 1 second interupt and prescaler question

Posted: Wed Jul 22, 2009 9:03 am
by Benj
Hello

PPP does list the internal oscillator as an option. Simply click Chip -> Configure in flowcode.

Next click the switch to expert mode button and you should be faced with the configuration settings for the 16F616 device.

Under Oscillator you have Internal RC No Clock or Internal RC Clockout.

Make sure that the code protect setting is set to off to avoid locking the program on your device.

Re: 1 second interupt and prescaler question

Posted: Wed Jul 22, 2009 12:36 pm
by DanDMan
Ok, thanks.

So now for the prescaler question. At 4 Mhz, the counters run at 1 Mhz correct?

Re: 1 second interupt and prescaler question

Posted: Wed Jul 22, 2009 4:03 pm
by Benj
Hello

If your prescaler is set to 1:1 then yes the PICmicro timers will run at 1/4 of the system clock, same as the program instruction rate.

Re: 1 second interupt and prescaler question

Posted: Wed Jul 22, 2009 9:32 pm
by DanDMan
I was looking at the sample code for a 1 second timer.

In the example the clock is 19660800 Hz , the scaler is 256 and in the interrupt counts to 75 then adds to the second counter.

19660800 / 4 / 256 = 19200 hz that the interrupt is called. It runs 75 times before the second is advanced. How exactly is that 1 second of time? Can anyone explain how this works.

If I run at 4 mhz then how do I made a seconds counter with an interupt?

Re: 1 second interupt and prescaler question

Posted: Thu Jul 23, 2009 8:27 am
by Benj
Hello Dan

You forgot the timer register of 256.

19660800 / 4 / 256 / 256 = 75Hz

For the 4MHz crystal you could do the following.

4000000 / 4 / 64 / 256 = 61.0352

This seems to be the closest to a whole number you can get when using a 4MHz clock.

Re: 1 second interupt and prescaler question

Posted: Thu Jul 23, 2009 8:29 am
by Benj
This website is quite useful for calculating timer periods etc.

http://eng-serve.com/pic/pic_timer.html

Re: 1 second interupt and prescaler question

Posted: Thu Jul 23, 2009 1:16 pm
by DanDMan
I knew I was missing something! Thank you I "got" it now.