Menu

timer2 avr

wn
2017-12-16
2017-12-17
  • wn

    wn - 2017-12-16

    Having trouble. I need a 1 second time base timer. I am attempting to use timer2 on an AVR mega328. So far I think that the timer value for overflow needs to be set to 10800 with the oscillator being a 11.0592Mhz crystal. I am intializing with:

    InitTimer2 Osc, PS_1024

    I have a overflow handler like this:

    sub idle_cntr()

    sleep_cntr = sleep_cntr + 1
    ser1send 10
    ser1send 13
    ser1print "TIMER 0 O/F"
    
    ClearTimer 2
    SetTimer 2, 10800
    TMR2IF = 0
    

    end sub

    Currently it overflows much too quickly, way faster than 1 second.

     
  • Anobium

    Anobium - 2017-12-16

    look in your installation for a nice set of timer help tools. There is a nice ZIP and one of the tools with help with the parameters.

    ..\GCB@Syn\GreatCowBasic\Demos\Interrupt_and_Timer_Solutions\Interrupt - Timed examples

     
  • stan cartwright

    stan cartwright - 2017-12-16

    these values from timercalculator for 1000ms

      #chip mega328p,16
      #option explicit
      #define LED PORTB.4
      dir LED out
        ' Add the handler for the interrupt
        On Interrupt Timer1Match1 Call InterruptHandler
        ' Initialise the timer - this is required
        ' Set prescaler and then start the timer
        InitTimer1 Osc, PS_1_1
        ' Start the timer - this is required
        StartTimer 1
    TCCR1A = 0x80;
    TCCR1B = 0x0C;
    OCR1AH = 0xF4;
    OCR1AL = 0x23;
    
    'Main routine
      Do
      Loop
      end
    'This will be called when the Timer matches
    Sub InterruptHandler
      LED = !LED
    End Sub
    
     

    Last edit: stan cartwright 2017-12-16
    • wn

      wn - 2017-12-17

      Thanks for the information. I will try these values. I also found the demos, which I has some how overlooked.

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.