1 second interupt and prescaler question

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

Post Reply
DanDMan
Posts: 11
Joined: Wed Jul 15, 2009 8:28 pm

1 second interupt and prescaler question

Post 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?

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: 1 second interupt and prescaler question

Post 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.

DanDMan
Posts: 11
Joined: Wed Jul 15, 2009 8:28 pm

Re: 1 second interupt and prescaler question

Post by DanDMan »

Ok, thanks.

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

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: 1 second interupt and prescaler question

Post 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.

DanDMan
Posts: 11
Joined: Wed Jul 15, 2009 8:28 pm

Re: 1 second interupt and prescaler question

Post 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?

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: 1 second interupt and prescaler question

Post 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.

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: 1 second interupt and prescaler question

Post by Benj »

This website is quite useful for calculating timer periods etc.

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

DanDMan
Posts: 11
Joined: Wed Jul 15, 2009 8:28 pm

Re: 1 second interupt and prescaler question

Post by DanDMan »

I knew I was missing something! Thank you I "got" it now.

Post Reply