0% found this document useful (0 votes)
73 views16 pages

Role of Interrupts

The document discusses interrupts in microcontrollers. It explains that interrupts allow a microcontroller to respond to unscheduled external or internal events by pausing the current program and executing an interrupt service routine (ISR). There are two types of interrupts - hardware interrupts from external pins and software interrupts triggered by code. The attachInterrupt function attaches an ISR to run when an interrupt occurs. Common interrupts include timer overflows and ADC conversions.

Uploaded by

HOD-DCE PSG-PTC
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
73 views16 pages

Role of Interrupts

The document discusses interrupts in microcontrollers. It explains that interrupts allow a microcontroller to respond to unscheduled external or internal events by pausing the current program and executing an interrupt service routine (ISR). There are two types of interrupts - hardware interrupts from external pins and software interrupts triggered by code. The attachInterrupt function attaches an ISR to run when an interrupt occurs. Common interrupts include timer overflows and ADC conversions.

Uploaded by

HOD-DCE PSG-PTC
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 16

The Role of Interrupts

• A microcontroller normally executes instructions in an orderly fetch-execute


sequence as dictated by a user-written program.
• A microcontroller must also be ready to handle unscheduled, events that
might occur inside or outside the microcontroller.
• The interrupt system allows it to respond to these internally and externally
generated events.
• When an interrupt event occurs, the microcontroller will normally complete
the instruction it is currently executing and then transition program control
to an Interrupt Service Routine (ISR). The ISR handles the interrupt.
• Once the ISR is complete, the microcontroller will resume processing where
it left off before the interrupt event occurred.
Types of Interrupts
There are two types of interrupts −
• Hardware Interrupts − They occur in response to an external event, such as an external interrupt pin
going high or low.
• Software Interrupts − They occur in response to an instruction sent in software. The only type of
interrupt that the “Arduino language” supports is the attachInterrupt() function.

attachInterrupt Statement Syntax


• attachInterrupt(digitalPinToInterrupt(pin),ISR,mode); //recommended for Arduino board
• attachInterrupt(pin, ISR, mode) ; //recommended Arduino Due, Zero only
pin: the pin number, ISR: the ISR to call when the interrupt occurs; mode defines when the interrupt be triggered.

The following three constants are predefined as valid values −


• LOW - trigger the interrupt whenever the pin is low.
• CHANGE - trigger the interrupt whenever the pin changes value.
• FALLING - whenever the pin goes from high to low.
• RISING - whenever the pin goes from low to high.
• HIGH - trigger the interrupt whenever the pin is high.
Example : Interrupt – When a button is pressed the LED had to change its state

int pin = 2; //define interrupt pin to 2


volatile int state = LOW; // To make sure variables shared between an ISR
//the main program are updated correctly ,declare them as volatile.

void setup() {
pinMode(13, OUTPUT); //set pin 13 as output
attachInterrupt(digitalPinToInterrupt(pin), blink, RISING); //interrupt at pin 2 blink ISR when
pin to change the value
}

void loop() {
digitalWrite(13, state); //pin 13 equal the state value
}

void blink() { //ISR function


state = !state; //toggle the state when the interrupt occurs
}
Address location of selected Interrupts

Program Address(Hex) Interrupt Source Interrupt Description


002 INT0 External Interrupt Request 0
004 INT10 External Interrupt Request 1
016 Timer 0 Overflow Timer/counter 0 overflow
018 SPI, STC Serial Transfer Complete
01A UART, RXC USART Data Receive Complete
01C UART, UDRE USART Data Register Empty
01E UART, TXC USART Data Transmit Complete
020 ADC ADC Conversion Complete
Analog to Digital Converter
• The ADC is used to convert analog information into digital information.
• There are several techniques used for ADC architectures.
• Commonly used technique is Successive Approximation(SA).
• The SA architecture consists of a SA register (SAR), a DAC(digital to analog
converter), a comparator and a sample and hold circuit.
• The unknown signal Vin is brought to a comparator where it is compared
with the different values generated by the digital analog converter(DAC).
• The comparator output tells the register if the DAC generated weight is
less than or greater than the unknown value.
• The number of clock cycles needed for conversion is equal to the
resolution of the ADC. Thus an 8-bit SA ADC will need 8 conversion clock
cycles.
Block Diagram of a Successive Approximation analog to digital converter

EoC
CLOCK Successive
Approximation
Register (SAR)

Vref Digital to Analog


Converter (DAC)

--

Vin Sample
and +
Hold Comparator
Steps to determine the digital value of the input signal
Clock Cycle Output of Comparator O/P Retain Comment
or Step SAR/DAC Input =153 Weight
1 128 153 >128 1 (Yes) Scan with the median weight of
128 = 10000000
2 128 + 64 =192 153 < 192 0 (No) Discard the new weight of 64 and try a lower
weight
3 128 + 32 = 160 153 < 160 0 (No) Discard32 since the output is greater than
153
4 128 +16 =144 153 > 144 1 (Yes) Retain 16 since the input signal is greater
5 128 +16 + 8 = 152 153 > 152 1 (Yes) Retain 8 since the input signal is still greater
6 128 + 16 + 8 + 4 = 153 < 156 0 (No) Discard 4 as the DAC output becomes greater
156
7 128 + 16 + 8 + 2 = 153 < 154 0 (No) Discard 2 as the DAC output becomes greater
154
8 128 + 16 + 8 + 1 = 153 = 153 1 (Yes) Right value found, signal end of Conversion
153 (EoC)
Arduino Analog input pins
• Arduino Uno has 6 0n-board ADC channels which can be
used to read analog signal in the range 0-5V.
• It has 10-bit ADC means it will give digital value in the range of
0 – 1023 (2^10).
•  Resolution - indicates the number of discrete values it can
produce over the range of analog values.

• Digital Output value Calculation


ADC Resolution = Vref / ((2^n) - 1)
Digital Output = Vin / Resolution
Vref - The reference voltage is the maximum value that the
ADC can convert.
Analog Input pins
Analog Functions for Arduino ADC

• analogRead (pin)
• This function is used to read analog value from specified analog pin.
• pin - number of analog pin which we want to read
• returns - digital value 0 – 1023
• e.g. analogRead(A0) //read analog value at A0 channel

• analogReference (type)
• This function is used for configuring the reference voltage used for
analog input.
Read Analog Voltage using Arduino Uno

• ADC provide digital output which is proportional to analog value.


• To convert the digital value to analog input voltage:
Aout = digital value * (Vref/2^n – 1)

• e.g. digital value = 512 and ADC is 10-bit with 5V Vref.


• Analog voltage to respective digital value is as
Aout = 512 * (5 V / 1023)
          = 2.5 V
Problems in ADC

1. For an 8-bit ADC when Vref is 5 V and Vin is 3V. Find the digital equivalent
• ADC Resolution = Vref / ((2^n) - 1)
• Digital Output = Vin / Resolution
• Digital Output = (Vin/Vref)*255 = 153 Resolution =2^8 – 1 = 255
= 10011001
2. Find the ADC register count value when a 12-bit ADC with Vref of 3.3V is given an
input voltage of 2V
• Full scale count = 2^12=4096.
• The converted ADC value is equal to
( Vin / Vref ) * fullscale counts = (2/3.3)*4096 = 2483 counts

You might also like