Starting, reseting and stopping AVR timer

Thread Starter

Alasttt

Joined May 13, 2015
68
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..
 

ScottWang

Joined Aug 23, 2012
6,844
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?
 

eeabe

Joined Nov 30, 2013
59
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.
 
Top