Pages: [1]   Go Down
Author Topic: atmel 168 timer and prescaler question  (Read 636 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 12
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So I've setup an ISR using Timer 1.

What I can't seem to get is right is the physical amount of time per count.

I've tried all sorts of prescalers, using the CS10,11, and 12 bits.

Those are divisions of the I/O-clk, and i can't find anywhere for the atmel 168 what that clock is.

I've setup CTC, but it still seems that I need to reset TNT1 = 1 and OCR1A = num_max_counts after every ISR loop or the behavior is different

I'm setting my TMR1A = 0x00 and my TMR1B = (1 << CS10)  [or 11 or 12 as i play with prescalers]

Any help here or example scripts would be appreciated that show for a given timer setup exactly how much time passes for each count.  I'm doing some numerical integration and its vital i get this.


FWIW i'm taking care of the analogRead outside the interrupt, and my main loop() function has no delay statements.  I am running a serial connection at 9600 baud.


Thanks!
JM
« Last Edit: February 06, 2008, 02:29:07 am by johnm1019 » Logged

London
Offline Offline
Tesla Member
***
Karma: 10
Posts: 6255
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

try setting  TCCR1A for normal counting mode :
TCCR1A = 0x00;      // COM1A1=0, COM1A0=0 => Disconnect Pin OC1, => PWM Operation disabled

setting cs11 sets the prescaller to divide the arduino's 16mhz clock by 8  
  TCCR1B = 0x02;      // TCNT1 increments every .5 uS  

once you have that running you can play with the output compare register values.

I hope that helps.
Logged

Pages: [1]   Go Up
Jump to: