Timer0

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 8.

Moderator: Benj

Post Reply
User avatar
Jan Lichtenbelt
Posts: 797
Joined: Tue Feb 17, 2009 8:35 pm
Location: Haren GN, the Netherlands
Has thanked: 128 times
Been thanked: 264 times
Contact:

Timer0

Post by Jan Lichtenbelt »

I use the Timer0 with a very low frequency of 134 seconds. In the simulation it works fine, but with the microchip I get only 2 seconds, see flowcode.
Test_Timer0_V1.fcfx
(11.92 KiB) Downloaded 257 times
Who can help me?

Kind regards

Jan

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Timer0

Post by Benj »

Hi Jan,

Hmm the generated code looks ok to me.

Code: Select all

    // Name: Interrupt 134 seconds, Type: Interrupt: Enable TMR0
    T0CON1 = (T0CON1 & 0x1F) | 0x40;
    st_bit(T0CON1,T0ASYNC);
    T0CON1 = (T0CON1 & 0xF0) | 0x0E;
    T0CON0 = 0x90;
    st_bit(INTCON,GIE);
    st_bit(PIE0, TMR0IE);
What if you clear the timer count registers before enabling the interrupt.

Using a C icon.

Code: Select all

TMR0L = 0;
TMR0H = 0;

User avatar
Jan Lichtenbelt
Posts: 797
Joined: Tue Feb 17, 2009 8:35 pm
Location: Haren GN, the Netherlands
Has thanked: 128 times
Been thanked: 264 times
Contact:

Re: Timer0

Post by Jan Lichtenbelt »

Hi Ben,

That works OK now. The timer0 works correctly.

But the timer1 was a factor 4 times faster as expected. The problem could be solved by changing the clock source from Fosc to Fosc/4. But flowcode showed in both cases the same frequency. In case Fosc will be choosen, the frequency must be 61.035 x 4 Hz.
Timer1_2.jpg
Timer1_2.jpg (38.18 KiB) Viewed 2667 times
Timer1_1.jpg
Timer1_1.jpg (34.96 KiB) Viewed 2667 times
Kind regards

Jan

User avatar
Jan Lichtenbelt
Posts: 797
Joined: Tue Feb 17, 2009 8:35 pm
Location: Haren GN, the Netherlands
Has thanked: 128 times
Been thanked: 264 times
Contact:

Re: Timer0

Post by Jan Lichtenbelt »

Hi Ben

I still have problems with the frequency of the timers with the PIC16LF18857 microchip.
Above problems with timer1. But thesame problem will be met with timer0, which is 4 times faster as expected. The settings are:
Clock source: HFINTOSC
Input Asyn.: FOSC/4
Prescaler: 1:512
Postscaler: 1:1
Clipboard01.jpg
Clipboard01.jpg (20.98 KiB) Viewed 2545 times
The C-code seems correct to me


The frequency is 4 times faster, independent of the prescaler and postscaler.

Is there a solution for this problem?

Kind regards

Jan
Test_Timer0_v1.fcfx
(12.82 KiB) Downloaded 228 times

Post Reply