start/stop timer1

5 posts / 0 new
Last post
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

  • 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.

  • 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:

"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]

  • 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?