start/stop timer1

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

For pwm measuring timer1 is
started and stopped like (below).
After stop TCNT1H:L are read.

;stop
clr r16
sts TCCR1B,r16

;start
clr r16
sts TCNT1H,r16
sts TCNT1L,r16
ldi r16,1
sts TCCR1B,r16

Is this ok for timer1

Last Edited: Fri. Dec 6, 2013 - 08:23 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Except for the typo, it looks OK.

For precise work, PWM measurement would be done using the Input Capture facility (ICP) and the ICP1 pin.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

Quote:
sts TCCR1B,r16
Is this ok for timer1
Depends on avr type.
Ok for Atmega88 (TCCR1B adr=0x81)
but for Atmega8 (TCCR1B adr=0x2E) it writes to a wrong address without warning .

I allways use OUT and if I get a warning I rewrite to STS.

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

And then there are the macros that select between STS and OUT automagically.

Just wait for John to pass by and he'll point them out. :wink:

"He used to carry his guitar in a gunny sack, or sit beneath the tree by the railroad track. Oh the engineers would see him sitting in the shade, Strumming with the rhythm that the drivers made. People passing by, they would stop and say, "Oh, my, what that little country boy could play!" [Chuck Berry]

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

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

Quote:

Just wait for John to pass by and he'll point them out.

It's AVR001 isn't it?