Page 1 of 1

Timer0

Posted: Thu May 16, 2019 1:10 pm
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 260 times
Who can help me?

Kind regards

Jan

Re: Timer0

Posted: Thu May 16, 2019 3:23 pm
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;

Re: Timer0

Posted: Thu May 16, 2019 3:52 pm
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 2706 times
Timer1_1.jpg
Timer1_1.jpg (34.96 KiB) Viewed 2706 times
Kind regards

Jan

Re: Timer0

Posted: Sun Jun 16, 2019 12:54 pm
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 2584 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 231 times