Pic16F18855, Timer2 and IT

Pic16F18855, Timer2 and IT

Postby Scrubb » Sun Mar 05, 2023 4:53 pm

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
Scrubb
 
Posts: 1
Joined: Sun Mar 05, 2023 4:29 pm

Re: Pic16F18855, Timer2 and IT

Postby AussieSusan » Mon Mar 06, 2023 3:02 am

Can you show us your code (preferably a small but complete ap that demonstrates just the problem)?
Also what is an 'IT'?
Susan
AussieSusan
Verified identity
 
Posts: 173
Joined: Mon Jun 16, 2014 4:45 am
PIC experience: Experienced Hobbyist

Re: Pic16F18855, Timer2 and IT

Postby ric » Tue Mar 07, 2023 12:05 pm

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.
Latest test project, an LED matrix display made from one reel of addressable LEDs. here
User avatar
ric
Verified identity
 
Posts: 659
Joined: Sat May 24, 2014 2:35 pm
Location: Melbourne, Australia
PIC experience: Professional 5+ years with MCHP products


Return to Timers

Who is online

Users browsing this forum: No registered users and 4 guests

cron