Tuesday, 15 September 2015

timer - Using Input Capture Register on Timer1 of ATmega328 to determine signal frequency -



timer - Using Input Capture Register on Timer1 of ATmega328 to determine signal frequency -

i trying arduino uno read 64cpr quadrature encoder. want utilize timer1 measure of frequency (and hence speed) of 1 of encoder signals.

i want store 10 measurements in array compute moving average filter, 1 thing @ time. first need able measure clock cycles between 2 rising edges.

here's i've got far. help or comments appreciated:

#include <avr/io.h> #include <avr/interrupt.h> const int inputcapture = 8; void setup(){ sei(); tcnt1 = 0; tccr1b = (1<<cs10)|(1<<ices1); // no prescaling tifr1 = 1<<icf1; pinmode(inputcapture, input); serial.begin(9600); } isr(timer1_capt1_vect){ thisstep = icr1; tcnt1 = 0; } void loop(){ serial.println(thisstep); }

right i'm not jumping isr, don't understand. think have set correctly. interrupts enabled. ices1 should default 0, or falling border trigger, fine (just want measure 1 period). i'm picking pin on port b receive (input) signal, should fine. atmel's documentation, think timer1 connected.

any thoughts? in advance!

timer arduino interrupt icr

No comments:

Post a Comment