Connect with us

Checking PIC18F4520 Timer 0 overflow

Discussion in 'Microcontrollers, Programming and IoT' started by Rajinder, Apr 4, 2018.

  1. Rajinder

    Rajinder

    409
    7
    Jan 30, 2016
    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
     
  2. Minder

    Minder

    2,871
    594
    Apr 24, 2015
    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.
     
  3. JWHassler

    JWHassler

    77
    16
    Dec 22, 2014
    Post the offending code section, including errors, inside 'code' tags
     
    Arouse1973 likes this.
  4. Rajinder

    Rajinder

    409
    7
    Jan 30, 2016
    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
     
  5. Rajinder

    Rajinder

    409
    7
    Jan 30, 2016
    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
     

    Attached Files:

  6. Arouse1973

    Arouse1973 Adam

    5,164
    1,078
    Dec 18, 2013
    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.
     
  7. Rajinder

    Rajinder

    409
    7
    Jan 30, 2016
    Hi
    I can send it again with more comments.
    Thanks
     
    Arouse1973 likes this.
  8. Minder

    Minder

    2,871
    594
    Apr 24, 2015
    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.
     
  9. Minder

    Minder

    2,871
    594
    Apr 24, 2015
    Also set TMR1IE in PIE1.
    M.
     
  10. Rajinder

    Rajinder

    409
    7
    Jan 30, 2016
    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.
     
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day

-