I've been playing with a couple servomotors i got from surplus of pick and place machines. So far, i've decoded their pinout and i'm working on reading the encoder, here comes the problem:
From what i observed, motor comes fitted with a 4096 cuadrature pulses per revolution +1 index pulse each revolution. Doing some testing in the Arduino IDE showed that spinning the motor a little faster and the encoder starts loosing steps...
I decided to migrate the code to AS7 and flush all the Arduino overhead, but the chip seems incapable of dealing with it. Correct me if i'm wrong about the following:
With 2048 cpr (just using the rising pulse of one cuadrature channel) and a rotational speed of 3000rpm, one revolution is complete in 0.02seconds.
Assuming the previous 20mS / 2048ppr we have one rising edge every 0.097mS -> 97uS give or take.
Is that time enought for executing the following ISR?:
#define F_CPU 16000000UL
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include <stdio.h>
volatile int count;
int main(void)
{
DDRD = (0<<PORTD2) | (0<<PORTD3)| (0<<PORTD4);
PORTD = (0<<PORTD2) | (0<<PORTD3)| (0<<PORTD4);
EICRA = (1 << ISC11) | (1 << ISC01); // Configure interrupt trigger on rising edge of INT0
EIMSK = (1 << INT0); //ebable INT0
sei();
while (1)
{
}
}
ISR (INT0_vect){
uint8_t i = ((PIND & 0b00010000)>>4);
if (i == 1) {
count = count +1;
}else{
count = count -1;
}
EIFR = (1<<INTF0);
}
If not, how should i do it... Dedicated counter IC?
Thanks
**Edit:**capture of the logic analyzer comparing one revolution (index) to encoder A