[solved]pin change interrupt problem

Go To Last Post
6 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

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.

Last Edited: Wed. Jan 9, 2008 - 05:30 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If you have JTAG fuse enabled, then you won't be able to use PCINT18 to PCINT21 (those pins need to be dedicated to JTAG interface).

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Cheers dude, spot on, works great now.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Glad to hear the good news -- enjoy! The 644P is one of my more favored AVR's.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

I´m using a similar project where pcint21 is used to count pulses as an interrupt. I also run async timer2 with tosc1 and 2 for a RTC.

The problem I´m having is that whenever I apply a signal to pcint21 the RTC slows down to the point of freezing.

I have tried disabling JTAG, capacitors of 10pF, 20pF, no capacitor at all...

Has anyone used pcint21 together with timer2 without problems? Really lost here..

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

One final thing, I have disconnected (physically) pcint21 (pin 24) from the pcb and apply a frequency to the track that was connected to it. The problem does not happen anymore.

This input is externally pulled high, I guess if it was some stray capacitance or crosstalk it would be there anyway but it isn´t if pin 24 is lifted.

Could this be a bug on the IC?