PIC Timer interrupt calculation

Any bugs you encounter with Flowcode should be discussed here.
Post Reply
mnfisher
Valued Contributor
Posts: 938
http://meble-kuchenne.info.pl
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 104 times
Been thanked: 502 times

PIC Timer interrupt calculation

Post by mnfisher »

There seems to be an error in the Timer interrupt frequency calculation.

I created a small test program - using a pic16lf15313 running at 32MHz. I have a LED on a4 (with a current limiting resistor of course)

The Interrupt enable specifies a frequency of 1953Hz - but as can be seen from the check at the end - the frequency is ~8000Hz (actually it's its slightly > 8000 set check to 7800 - 8100 to light the LED!)

Modifying source to FOsc / 4 gives the same 'calculated' rate - and the correct rate in hardware.
timer.fcfx
(9.23 KiB) Downloaded 66 times
Edit - it's probably just that fosc /hfintosc options shouldn't be offered?

Martin

BenR
Matrix Staff
Posts: 1707
Joined: Mon Dec 07, 2020 10:06 am
Has thanked: 435 times
Been thanked: 598 times

Re: PIC Timer interrupt calculation

Post by BenR »

Hi Martin,

Hmm that's strange maybe something for us to explore in the executable. Here is the XML from the definition file for timer 2 and it seems to be setting the clock divider (clkdiv) correctly to 0 when the selected source clock speed is unknown. Maybe Flowcode is incorrectly assuming a clkdiv of 0 is actually a clkdiv of 4.

Hmm even the clkdiv of 1 isn't working. Very odd I'll chase this up.

Code: Select all

                <option name='Clock Source Select' >
                    <entry name='Transition on T2CKI pin' clkdiv='0' value='T2CLKCON = 0;\n' />
                    <entry name='Internal clock (Fosc/4)' clkdiv='4' value='T2CLKCON = 1;\n' />
                    <entry name='Internal clock (Fosc)' clkdiv='1' value='T2CLKCON = 2;\n' />
                    <entry name='HFINTOSC' clkdiv='0' value='T2CLKCON = 3;\n' />
                    <entry name='LFINTOSC' clkdiv='0' value='T2CLKCON = 4;\n' />
                    <entry name='MFINTOSC 500KHz' clkdiv='0' value='T2CLKCON = 5;\n' />
                    <entry name='MFINTOSC 31.25KHz' clkdiv='0' value='T2CLKCON = 6;\n' />
                    <entry name='SOSC' clkdiv='0' value='T2CLKCON = 7;\n' />
                </option>

Steve-Matrix
Matrix Staff
Posts: 1234
Joined: Sat Dec 05, 2020 10:32 am
Has thanked: 167 times
Been thanked: 277 times

Re: PIC Timer interrupt calculation

Post by Steve-Matrix »

I've looked into this and it appears that the "clkdiv" override on the clock source entries in the FCD are totally ignored by Flowcode and instead the "master_divider" entry is used.

There is no simple fix. I'll add it to my list to investigate, and hopefully there will be a fix in a future release of Flowcode.

Steve-Matrix
Matrix Staff
Posts: 1234
Joined: Sat Dec 05, 2020 10:32 am
Has thanked: 167 times
Been thanked: 277 times

Re: PIC Timer interrupt calculation

Post by Steve-Matrix »

A quick update on this. I have fixed this issue and it will be fixed once v10 has been released. We expect this release before the year end.

Post Reply