Task 3: External Interrupt Based on Signal Change on Pin

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

Task: Enable 16-bit Timer 3 in CTC mode with OC3B pin (PE4 pin - configured as output) (also INT4 pin) toggling on compare match. Enable the interrupt INT4 with the ISR containing a routine that turns on and off the LED0 connected to PORTA.

  1. 1.Configure PORTA0 as output to drive LED0.
  2. 2.Configure INT4 to sense rising edge and enable INT4. Also set the global interrupt enable bit.
  3. 3.Configure Timer3 to operate in CTC mode (OCR3A as TOP) with OC3B pin toggling on compare match. Load OCR3A with some value.
  4. 4.Configure OC3B pin (INT4 pin/PE4 pin) as output and start the timer with some pre-scalar value (in the example code it is divide by 256).
  5. 5.Within the ISR, turn ON LED0 connected to PORTA0 and turn OFF LED0 after some delay.
Hardware Setup:
  1. 1.Connect a wire between pins PA0 and LED0.
  2. 2.Connect a wire between pins PE4 and LED1 to view the OC3B output.

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

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