Farhan,
In reviewing the tuning encoder, I found the function tuning_isr(void):
static int tuning_ticks = 0;
void tuning_isr(void){
int tuning = enc_read(&enc_b);
if (tuning < 0)
tuning_ticks++;
if (tuning > 0)
tuning_ticks--;
}When the interrupt is received, the following is called :
int enc_read(struct encoder *e) {
? int result = 0;?
? int newState;
??
? newState = enc_state(e); // Get current state??
? ??
? if (newState != e->prev_state)
? ? ?delay (1);
??
? if (enc_state(e) != newState || newState == e->prev_state)
? ? return 0;?
?
? //these transitions point to the encoder being rotated anti-clockwise
? if ((e->prev_state == 0 && newState == 2) ||?
? ? (e->prev_state == 2 && newState == 3) ||?
? ? (e->prev_state == 3 && newState == 1) ||?
? ? (e->prev_state == 1 && newState == 0)){
? ? ? e->history--;
? ? ? //result = -1;
? ? }
? //these transitions point to the enccoder being rotated clockwise
? if ((e->prev_state == 0 && newState == 1) ||?
? ? (e->prev_state == 1 && newState == 3) ||?
? ? (e->prev_state == 3 && newState == 2) ||?
? ? (e->prev_state == 2 && newState == 0)){
? ? ? e->history++;
? ? }
? e->prev_state = newState; // Record state for next pulse interpretation
? if (e->history > e->speed){
? ? result = 1;
? ? e->history = 0;
? }
? if (e->history < -e->speed){
? ? result = -1;
? ? e->history = 0;
? }
? return result;
}The only delay function is the?
?if (newState != e->prev_state)
? ? ?delay (1);
That is using delay and not the same as what Jack has suggested.? Still, the delay is active for only one millisecond.? If this would need to be increased, it would be better to use the construct that Jack has suggested.? Other delays in the code do use the millis() function.?
Please let me know if I have missed something so I can understand the code better.
73
Evan
AC9TU