0% found this document useful (0 votes)
68 views14 pages

Interrupts With Atmega 2560: Team D

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 14

  

 
Interrupts with ATmega 2560 
 

TEAM D 

Sketch:- 
Learning basics of Arduino mega. Using timer interrupts for task 
scheduling. Design a project which carries out 3 tasks at specific time 
intervals. 

AIM:-   

● Write a simple program to control an array of 4 LED such a way that after 
every second the next led gets turned on and the previous LED gets off and 
the loop goes on. 
● Implement a push button to generate hardware interrupt and we have to 
write an ISR to handle interrupt toggle. 
● We need to modify our array of LED program to include ISR for timer 
interrupts and configure one timer for providing delay of 400ms and another 
delay for providing 200ms. We need to write ISR to sample data of the 
potentiometer of any pin. 

INTRODUCTION 

The second task in the journey of ABHIYANTA adventure was to develop an 
interrupt using ATMEGA 2560. The first part of the task included 
implementation of ARDUINO MEGA in proteus and also including a 
hardware interrupt. And the second included Timer interrupt. 

ATMEGA 2560 

The Arduino MEGA 2560 board is just like a brother of the Arduino UNO 
board. It is way more powerful than the Arduino UNO and also twice as 
long from it. This board is the successor of Arduino MEGA. It can be named 
as ATMega2560. 
It can have more memory space as compared to other boards of Arduino.  
Arduino Mega 2560 can have power supply of two voltages i.e. 3.3 V and 5 
V. 
DIVING DEEP INTO THE TASK  
2.1  

1. ARRAY OF LED 

This included the implementation of array of 4 leds in proteus using 


the ARDUINO MEGA board. The leds blink at a particular time interval 
just like we see it in lightings hanging outside the houses during 
Diwali. 

2. ​HARDWARE INTERRUPT 
This part included an addition of the push button that acts as 
hardware interrupt in the circuit of the blinking of array of leds as 
above. 
 

2.2 

➢TIMER INTERRUPT 

In this task we had to include ISR for timer interrupts and sample 
data of potentiometer at a delay of 400ms and toggle the state of led 
at a delay of 200ms. Also we had to do it while using only single 
timer. 
 
 
What is Interrupt ? 
We have explained interrupt below by attaching handwritten notes. Kindly 
refer them. 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
Timer Interrupts :-  
When you want things to happen at a regular time interval, it can be easy 
to go for the delay() function. But this just pauses the program for a 
specific time period which is wasteful especially if you need to do other 
processing in the meantime. 
This is where timers and interrupts come in to play. 
The Arduino UNO has three timers 
● Timer0 - An 8 bit timer used by Arduino functions delay(), millis() and 
micros(). 
● Timer1 - A 16 bit timer used by the Servo() library 
● Timer2 - An 8 bit timer used by the Tone() library 
The Mega boards have Timers 3,4,5 which may be used instead 
In the example that follows, we shall use Timer1 for our interrupt. 
Obviously, if you are using the Servo Library there will be a conflict, so you 
should choose another timer. 

DIRECTION TO CODE :- 


Clear Timer on Compare Match (CTC mode) 
Generally, compare mode is used for generating periodic event or for 
generating waveforms. In compare mode, there is one compare register, 
where we can set value to compare with the Timer / counter register value. 
Once the compare value matches with timer / counter register value, 
compare match occurs. This compare match event can be used for 
waveform generation. 

We here use mode 4 i.e CTC with the TOP reference value equal to the 
OCRnA value. So for that we need to find the required bits in which 
particular sub register is this bit allowed. So we need to take a look at 
description of the individual registers. 
 

 
 
 
CHALLENGES FACED 
This task as compared to the previous one was quite difficult. In this task 
we learnt many new things like reading the datasheets of the ATMEGA 
2560 and knowing about various parts of the circuit. The internet sources 
also were not that much helpful this time we were just on our own. 
 

 
 

 
 
 
 
 

You might also like