MSP430 Adc

You might also like

Download as ppsx, pdf, or txt
Download as ppsx, pdf, or txt
You are on page 1of 19

MSP430 ADC

---PRASANNA KUMAR M

Note: For better understanding I have added animation to this presentation,


• Please wait for the animation to complete
• When the animation is complete, click for explanation
Analog Signal Vs Digital Signal
• Analog signals are directly measurable quantities. (measure
one quantity in terms of some other quantity)

Ex: Speedo meter needle with respect to speed


• Digital signals only have two states. For digital computer, we
refer to binary states, 0 and 1.

Ex : Switch can be either ON or OFF


Door to a room is either open or close!
What is ADC?
• An Analog Integrated Circuit which converts Signal
from Analog(Continuous) signal to Digital(Discrete)
form.
• Provides a link between Analog world of transducer
and Digital world of Signal processing and data
handling
ADC Conversion process
• Sample and Hold Taking the Sample at uniform Quantizing: Breaking down
interval of time analog value to a set of finite
• Quantization and Encoding states

Encoding: Assigning a digital


value to each state
Quantization and Encoding
• Ex: Assume we have Analog input Vin = 0 to 10V, ie., Vmin = 0V and Vmax = 10V
• If we convert input Vin to 3 bit Digital O/P say,
Then, we need to breakdown analog value to a set of finite states
Quantization
ie., Q = (Vmax – Vmin)/2no. of Bits
Therefore
Q = (10 – 0)/23
Q = 1.25
• 10V input is equally breakdown 1.25V apart and there are 8 Finite states
• Q is also called the Resolution of ADC( for every 1.25V change in the
input there will be 1 bit change in the output).
Quantization and Encoding
• Encoding is Assigning a digital value to each state
Any voltage between
0.00 to 1.25 is
3 Bit Digital O/P converted to digital
o/p 000
000

001

010

011 In order to observe


change in the o/p,
100 there must be
change of 1.2V at the
101 input( This is called
110 Resolution of ADC)

111
MSP430 ADC
Features:
• MSP430F5529 has 12-bit ADC
• 16 individually configurable input channels : 12 external input channels
and 4 internal input channels.
• Has Internal Temperature Sensor
• On-chip reference voltage generator called REF module that can
generate accurate voltage references  1.5V, 2.0V and 2.5V reference
voltages
• 4 clock source(ADCOSC,ACLK,MCLK,SMCLK) available for ADC
• Sample-and-hold circuitry offers programmable sampling periods via
timers or software.
• 16 Result register; one for each channel.
MSP430 ADC
MSP430F5529 has 12- Software configurable
bit ADC, which converts Reference Voltage
analog input to 12-bit generator(1.5/2.0/2.5V)
Digital Value. for accurate conversion.

MSP430F5529 has 16
Analog Input Channel There are 4 clock source
12- External available ADC module
4 – Internal which is software
Any one of the Analog selectable.
source can be selected
for the conversion.
Sample-and-hold
MSP430F5529 has circuitry offers
Internal Temperature programmable sampling
sensor, is one of the periods via timers or
internal analog input software
source
16 Result Registers; the 12 bit Digital
output are available in these registers;
one for each of the channel
MSP430 ADC Registers
1.0) ADC12MCTL0:ADC12_A Memory
Control 0
Using this register we can select the
Analog input channel.
• In the program, we have selected
Channel-0 (Analog Input-0  A0 pin)
• Analog input Pin A0 is multiplexed with
P6.0
ADC12MCTL0 = 0x00;

Change this value for


analog input at different
channel need to be
converted to Digital.
MSP430 ADC Registers
2.0) ADC12CTL0:ADC Control Register-0
Using this register we can
Configure the sampling rates
and Switch ON ADC module
• In the program, the sampling rate
selected is 64 clock cycles
• ADC module is Switched ON using
ADC12ON

ADC12CTL0 = ADC12SHT02 + ADC12ON;


MSP430 ADC Registers
3.0) ADC12CTL1:ADC Control Register-1
Using this register we can
Configure the sampling rates
Generated by sampling timer

ADC12CTL1 = ADC12SHP;
MSP430 ADC Registers
2.1) ADC12CTL0:ADC Control Register-0
• Enable ADC
• Start Conversion

ADC12CTL0 |= ADC12ENC;
ADC12CTL0 |= ADC12SC;
MSP430 ADC Registers
3.1) ADC12CTL1:ADC Control Register-1
To convert analog input to Digital, ADC
Will take some time;
So, Wait for conversion to get over

While(ADC12CTL1 & ADC12BUSY);

When the Conversion is in progress,


ADC12BUSY bit will be at Logic -1.
As Soon as conversion is over,
this bit Clear to Logic -0.
MSP430 ADC

4) ADC12MEM0
-- Conversion Memory Register
of channel – 0 (A0)
• After A/D conversion, 12bit Digital
Value will be in this Register.
MSP430 ADC Program example

3.3V

P1.0
P6.0/A0

2 V
5K Pot
Pot + MSP430F5529

Pot -
ADC

Resolution = Vref/ 2N
3.3V/212 4096
Digital Value(in Decimal)
= 0.00080566V Reference Voltage = 3.3 V
N = 12 Bit
MSP430 ADC Program example
#include <msp430f5529.h> Configure P6.0 for analog
Start conversion input A0 function
unsigned int value_adc=0;

int main(void)
{ Configure P1.0 as O/P Pin
WDTCTL = WDTPW + WDTHOLD; // Stop WDT

P6SEL |= 0x01; // P6.0 ADC option select


P1DIR |= 0x01; // P1.0 output Select Analog Input A0
ADC12MCTL0 = 0x00; //Select the P6.0/A0 channel Channel for conversion
ADC12CTL0 = ADC12SHT02 + ADC12ON; // Sampling time, ADC12 on
ADC12CTL1 = ADC12SHP;
ADC12CTL0 |= ADC12ENC;
// Use sampling timer
Configure ADC for 64 cycle
sample and Hold, and Turn
while (1)
{ ON ADC module
ADC12CTL0 |= ADC12SC; // Start sampling/conversion
while (ADC12CTL1 & ADC12BUSY)
{
__no_operation(); // Could just leave body of loop empty Select the 64 cycle sample
}
value_adc=ADC12MEM0; // Read the result in ADC12MEM0 to variable value_adc
clock from Sample timer
if(value_adc>=512)
P1OUT |= BIT0; // P1.0 = 1 Switch ON LED if value_adc is greater than 512
else Enable the ADC for
P1OUT &= ~BIT0; // P1.0 = 0 Switch OFF LED if value_adc is lesser than 512
} conversion
}
Read the Digital Value in Wait for conversion to get over.
Switch ON or Switch OFF
ADC12MEM0 register to variable ADC12BUSY bit will clear when
LED based on value_adc.
value_adc Conversion is complete
MSP430 ADC Program example
#include <msp430f5529.h>

unsigned int value_adc=0;

int main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT

P6SEL |= 0x01; // P6.0 ADC option select


P1DIR |= 0x01; // P1.0 output

ADC12MCTL0 = 0x00; //Select the P6.0/A0 channel


ADC12CTL0 = ADC12SHT02 + ADC12ON; // Sampling time, ADC12 on
ADC12CTL1 = ADC12SHP; // Use sampling timer
ADC12CTL0 |= ADC12ENC;

while (1)
{
ADC12CTL0 |= ADC12SC; // Start sampling/conversion
while (ADC12CTL1 & ADC12BUSY)
{
__no_operation(); // Could just leave body of loop empty
}
value_adc=ADC12MEM0; // Read the result in ADC12MEM0 to variable value_adc

if(value_adc>=512)
P1OUT |= BIT0; // P1.0 = 1 Switch ON LED if value_adc is greater than 512
else
P1OUT &= ~BIT0; // P1.0 = 0 Switch OFF LED if value_adc is lesser than 512
}

}
MSP430 Demo
Thank you

You might also like