Hi Sir,
I need to use 4 External Interrupts for my application with Atmega328. But i found that the Atmega328 have only 2 External Interrupts. Then i found that the all the Port pins in the Atmega328 are Port change interrupt pins. I have to sense the Port Pin High to Low Transition from the input received to the IC Externally. So Shall i use any 4 Pins in the ATmega328 as Port Change Interrupt instead of 2 External Interrupts? These Port change interrupts will respond within 3 clock cycle as External Interrupts Function in Atmega328? Kindly let us know.
Port Change Interrupts work fine. It does require a bit more checking to determine which pins in the port causes an interrupt. You also do not have the luxury of choosing rising or falling edge - you only have "change". If you need a specific edge you have to check for that in software (I do all of that in the IRQ).
Search on Arduino Pin Change Interrupt or find it in this tutorial with code in steps:
Nick Gammon's Interrupts Tutorial
Nick: Below is a list of interrupts, in priority order, for the Atmega328, see 4,5,6:
1 Reset
2 External Interrupt Request 0 (pin D2) (INT0_vect)
3 External Interrupt Request 1 (pin D3) (INT1_vect)
4 Pin Change Interrupt Request 0 (pins D8 to D13) (PCINT0_vect)
5 Pin Change Interrupt Request 1 (pins A0 to A5) (PCINT1_vect)
6 Pin Change Interrupt Request 2 (pins D0 to D7) (PCINT2_vect)
7 Watchdog Time-out Interrupt (WDT_vect)
8 Timer/Counter2 Compare Match A (TIMER2_COMPA_vect)
9 Timer/Counter2 Compare Match B (TIMER2_COMPB_vect)
10 Timer/Counter2 Overflow (TIMER2_OVF_vect)
11 Timer/Counter1 Capture Event (TIMER1_CAPT_vect)
12 Timer/Counter1 Compare Match A (TIMER1_COMPA_vect)
13 Timer/Counter1 Compare Match B (TIMER1_COMPB_vect)
14 Timer/Counter1 Overflow (TIMER1_OVF_vect)
15 Timer/Counter0 Compare Match A (TIMER0_COMPA_vect)
16 Timer/Counter0 Compare Match B (TIMER0_COMPB_vect)
17 Timer/Counter0 Overflow (TIMER0_OVF_vect)
18 SPI Serial Transfer Complete (SPI_STC_vect)
19 USART Rx Complete (USART_RX_vect)
20 USART, Data Register Empty (USART_UDRE_vect)
21 USART, Tx Complete (USART_TX_vect)
22 ADC Conversion Complete (ADC_vect)
23 EEPROM Ready (EE_READY_vect)
24 Analog Comparator (ANALOG_COMP_vect)
25 2-wire Serial Interface (I2C) (TWI_vect)
26 Store Program Memory Ready (SPM_READY_vect)
Yes
These Port change interrupts will respond within 3 clock cycle as External Interrupts Function in Atmega328?
Yes
You can do better (more precise) pin-change timer-capture if you use
11 Timer/Counter1 Capture Event
on the interrupt list above.
This works like a pin-change interrupt but the hardware also captures the value of timer-1 when the pin changes. You can drive it from an interrupt or you can poll it.
The main down-side is that you can only use the input pin that is attached to the input capture unit. On UNO there is only one of these and it is ICP1 which is PortB-0 or Arduino digital pin 8.
I use this to capture rising and falling edges for a software CAN-bus driver. It works very well.
You do know that hardware interrupts have 85 cycles overhead and that pin change interrupts take longer? 3 cycle response?
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.