Page 1 of 1

Pic16F18855, Timer2 and IT

PostPosted: Sun Mar 05, 2023 4:53 pm
by Scrubb
Hi all
Lets's say that I need an IT every 100us....
I've decided to use Timer 2 and from what I understand , If you use a Timer with a clock frequency of 1Mhz, you only need to count up to 100 provided you've loaded the 8 bit counter ( no pre and post scalers ) to 256-100
Due to the extra clock cycle, you need to count 99...

Consequently I have configured ( with MCC ) with the following
Fosc (1Mhz, pre and Post scallers 1:1, PR2 = 99, T2TMR= 156 , Global an Peripheral Interrupts validated, Interrupt validated...
In order to see the effect of the Interrupt, each time an IT arrives, I generate a small 5us pulse, pulsing High an Low a Pin of the Pic16F...

This works nicely...but instead of having an IT each 100us, it is an IT each ~200us and I clearly don't see why...and where I make a mistake

I've tried the callback capability...with a Callback freq of 1...i.e a callback evevry 100us
Moved my ISR the the right place..
Works nicely too...but, same stuff, an IT every 200 us instead of 100us
Could someone tell me where I'm goofing ?
Ths in advance

Re: Pic16F18855, Timer2 and IT

PostPosted: Mon Mar 06, 2023 3:02 am
by AussieSusan
Can you show us your code (preferably a small but complete ap that demonstrates just the problem)?
Also what is an 'IT'?
Susan

Re: Pic16F18855, Timer2 and IT

PostPosted: Tue Mar 07, 2023 12:05 pm
by ric
AussieSusan wrote:...
Also what is an 'IT'?
Susan

Almost certainly a self made-up abbreviation for "interrupt"

If your interrupt service is reloading the timer with 156 in every interrupt, that is the source of the error.
It should be left alone, so the timer can count from 0 to 99, when the PR2 valiue will trigger an interrupt and reset it to zero again.