New Project interrupt timer slow

For general Flowcode discussion that does not belong in the other sections.
Post Reply
ianjoh
Posts: 5
http://meble-kuchenne.info.pl
Joined: Sat Jan 30, 2021 3:42 pm

New Project interrupt timer slow

Post 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
Attachments
new sounder.fcfx
(7.18 KiB) Downloaded 11 times

chipfryer27
Valued Contributor
Posts: 1147
Joined: Thu Dec 03, 2020 10:57 am
Has thanked: 285 times
Been thanked: 412 times

Re: New Project interrupt timer slow

Post 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

chipfryer27
Valued Contributor
Posts: 1147
Joined: Thu Dec 03, 2020 10:57 am
Has thanked: 285 times
Been thanked: 412 times

Re: New Project interrupt timer slow

Post 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

ianjoh
Posts: 5
Joined: Sat Jan 30, 2021 3:42 pm

Re: New Project interrupt timer slow

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

chipfryer27
Valued Contributor
Posts: 1147
Joined: Thu Dec 03, 2020 10:57 am
Has thanked: 285 times
Been thanked: 412 times

Re: New Project interrupt timer slow

Post 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

Post Reply