Question about timer

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

this is my question(ATMega16)

can you tell my if i have the TCCR1B set to external clock source on T1 pin clock on rising edge , what is the principle by what the ATMega16 TCNT1 counts ?

I mean i have a circuit that measure the resonant frequency of a LC circuit and the output of this circuit(a square wave) enters on T1 pin clock. The resonant frequency is f1.How does ATMega16 to count exact this value?

and if i have a 7.3728 MHz quartz oscillator as clock what do you think it will be the maximum frequency that ATMega16 will count ?
Tanks!

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

Use 16MHz Crystal for maximum speed count.
It is 16 bit. for expanding, append upper bytes in the interrupt overflow routine.
before reading 16 bit counter register, check datasheet procedure.

Regards
A.R.Khorasani
http://www.instrumentalanalysis.com

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

Quote:

can you tell my if i have the TCCR1B set to external clock source on T1 pin clock on rising edge , what is the principle by what the ATMega16 TCNT1 counts ?

TCNT1 increments by 1 each time a rising edge on T1 is detected.

You could, for example, run another timer from F_CPU and in the time it takes for say 10ms to pass you then look at TCNT1 and see how many it has counted to in the same period and from that derive it's frequency.

The simple case would be have the other timer run for 1 second. If TCNT1 had just counted to 317 in the time that took then you'd know it was 317Hz. But you will probably want to work in smaller time slices.

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

So if my timer in the period of 1 second counts 317 rising edge the frequency is 317Hz?
it is this right?

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

Quote:
and if i have a 7.3728 MHz quartz oscillator as clock what do you think it will be the maximum frequency that ATMega16 will count ?

The AVR checks the pin every cpu clock cycle, so the best frequency you can get is 1/2 the system clock.

Regards,
Steve A.

The Board helps those that help themselves.

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

i understand so far

I have another question though

so i have set the timer1 to Output Compare A Match Interrupt Enable

and i want the timer to reset (if the TCNT1 goes over i want to TCNT1=0 and write to my lcd Out of range)
i set OCR1A=0xffff;

my problem is that i don't know how to enable this reset

or can you tell me what happens with TCNT1 when it goes over(i have an External clock source on T1 pin) ...because i don't know how to write my code
if(TCNT! condition) lcd_puts("out of range")

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

no one home for my last question?

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

If you use CTC mode, then the timer will automatically reset to 0 on compare match. But if your TOP value is 0xffff, then you don't need to do anything. The next value after 0xffff is 0.

Regards,
Steve A.

The Board helps those that help themselves.