timer1 as counter

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

In at90usb1287, I want to use timer1 as counter...
I have connected my pulse source to pin no.31 (T1)PD.6.

I want to use prescale=1
I have defined registers as

TCCR1A=0
TCCR1B=129(10000001)
TCCR1C=0

I am reading every 1 second the TCNT1 register...and then assigning to 0 after the read.
Its not working...
Are the value assigned registers correct?

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

Quote:

Its not working...

What does that mean?

Quote:

TCCR1B=129(10000001)

What does this say about how to set the CS bits for external clock?

Table 14-5. Clock Select Bit Description
CSn2 CSn1 CSn0 Description
0 0 0 No clock source. (Timer/Counter stopped)
001clkI/O/1 (No prescaling
010clkI/O/8 (From prescaler)
011clkI/O/64 (From prescaler)
100clkI/O/256 (From prescaler)
101clkI/O/1024 (From prescaler)
1 1 0 External clock source on Tn pin. Clock on falling edge
1 1 1 External clock source on Tn pin. Clock on rising edge

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

I want to use system clock 8Mhz...so its not prescaled....thats why it is 001. No prescaling.

Its not giving any counts, I have connected 100Hz pulse source..

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

Quote:
I have connected my pulse source to pin no.31 (T1)PD.6.
and
Quote:
I want to use system clock 8Mhz
.
These are two mutually exclusive things. You can count external pulses or system clock ticks. The bit settings posted by theusch above show how you choose one or the other.

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

thanks for the info..I got the difference...its working after setting changed...