Maker Pro
Maker Pro

Checking PIC18F4520 Timer 0 overflow

Hi
I am using MikroC compiler for the PIC18F4520 family.
I want to know how I check if TMR0 has overflowed?

I have seen on a PIC16xxxx device it is just as TMR0, the following are snippets of code for a PIC16F device :-

i.e. TMR0 = 0 /*clear TMR0*/
while (TMR0 < (int) 500/2.048))

How do I do the same for the PIC18F4520 in Mikro C. I can't just type TMR0 as the compiler reports an error.

Any help would be greatly appreciated.
Thanks in advance
 
Pic timers have a Interrupt flag on overflow, this can be tested, it has to be cleared once read, this occurs whether the int enable is set or not.
I only use Assembly but there must be a simple way in C.
M.
 
Hi
Thanks for the reply.
I will post the code today. I thought thst i had it cracked by using TMR0L. However it still doesnt work.
I will post it later today.
Thanks
 
Hi
I have attached the code. It is a reaction timer.
The start LED lights after 2 seconds. Then you have 200/2.048 seconds to hit the button.
If you do then the success LED is lit.

I am getting the success LED on all the time. I am using the internal oscillator set to 500KHz. The LED will light when a 0 is output on the PIC I/O line.
Can anyone help?
Best regards
Raj
 

Attachments

  • reaction timer.pdf
    113 KB · Views: 42
You need to comment your code so we know what you think the code should do. You need to do this with all your code.
 
To check for TIM0 O.F. is a simple check of TMR0IF in INTCON.
If using it to interrupt then it should be cleared immediately after.
M.
 
Hi all
I have already tried the suggestions that you have mentioned.
Clearing the timer0 overflow flag and setting both global and peripheral interrupts.
For some reason i get the success LED switch on all the time.
I have also tried switching timer0 on by using TMR0ON = 1. I am sure this is not needed as the timer increments on the internal prescaled clock.
Thanks in advance.
 
Top