How To Stop Timer0 in ATmega8.

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am try to measure distance via HC-SR04 ultrasonic sensor module.
first im send a 10us pulse in HC-sr04 trig pin,
then checking echo pin..
when echo pin go high then start Timer0.
now im stop the Timer0 when echo pin go low.

please suggest me how to stop timer0.

 

(I am skip Timer Overflow interrupt)

শূন্য  - The ZeRo

Last Edited: Sun. Nov 30, 2014 - 03:41 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1
TCCR0B = 0;

But really you don't need to stop the timer, you only need to capture the value of it by reading TCNT0:

foo = TCNT0;

If you started with the timer at 0, then foo will contain the number of ticks which timer 0 counted before you captured TNCT0.

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I misspoke :(

 

ATmega8 doesn't have TCCR0B, it only has TCCR0, so:

TCCR0 = 0;

... will stop the timer.

 

Perhaps you should post your code.

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
//first im send a 10us pulse in HC-sr04 trig pin,

//then checking echo pin..
   loop_until_bit_is_set(port,echopin);
//when echo pin goes high then clear Timer0.
   TCNT0 = 0;
//when echo pin goes low then read Timer0.
   loop_until_bit_is_clear(port,echopin);
   value = TCNT0;