Starting, reseting and stopping AVR timer

Discussion in 'Embedded Systems and Microcontrollers' started by Alasttt, Jan 22, 2016.

  1. Alasttt

    Thread Starter Member

    May 13, 2015
    68
    0
    Hi,

    I want to start, reset and stop the timer in my program, and copy the TCNT0 value into a variable. My research tells me to start and stop the timer I just set the prescaler bits to my preferred setting to start, and clear the prescaler bits to stop the timer. I can restart the timer by doing TCNT0 = 0 ; Could someone please confirm that my below functions are correct?

    void Start_Timer(){
    TCCR1B = (1 << CS11);
    }

    void Stop_Timer(){
    TCCR1B &= ~(1 << CS11);
    }

    void Reset_Timer(){
    TCNT1 = 0;
    }

    Cheers..
     
  2. dannyf

    Well-Known Member

    Sep 13, 2015
    1,771
    358
    It probably differs from chip to chip and timer to timer.
     
  3. ScottWang

    Moderator

    Aug 23, 2012
    4,853
    767
    Too less info that we can't see the whole picture then every members could be feed you anything just match one point, it just like playing the puzzle and you will get the answer as the blind touch the elephant, you should describe some more as what's the purpose for your whole program doing and does any relation with the I/O port?
     
  4. eeabe

    Member

    Nov 30, 2013
    59
    9
    Assuming CS11 is the bit number of the single bit for the prescaler setting you want, it looks fine and pretty typical for AVR registers.

    If you're having a problem, you could specify the exact chip you're using so we could reference the datasheet.
     
Loading...