Timer0

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

Moderator: Benj

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

Timer0

Postby Jan Lichtenbelt » Thu May 16, 2019 1:10 pm

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 18 times


Who can help me?

Kind regards

Jan

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

Re: Timer0

Postby Benj » Thu May 16, 2019 3:23 pm

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;
These users thanked the author Benj for the post:
Jan Lichtenbelt (Thu May 16, 2019 3:53 pm)
Rating: 5.88%
 

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

Re: Timer0

Postby Jan Lichtenbelt » Thu May 16, 2019 3:52 pm

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 259 times


Timer1_1.jpg
Timer1_1.jpg (34.96 KiB) Viewed 259 times


Kind regards

Jan
These users thanked the author Jan Lichtenbelt for the post:
Benj (Fri May 17, 2019 4:57 pm)
Rating: 5.88%
 

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

Re: Timer0

Postby Jan Lichtenbelt » Sun Jun 16, 2019 12:54 pm

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 137 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 5 times