I've been trying to fix this problem for a few days now, have run out of ideas so I am asking on here.
I've wrote some code to read PWM from the servo output of a Futaba 7 channel receiver. I've got it displaying the first 4 channels on a LCD. The problem is however, it only is reading the first 2 channels, with the remaing 6 channel inputs to the ATMega644P read 0 (zero).
I've narrowed it down to the fact that its not intercepting any pin change interrupts from the 6 input pins that are not reading correctly (but it does intercept the first 2 pins).
As far as hardware goes, the grounds are connected all together, and each channel is separately connected through a 190ohm resistor in series to the input pin. I've also replaced the ATMega644P to make sure the one I had wasn't faulty (it wasn't).
Here is my code to initialise the pin change interrupts (I'm using port C (all 8) pins.
TCCR1B |= (1 << CS10); TCCR1B &= ~(1 << CS11); TCCR1B &= ~(1 << CS12); // Setup input pins PC0_input; PC1_input; PC2_input; PC3_input; PC4_input; PC5_input; PC6_input; PC7_input; PCMSK2 |= (1<<PCINT16); PCMSK2 |= (1<<PCINT17); PCMSK2 |= (1<<PCINT18); PCMSK2 |= (1<<PCINT19); PCMSK2 |= (1<<PCINT20); PCMSK2 |= (1<<PCINT21); PCMSK2 |= (1<<PCINT22); PCMSK2 |= (1<<PCINT23); PCICR |= (1<<PCIE2); sei();
Here is my ISR:
ISR(PCINT2_vect) { time_list[count] = TCNT1; // Record time interrupt was triggered pin_state_list[count] = PINC; // Record state of PINC inputs count++; // Increment count of interrupts triggered if ( count == 16 ) // Need to reset since only 16 places in list arrays, which are addressed below { count = 0; } }
And here are the globals that the ISR accesses:
volatile u8 pin_state_list[NUM_INTERRUPT]; volatile u16 time_list[NUM_INTERRUPT]; volatile u8 count;
As you can see, all the ISR does is record the 16-bit time the interrupt occurred, and the state of PINC, and incrementing the count (so the next interrupt does over write the previous data). I am certain that I'm not receiving any interrupt calls from the 6 channels that are not working, and the ones that are not working are the 6 MSB. (PC7:PC2).
Clock is 20Mhz, and I've got no other interrupts running at all. If anyone has any ideas, it'd be greatly appreciated.