1

I am trying to get an Arduino UNO to read a 64cpr quadrature encoder. I specifically want to use Timer1 to measure of the frequency (and hence speed) of one of the encoder signals.

I ultimately want to store 10 measurements in an array to compute a moving average filter, but one thing at a time. I first need to be able to measure the clock cycles between two rising edges.

Here's what I've got so far. Any help or comments are 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 now I'm not even jumping into the ISR, which I don't understand. I think I have set everything up correctly. Interrupts are enabled. ICES1 should default to 0, or falling edge trigger, which is fine (just want to measure one period). I'm picking a pin on port B to receive the (input) signal, which should be fine. From Atmel's documentation, I think Timer1 is connected.

Any thoughts? Thanks in advance!

descarte
  • 11
  • 2

0 Answers0