Task 3: External Interrupt Based on Signal Change on Pin

As mentioned before, once an interrupt is enabled it will be triggered even when the corresponding pin is configured as output.

Task: Enable 16-bit Timer 1 in CTC mode with OC1A pin (PB1 pin - configured as output) (also PCINT1 pin) toggling on compare match. Enable the interrupt PCINT1 with the ISR containing a routine that turns on and off the LED0 connected to PORTC. Pin Change Interrupt PCI0 triggers if a pin in PCINT[7:0] is toggled while enabled. Here PCINT1 is enabled.

  1. Configure PORTC0 as output to drive LED0.
  2. Enable pin change interrupt PCINT1.Also set the global interrupt enable bit.
  3. Configure Timer1 to operate in CTC mode (OCR1A as TOP) with OC1A pin toggling on compare match. Load OCR1A with some value.
  4. Configure OC1A pin (PCINT1 pin/PB1 pin) as output and start the timer with some prescalar value (in the example code it is divide by 64).
  5. Within the ISR turn on LED0 connected to PORTC0 and turn off LED0 after some delay.
Hardware Setup:
  1. Connect a wire between pins PC0 and LED0.
  2. Connect a wire between pins PB1 and LED1 to view the OC1A output.

Without using STK600, connect two LED circuits as shown in Figure 1; one at PC0 and another at PB1.

When running the example code, LED1 (connected to OC1A pin) toggles because of timer action. Whenever LED1 switches OFF (means a transition from low to high – a rising edge) or switches ON (means a transition from high to low – a falling edge), PCINT1 interrupt is triggered and so LED0 blinks once.