Timer0

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

Moderator: Benj

User avatar
Jan Lichtenbelt
Posts: 742
Joined: Tue Feb 17, 2009 8:35 pm
Location: Haren GN, the Netherlands
Has thanked: 101 times
Been thanked: 251 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 2 times


Who can help me?

Kind regards

Jan

User avatar
Benj
Matrix Staff
Posts: 13885
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4176 times
Been thanked: 3954 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: 742
Joined: Tue Feb 17, 2009 8:35 pm
Location: Haren GN, the Netherlands
Has thanked: 101 times
Been thanked: 251 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 37 times


Timer1_1.jpg
Timer1_1.jpg (34.96 KiB) Viewed 37 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%