Page 1 of 1
New Project interrupt timer slow
Posted: Sat Feb 17, 2024 11:45 pm
by ianjoh
This is a new PIC to me, an upgrade from my usual 16F688 so the I can make use of the PWM function.
However I am unable to get the interrupt timer in the properties faster then 15Hz with a 4Mhz HS external crystal. I am looking for around 1kHz.
Have I got a setting wrong somewhere?
Before i get too far I will also confirm the timings with a flashing LED when I get the PIC soldered on the board.
Thanks
Re: New Project interrupt timer slow
Posted: Sun Feb 18, 2024 12:19 am
by chipfryer27
Hi
I don't have the datasheet for your chip to hand so can't comment on Timer0 capabilities.
However you could use Timer2 set for Internal Clock (Fosc) with prescaler set at 1:16 and rollover to 250 to give you a 1KHz interrupt. Test in hardware though.
Regards
Re: New Project interrupt timer slow
Posted: Sun Feb 18, 2024 6:00 am
by chipfryer27
Hi
Heading out soon, sorry to brief.
I had a very quick look at the datasheet and it appears that Timer0 can operate in either 8 or 16-bit mode. The timer can also run synchronous or asynchronous to selected source. When synchronous it is set as Fosc/4.
It appears that Timer0 is set to 16-bit mode (I don't see a way to change this in Properties) and it also appears to be set at Synchronous (Fosc/4) irrespective of settings (Sync / Async) in Timer0 Properties.
This means you would interrupt at :-
16-bit x scaler x (1 /( Fosc / 4 )) = 65535 x 1 x (1 / (4000000 / 4) = 0.06535 = 15.259Hz
If you could actually change to Asynchronous you could get a potential 4 x improvement giving a frequency of roughly 61Hz, which although better still falls far short of requirement. However if FC allowed you to run Timer0 in 8-bit mode you would then have interrupt frequencies of roughly 3921Hz / 15686Hz for sync / async.
I don't know if any of the above constitutes a "bug", not seeming to accept asynchronous etc, or if I have misunderstood (quite possibly, it is very early

) but running using Timer2 as per previous post gives you your 1KHz interrupt.
Regards
Edit
Actually if you use the internal PWM component it only offers you timer2/4/6 as options and you can easily set for 1KHz
Re: New Project interrupt timer slow
Posted: Sun Feb 18, 2024 8:23 pm
by ianjoh
Ah thank you! A perfect answer.
I got a bit bamboozled by the sheer amount of options with selecting frequency modes, lots to learn.
Re: New Project interrupt timer slow
Posted: Sun Feb 18, 2024 9:41 pm
by chipfryer27
Hi
Some of the chips can be quite frightening in their configuration, many times I've overlooked something simple
The one second flasher test really is your best friend when working with a new chip, but unfortunately often forgotten, and the WiKi is a helpful resource for most components / features, giving easy to follow examples.
Regards