Interrupts On Firebird-V Robot: E-Yantra Team Embedded Real-Time Systems Lab Indian Institute of Technology-Bombay

Download as pdf or txt
Download as pdf or txt
You are on page 1of 67

Outline

Interrupts
Interrupt-Handling on Firebird

Interrupts On Firebird-V Robot

E-Yantra Team
Embedded Real-Time Systems Lab
Indian Institute of Technology-Bombay

IIT Bombay
October 19, 2012

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 1/16


Outline
Interrupts
Interrupt-Handling on Firebird

Agenda for Discussion


1 Interrupts
What is an Interrupt
Closed Loop Programming
2 Interrupt-Handling on Firebird
Sources of Interrupt
Position Encoder
Interrupt Calculation
SREG-Register
EIMSK
EICRA
EICRB
ISR
C-Code

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 2/16


Outline
What is an Interrupt
Interrupts
Closed Loop Programming
Interrupt-Handling on Firebird

What is an Interrupt

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 3/16


Outline
What is an Interrupt
Interrupts
Closed Loop Programming
Interrupt-Handling on Firebird

What is an Interrupt

X Any signal that causes break in continuity of some ongoing process

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 3/16


Outline
What is an Interrupt
Interrupts
Closed Loop Programming
Interrupt-Handling on Firebird

What is an Interrupt

X Any signal that causes break in continuity of some ongoing process

X In microcontrollers interrupt signal halts the execution of main


program and dedicates processor to another task

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 3/16


Outline
What is an Interrupt
Interrupts
Closed Loop Programming
Interrupt-Handling on Firebird

What is an Interrupt

X Any signal that causes break in continuity of some ongoing process

X In microcontrollers interrupt signal halts the execution of main


program and dedicates processor to another task

X While main program is running, if an interrupt occurs, execution of


main program is stopped, and program counter goes to address of ISR

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 3/16


Outline
What is an Interrupt
Interrupts
Closed Loop Programming
Interrupt-Handling on Firebird

What is an Interrupt

X Any signal that causes break in continuity of some ongoing process

X In microcontrollers interrupt signal halts the execution of main


program and dedicates processor to another task

X While main program is running, if an interrupt occurs, execution of


main program is stopped, and program counter goes to address of ISR

X Interrupt Service Routine: Program that needs to be executed when


interrupt occurs

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 3/16


Outline
What is an Interrupt
Interrupts
Closed Loop Programming
Interrupt-Handling on Firebird

What is an Interrupt

X Any signal that causes break in continuity of some ongoing process

X In microcontrollers interrupt signal halts the execution of main


program and dedicates processor to another task

X While main program is running, if an interrupt occurs, execution of


main program is stopped, and program counter goes to address of ISR

X Interrupt Service Routine: Program that needs to be executed when


interrupt occurs

X After program inside ISR is executed completely, program counter


returns back to point where main program was interrupted

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 3/16


Outline
What is an Interrupt
Interrupts
Closed Loop Programming
Interrupt-Handling on Firebird

Closed Loop Programming

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 4/16


Outline
What is an Interrupt
Interrupts
Closed Loop Programming
Interrupt-Handling on Firebird

Closed Loop Programming


Systems that utilize feedback are called closed-loop control systems

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 4/16


Outline
What is an Interrupt
Interrupts
Closed Loop Programming
Interrupt-Handling on Firebird

Closed Loop Programming


Systems that utilize feedback are called closed-loop control systems

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 4/16


Outline
What is an Interrupt
Interrupts
Closed Loop Programming
Interrupt-Handling on Firebird

Closed Loop Programming


Systems that utilize feedback are called closed-loop control systems

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 4/16


Outline
What is an Interrupt
Interrupts
Closed Loop Programming
Interrupt-Handling on Firebird

Closed Loop Programming


Systems that utilize feedback are called closed-loop control systems

The feedback is used to make decisions about changes to the control


signal that drives the plant

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 4/16


Outline
What is an Interrupt
Interrupts
Closed Loop Programming
Interrupt-Handling on Firebird

Closed Loop Programming


Systems that utilize feedback are called closed-loop control systems

The feedback is used to make decisions about changes to the control


signal that drives the plant

An open-loop control system doesn’t have or doesn’t use feedback

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 4/16


Sources of Interrupt
Position Encoder
Interrupt Calculation
Outline SREG-Register
Interrupts EIMSK
Interrupt-Handling on Firebird EICRA
EICRB
ISR
C-Code

Sources of Interrupt on ATmega2560

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 5/16


Sources of Interrupt
Position Encoder
Interrupt Calculation
Outline SREG-Register
Interrupts EIMSK
Interrupt-Handling on Firebird EICRA
EICRB
ISR
C-Code

Sources of Interrupt on ATmega2560

ATmega 2560 has Fifty-Seven Different sources for Interrupt generation

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 5/16


Sources of Interrupt
Position Encoder
Interrupt Calculation
Outline SREG-Register
Interrupts EIMSK
Interrupt-Handling on Firebird EICRA
EICRB
ISR
C-Code

Sources of Interrupt on ATmega2560

ATmega 2560 has Fifty-Seven Different sources for Interrupt generation

Timer Overflow Interrupt

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 5/16


Sources of Interrupt
Position Encoder
Interrupt Calculation
Outline SREG-Register
Interrupts EIMSK
Interrupt-Handling on Firebird EICRA
EICRB
ISR
C-Code

Sources of Interrupt on ATmega2560

ATmega 2560 has Fifty-Seven Different sources for Interrupt generation

Timer Overflow Interrupt

Timer Compare

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 5/16


Sources of Interrupt
Position Encoder
Interrupt Calculation
Outline SREG-Register
Interrupts EIMSK
Interrupt-Handling on Firebird EICRA
EICRB
ISR
C-Code

Sources of Interrupt on ATmega2560

ATmega 2560 has Fifty-Seven Different sources for Interrupt generation

Timer Overflow Interrupt

Timer Compare

Serial interrupt

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 5/16


Sources of Interrupt
Position Encoder
Interrupt Calculation
Outline SREG-Register
Interrupts EIMSK
Interrupt-Handling on Firebird EICRA
EICRB
ISR
C-Code

Sources of Interrupt on ATmega2560

ATmega 2560 has Fifty-Seven Different sources for Interrupt generation

Timer Overflow Interrupt

Timer Compare

Serial interrupt

Wired & Wireless Interrupt

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 5/16


Sources of Interrupt
Position Encoder
Interrupt Calculation
Outline SREG-Register
Interrupts EIMSK
Interrupt-Handling on Firebird EICRA
EICRB
ISR
C-Code

Sources of Interrupt on ATmega2560

ATmega 2560 has Fifty-Seven Different sources for Interrupt generation

Timer Overflow Interrupt

Timer Compare

Serial interrupt

Wired & Wireless Interrupt

External hardware Interrupt

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 5/16


Sources of Interrupt
Position Encoder
Interrupt Calculation
Outline SREG-Register
Interrupts EIMSK
Interrupt-Handling on Firebird EICRA
EICRB
ISR
C-Code

Position encoder

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 6/16


Sources of Interrupt
Position Encoder
Interrupt Calculation
Outline SREG-Register
Interrupts EIMSK
Interrupt-Handling on Firebird EICRA
EICRB
ISR
C-Code

Position encoder

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 6/16


Sources of Interrupt
Position Encoder
Interrupt Calculation
Outline SREG-Register
Interrupts EIMSK
Interrupt-Handling on Firebird EICRA
EICRB
ISR
C-Code

Position encoder

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 6/16


Sources of Interrupt
Position Encoder
Interrupt Calculation
Outline SREG-Register
Interrupts EIMSK
Interrupt-Handling on Firebird EICRA
EICRB
ISR
C-Code

Position encoder

1 Optical position encoders are used


for position feedback

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 6/16


Sources of Interrupt
Position Encoder
Interrupt Calculation
Outline SREG-Register
Interrupts EIMSK
Interrupt-Handling on Firebird EICRA
EICRB
ISR
C-Code

Position encoder

1 Optical position encoders are used


for position feedback
2 It consists of IR LED and photo
diode placed opposite of each other

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 6/16


Sources of Interrupt
Position Encoder
Interrupt Calculation
Outline SREG-Register
Interrupts EIMSK
Interrupt-Handling on Firebird EICRA
EICRB
ISR
C-Code

Position encoder

1 Optical position encoders are used


for position feedback
2 It consists of IR LED and photo
diode placed opposite of each other
3 When IR light is interrupted by
encoder disc,its output state
changes (high to low or low to
high)

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 6/16


Sources of Interrupt
Position Encoder
Interrupt Calculation
Outline SREG-Register
Interrupts EIMSK
Interrupt-Handling on Firebird EICRA
EICRB
ISR
C-Code

Position encoder

1 Optical position encoders are used


for position feedback
2 It consists of IR LED and photo
diode placed opposite of each other
3 When IR light is interrupted by
encoder disc,its output state
changes (high to low or low to
high)
4 Output of the encoder is connected
to the interrupt pin of the
microcontroller

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 6/16


Sources of Interrupt
Position Encoder
Interrupt Calculation
Outline SREG-Register
Interrupts EIMSK
Interrupt-Handling on Firebird EICRA
EICRB
ISR
C-Code

Position encoder

1 Optical position encoders are used


for position feedback
2 It consists of IR LED and photo
diode placed opposite of each other
3 When IR light is interrupted by
encoder disc,its output state
changes (high to low or low to
high)
4 Output of the encoder is connected
to the interrupt pin of the
microcontroller
5 Left encoder is connected to INT4
and Right encoder is connected to
INT5
www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 6/16
Sources of Interrupt
Position Encoder
Interrupt Calculation
Outline SREG-Register
Interrupts EIMSK
Interrupt-Handling on Firebird EICRA
EICRB
ISR
C-Code

Some Mathematics...

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 7/16


Sources of Interrupt
Position Encoder
Interrupt Calculation
Outline SREG-Register
Interrupts EIMSK
Interrupt-Handling on Firebird EICRA
EICRB
ISR
C-Code

Some Mathematics...

1 Number of slots in disc = 30

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 7/16


Sources of Interrupt
Position Encoder
Interrupt Calculation
Outline SREG-Register
Interrupts EIMSK
Interrupt-Handling on Firebird EICRA
EICRB
ISR
C-Code

Some Mathematics...

1 Number of slots in disc = 30

2 Number of Pulse/rotation = 30

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 7/16


Sources of Interrupt
Position Encoder
Interrupt Calculation
Outline SREG-Register
Interrupts EIMSK
Interrupt-Handling on Firebird EICRA
EICRB
ISR
C-Code

Some Mathematics...

1 Number of slots in disc = 30

2 Number of Pulse/rotation = 30

3 Diameter of wheel = 52mm

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 7/16


Sources of Interrupt
Position Encoder
Interrupt Calculation
Outline SREG-Register
Interrupts EIMSK
Interrupt-Handling on Firebird EICRA
EICRB
ISR
C-Code

Some Mathematics...

1 Number of slots in disc = 30

2 Number of Pulse/rotation = 30

3 Diameter of wheel = 52mm

4 Resolution of position encoder

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 7/16


Sources of Interrupt
Position Encoder
Interrupt Calculation
Outline SREG-Register
Interrupts EIMSK
Interrupt-Handling on Firebird EICRA
EICRB
ISR
C-Code

Some Mathematics...

1 Number of slots in disc = 30

2 Number of Pulse/rotation = 30

3 Diameter of wheel = 52mm

4 Resolution of position encoder

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 7/16


Sources of Interrupt
Position Encoder
Interrupt Calculation
Outline SREG-Register
Interrupts EIMSK
Interrupt-Handling on Firebird EICRA
EICRB
ISR
C-Code

Some Mathematics...

1 Number of slots in disc = 30

2 Number of Pulse/rotation = 30

3 Diameter of wheel = 52mm

4 Resolution of position encoder


= (π∗d)/30 = 5.44

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 7/16


Sources of Interrupt
Position Encoder
Interrupt Calculation
Outline SREG-Register
Interrupts EIMSK
Interrupt-Handling on Firebird EICRA
EICRB
ISR
C-Code

Some Mathematics...

1 Number of slots in disc = 30

2 Number of Pulse/rotation = 30

3 Diameter of wheel = 52mm

4 Resolution of position encoder


= (π∗d)/30 = 5.44
5 Pulse count

= distance/5.44

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 7/16


Sources of Interrupt
Position Encoder
Interrupt Calculation
Outline SREG-Register
Interrupts EIMSK
Interrupt-Handling on Firebird EICRA
EICRB
ISR
C-Code

SREG- AVR Status Register


This register is used to Globally Enable all Interrupt

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 8/16


Sources of Interrupt
Position Encoder
Interrupt Calculation
Outline SREG-Register
Interrupts EIMSK
Interrupt-Handling on Firebird EICRA
EICRB
ISR
C-Code

SREG- AVR Status Register


This register is used to Globally Enable all Interrupt

Bit Symbol Description Bit Value


7 I Global Interrupt Enable bit 1
6 T Bit Copy Storage bit 0
5 H Half Carry Flag 0
4 S Sign Bit 0
3 V Two0 s Complement Overflow Flag 0
2 N Negative Flag 0
1 Z Zero Flag 0
0 C Carry Flag 0

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 8/16


Sources of Interrupt
Position Encoder
Interrupt Calculation
Outline SREG-Register
Interrupts EIMSK
Interrupt-Handling on Firebird EICRA
EICRB
ISR
C-Code

SREG- AVR Status Register


This register is used to Globally Enable all Interrupt

Bit Symbol Description Bit Value


7 I Global Interrupt Enable bit 1
6 T Bit Copy Storage bit 0
5 H Half Carry Flag 0
4 S Sign Bit 0
3 V Two0 s Complement Overflow Flag 0
2 N Negative Flag 0
1 Z Zero Flag 0
0 C Carry Flag 0

SREG = 0x80

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 8/16


Sources of Interrupt
Position Encoder
Interrupt Calculation
Outline SREG-Register
Interrupts EIMSK
Interrupt-Handling on Firebird EICRA
EICRB
ISR
C-Code

EIMSK- External Interrupt Mask Register


This register is Used to enable Individual External Interrupt

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 9/16


Sources of Interrupt
Position Encoder
Interrupt Calculation
Outline SREG-Register
Interrupts EIMSK
Interrupt-Handling on Firebird EICRA
EICRB
ISR
C-Code

EIMSK- External Interrupt Mask Register


This register is Used to enable Individual External Interrupt

Bit Symbol Description Bit Value


7 INT7 External Interrupt Request 7 0
6 INT6 External Interrupt Request 6 0
5 INT5 External Interrupt Request 5 1
4 INT4 External Interrupt Request 4 1
3 INT3 External Interrupt Request 3 0
2 INT2 External Interrupt Request 2 0
1 INT1 External Interrupt Request 1 0
0 INT0 External Interrupt Request 0 0

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 9/16


Sources of Interrupt
Position Encoder
Interrupt Calculation
Outline SREG-Register
Interrupts EIMSK
Interrupt-Handling on Firebird EICRA
EICRB
ISR
C-Code

EIMSK- External Interrupt Mask Register


This register is Used to enable Individual External Interrupt

Bit Symbol Description Bit Value


7 INT7 External Interrupt Request 7 0
6 INT6 External Interrupt Request 6 0
5 INT5 External Interrupt Request 5 1
4 INT4 External Interrupt Request 4 1
3 INT3 External Interrupt Request 3 0
2 INT2 External Interrupt Request 2 0
1 INT1 External Interrupt Request 1 0
0 INT0 External Interrupt Request 0 0

EIMSK = 0x30

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 9/16


Sources of Interrupt
Position Encoder
Interrupt Calculation
Outline SREG-Register
Interrupts EIMSK
Interrupt-Handling on Firebird EICRA
EICRB
ISR
C-Code

EICRA- External Interrupt Control Register A


This register is Used to generate Interrupt Signal

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 10/16


Sources of Interrupt
Position Encoder
Interrupt Calculation
Outline SREG-Register
Interrupts EIMSK
Interrupt-Handling on Firebird EICRA
EICRB
ISR
C-Code

EICRA- External Interrupt Control Register A


This register is Used to generate Interrupt Signal

Bit Symbol Description Bit Value


7 ISC31 Interrupt Sense control bit for Ext. Interrupt 3 0
6 ISC30 Interrupt Sense control bit for Ext. Interrupt 3 0
5 ISC21 Interrupt Sense control bit for Ext. Interrupt 2 0
4 ISC20 Interrupt Sense control bit for Ext. Interrupt 2 0
3 ISC11 Interrupt Sense control bit for Ext. Interrupt 1 0
2 ISC10 Interrupt Sense control bit for Ext. Interrupt 1 0
1 ISC01 Interrupt Sense control bit for Ext. Interrupt 0 0
0 ISC00 Interrupt Sense control bit for Ext. Interrupt 0 0

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 10/16


Sources of Interrupt
Position Encoder
Interrupt Calculation
Outline SREG-Register
Interrupts EIMSK
Interrupt-Handling on Firebird EICRA
EICRB
ISR
C-Code

EICRA- External Interrupt Control Register A


This register is Used to generate Interrupt Signal

Bit Symbol Description Bit Value


7 ISC31 Interrupt Sense control bit for Ext. Interrupt 3 0
6 ISC30 Interrupt Sense control bit for Ext. Interrupt 3 0
5 ISC21 Interrupt Sense control bit for Ext. Interrupt 2 0
4 ISC20 Interrupt Sense control bit for Ext. Interrupt 2 0
3 ISC11 Interrupt Sense control bit for Ext. Interrupt 1 0
2 ISC10 Interrupt Sense control bit for Ext. Interrupt 1 0
1 ISC01 Interrupt Sense control bit for Ext. Interrupt 0 0
0 ISC00 Interrupt Sense control bit for Ext. Interrupt 0 0

EICRA = 0x00

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 10/16


Sources of Interrupt
Position Encoder
Interrupt Calculation
Outline SREG-Register
Interrupts EIMSK
Interrupt-Handling on Firebird EICRA
EICRB
ISR
C-Code

EICRB- External Interrupt Control Register B


This register is Used to generate Interrupt Signal

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 11/16


Sources of Interrupt
Position Encoder
Interrupt Calculation
Outline SREG-Register
Interrupts EIMSK
Interrupt-Handling on Firebird EICRA
EICRB
ISR
C-Code

EICRB- External Interrupt Control Register B


This register is Used to generate Interrupt Signal

Bit Symbol Description Bit Value


7 ISC71 Interrupt Sense control bit for Ext. Interrupt 7 0
6 ISC70 Interrupt Sense control bit for Ext. Interrupt 7 0
5 ISC61 Interrupt Sense control bit for Ext. Interrupt 6 0
4 ISC60 Interrupt Sense control bit for Ext. Interrupt 6 0
3 ISC51 Interrupt Sense control bit for Ext. Interrupt 5 1
2 ISC50 Interrupt Sense control bit for Ext. Interrupt 5 0
1 ISC41 Interrupt Sense control bit for Ext. Interrupt 4 1
0 ISC40 Interrupt Sense control bit for Ext. Interrupt 4 0

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 11/16


Sources of Interrupt
Position Encoder
Interrupt Calculation
Outline SREG-Register
Interrupts EIMSK
Interrupt-Handling on Firebird EICRA
EICRB
ISR
C-Code

EICRB- External Interrupt Control Register B


This register is Used to generate Interrupt Signal

Bit Symbol Description Bit Value


7 ISC71 Interrupt Sense control bit for Ext. Interrupt 7 0
6 ISC70 Interrupt Sense control bit for Ext. Interrupt 7 0
5 ISC61 Interrupt Sense control bit for Ext. Interrupt 6 0
4 ISC60 Interrupt Sense control bit for Ext. Interrupt 6 0
3 ISC51 Interrupt Sense control bit for Ext. Interrupt 5 1
2 ISC50 Interrupt Sense control bit for Ext. Interrupt 5 0
1 ISC41 Interrupt Sense control bit for Ext. Interrupt 4 1
0 ISC40 Interrupt Sense control bit for Ext. Interrupt 4 0

EICRB = 0x0A

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 11/16


Sources of Interrupt
Position Encoder
Interrupt Calculation
Outline SREG-Register
Interrupts EIMSK
Interrupt-Handling on Firebird EICRA
EICRB
ISR
C-Code

Interrupt Sense Control Bit

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 12/16


Sources of Interrupt
Position Encoder
Interrupt Calculation
Outline SREG-Register
Interrupts EIMSK
Interrupt-Handling on Firebird EICRA
EICRB
ISR
C-Code

Interrupt Sense Control Bit

ISCn1 ISCn0 Description


0 0 The low level of INTn generates an Interrupt request
0 1 Any edge of INTn generates asynchronously an interrupt request
1 0 The falling edge of INTn generates asynchronously an interrupt request
1 1 The rising edge of INTn generates asynchronously an interrupt request

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 12/16


Sources of Interrupt
Position Encoder
Interrupt Calculation
Outline SREG-Register
Interrupts EIMSK
Interrupt-Handling on Firebird EICRA
EICRB
ISR
C-Code

ISR-Interrupt Service Routine

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 13/16


Sources of Interrupt
Position Encoder
Interrupt Calculation
Outline SREG-Register
Interrupts EIMSK
Interrupt-Handling on Firebird EICRA
EICRB
ISR
C-Code

ISR-Interrupt Service Routine

The format of ISR for external interrupt is

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 13/16


Sources of Interrupt
Position Encoder
Interrupt Calculation
Outline SREG-Register
Interrupts EIMSK
Interrupt-Handling on Firebird EICRA
EICRB
ISR
C-Code

ISR-Interrupt Service Routine

The format of ISR for external interrupt is

ISR Format

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 13/16


Sources of Interrupt
Position Encoder
Interrupt Calculation
Outline SREG-Register
Interrupts EIMSK
Interrupt-Handling on Firebird EICRA
EICRB
ISR
C-Code

ISR-Interrupt Service Routine

The format of ISR for external interrupt is

ISR Format
ISR(INTn_vect)
{
code
}

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 13/16


Sources of Interrupt
Position Encoder
Interrupt Calculation
Outline SREG-Register
Interrupts EIMSK
Interrupt-Handling on Firebird EICRA
EICRB
ISR
C-Code

ISR-Interrupt Service Routine

The format of ISR for external interrupt is

ISR Format
ISR(INTn_vect)
{
code
}

Where n = External Interrupt Number (For Atmega2560: n=0-7)

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 13/16


Sources of Interrupt
Position Encoder
Interrupt Calculation
Outline SREG-Register
Interrupts EIMSK
Interrupt-Handling on Firebird EICRA
EICRB
ISR
C-Code

Syntax for C-Program


Port Initialization

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 14/16


Sources of Interrupt
Position Encoder
Interrupt Calculation
Outline SREG-Register
Interrupts EIMSK
Interrupt-Handling on Firebird EICRA
EICRB
ISR
C-Code

Syntax for C-Program


Port Initialization

Left Encoder Port Initialization

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 14/16


Sources of Interrupt
Position Encoder
Interrupt Calculation
Outline SREG-Register
Interrupts EIMSK
Interrupt-Handling on Firebird EICRA
EICRB
ISR
C-Code

Syntax for C-Program


Port Initialization

Left Encoder Port Initialization


void left_encoder_pin_config (void) //Configure Interrupt 4
{

DDRE = DDRE & 0xEF; //Set the direction of the PORTE 4 pin as input
PORTE = PORTE | 0x10; //Enable internal pull-up for PORTE 4 pin

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 14/16


Sources of Interrupt
Position Encoder
Interrupt Calculation
Outline SREG-Register
Interrupts EIMSK
Interrupt-Handling on Firebird EICRA
EICRB
ISR
C-Code

Syntax for C-Program


Port Initialization

Left Encoder Port Initialization


void left_encoder_pin_config (void) //Configure Interrupt 4
{

DDRE = DDRE & 0xEF; //Set the direction of the PORTE 4 pin as input
PORTE = PORTE | 0x10; //Enable internal pull-up for PORTE 4 pin

Right Encoder Port Initialization

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 14/16


Sources of Interrupt
Position Encoder
Interrupt Calculation
Outline SREG-Register
Interrupts EIMSK
Interrupt-Handling on Firebird EICRA
EICRB
ISR
C-Code

Syntax for C-Program


Port Initialization

Left Encoder Port Initialization


void left_encoder_pin_config (void) //Configure Interrupt 4
{

DDRE = DDRE & 0xEF; //Set the direction of the PORTE 4 pin as input
PORTE = PORTE | 0x10; //Enable internal pull-up for PORTE 4 pin

Right Encoder Port Initialization


void right_encoder_pin_config (void) //Configure Interrupt 5
{

DDRE = DDRE & 0xDF; //Set the direction of the PORTE 4 pin as input
PORTE = PORTE | 0x20; //Enable internal pull-up for PORTE 4 pin

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 14/16


Sources of Interrupt
Position Encoder
Interrupt Calculation
Outline SREG-Register
Interrupts EIMSK
Interrupt-Handling on Firebird EICRA
EICRB
ISR
C-Code

Syntax for C-Program


Interrupt Initialization

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 15/16


Sources of Interrupt
Position Encoder
Interrupt Calculation
Outline SREG-Register
Interrupts EIMSK
Interrupt-Handling on Firebird EICRA
EICRB
ISR
C-Code

Syntax for C-Program


Interrupt Initialization

Left-Encoder Interrupt Initialization

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 15/16


Sources of Interrupt
Position Encoder
Interrupt Calculation
Outline SREG-Register
Interrupts EIMSK
Interrupt-Handling on Firebird EICRA
EICRB
ISR
C-Code

Syntax for C-Program


Interrupt Initialization

Left-Encoder Interrupt Initialization


void left_position_encoder_interrupt_init (void) //Interrupt 4 enable
{
cli(); //Clears the global interrupt
EICRB = EICRB | 0x02; // INT4 is set to trigger with falling edge
EIMSK = EIMSK | 0x10; // Enable Interrupt INT4 for left position encoder
sei(); // Enables the global interrupt
}

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 15/16


Sources of Interrupt
Position Encoder
Interrupt Calculation
Outline SREG-Register
Interrupts EIMSK
Interrupt-Handling on Firebird EICRA
EICRB
ISR
C-Code

Syntax for C-Program


Interrupt Initialization

Left-Encoder Interrupt Initialization


void left_position_encoder_interrupt_init (void) //Interrupt 4 enable
{
cli(); //Clears the global interrupt
EICRB = EICRB | 0x02; // INT4 is set to trigger with falling edge
EIMSK = EIMSK | 0x10; // Enable Interrupt INT4 for left position encoder
sei(); // Enables the global interrupt
}

Right-Encoder Interrupt Initialization

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 15/16


Sources of Interrupt
Position Encoder
Interrupt Calculation
Outline SREG-Register
Interrupts EIMSK
Interrupt-Handling on Firebird EICRA
EICRB
ISR
C-Code

Syntax for C-Program


Interrupt Initialization

Left-Encoder Interrupt Initialization


void left_position_encoder_interrupt_init (void) //Interrupt 4 enable
{
cli(); //Clears the global interrupt
EICRB = EICRB | 0x02; // INT4 is set to trigger with falling edge
EIMSK = EIMSK | 0x10; // Enable Interrupt INT4 for left position encoder
sei(); // Enables the global interrupt
}

Right-Encoder Interrupt Initialization


void right_position_encoder_interrupt_init (void) //Interrupt 5 enable
{
cli(); //Clears the global interrupt
EICRB = EICRB | 0x08; // INT5 is set to trigger with falling edge
EIMSK = EIMSK | 0x20; // Enable Interrupt INT5 for left position encoder
sei(); // Enables the global interrupt
}

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 15/16


Sources of Interrupt
Position Encoder
Interrupt Calculation
Outline SREG-Register
Interrupts EIMSK
Interrupt-Handling on Firebird EICRA
EICRB
ISR
C-Code

Thank You!
Post your queries on: http://qa.e-yantra.org/

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 16/16

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy