Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
82 views

ADC Lecture14

1) The document discusses using the ADC12 analog-to-digital converter on the MSP430 microcontroller. It describes the converter's features and how to configure and use it. 2) It provides an example of using the ADC12 to implement a digital current meter that measures from 0 to 1A with 1mA accuracy by mapping the current range to the ADC12's input voltage range. 3) The document outlines the steps needed to use the ADC12: select operating mode, choose input channels, enable interrupts, and start conversions.

Uploaded by

Angel Daniella
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
82 views

ADC Lecture14

1) The document discusses using the ADC12 analog-to-digital converter on the MSP430 microcontroller. It describes the converter's features and how to configure and use it. 2) It provides an example of using the ADC12 to implement a digital current meter that measures from 0 to 1A with 1mA accuracy by mapping the current range to the ADC12's input voltage range. 3) The document outlines the steps needed to use the ADC12: select operating mode, choose input channels, enable interrupts, and start conversions.

Uploaded by

Angel Daniella
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

ECE2049:EmbeddedComputinginEngineeringDesign

ATermFall2015
Lecture#14:UsingtheADC12AnalogtoDigitalConverter
ReadingforToday:
ReadingforNextClass:
HW#4(oweb):
Lab#2(onweb):

Davies9.23,9.7,MSP430User'sGuideCh28
Examplecode
DueMonday9/28/2015
Bonussignoff9/25(5pm).ReportdueTues9/29
(inclass)
Exam#2Tuesday9/29/2015

LastClass:
>>IntroductiontoAnalogtoDigitalConversion
>>MappinganalogsensorstoanADC(FSR,Resolution,DynamicRange)
Example.Asimpledigitalcurrentmetermightmeasurecurrentbymeasuringthe
voltageacrossasmallsensingresistor.HowcouldweusetheADC12tomeasure
acrosstherange0to1Ato1mAaccuracy?Canweget0.1mAaccuracy?

>>>KnowinghowyourexternalsensorworksandhowtomapittotheADC
you'reusingisascriticalasknowinghowtoprogramthemicroprocessortoreadthe
ADC!!
MSP430F5529AnalogtoDigitalConverter(ADC12_A)
16channel,12bitsampleandholdADC(200ksamplespersecondmax)
12ExternalAnalogInputsA0A7,A1215usesamepinsasPorts6&7
4internalAnalogInputsA8A11
Configureandusebysettingvaluesinvariouscontrolregisters
ADC12CTL0controlsthefollowingoptions
SampleandHoldtime(ADC12SHT1xandADC12SHT0x)
Multiplesampleconversionmethod(ADC12MSC)
ReferenceVoltages(ADC12REF2_5VandADC12REF_ON)
ADC12ONbit

Enableandstartconversion(ADC12ENCandADC12SC)
Overflow/Conversiontimeint.enables(ADC120VIE,ADC12TVIE)

ADC12CTL1controlsthefollowingoptions
Conversionstartaddress(ADC12CSTARTADDx)
Sampleandholdsourceselect(ADC12SHSx)
SampleandHoldpulsemodeselectable(ADC12SHP)
Invertsignalsampleandhold(ADC12ISSH)
ADC12clockdivider(ADC12DIVx)
ADC12clocksourceselect(ADC12SSELx)
Conversionmodeselect(ADC12CONSEQx)

ADC12busy/conversionnotcompletebit(ADC12BSY)

>>Resultsfromeachchannelarestoredinthelow12bitsofoneof16
ConversionMemoryRegisters(ADC12MEMx)

>>EachmemoryregisterhasacorrespondingConversionMemoryControl
Register(ADC12MCTLx)
EachADC12MCTLxcontrolsthefollowingoptionsforitsMemoryRegister
EndofSequence(EOS)=Isthischanneltheendonasequenceof
channelsthataretobeconverted
SelectReferenceVoltages(ADC12SREFx)=

Analoginputchannelselection(ADC12INCHx)=

SowhatdoestheprogrammerneedtodotouseADC12_A?
1)SelectADCCoreBehavior:InADC12CTL0andADC12CTL1registers
Clocksourceanddivider

Sampleandholdbehavior

ReferenceVoltages

2)SelectConversionModerequired:ADC12CONSEQxbitsinADC12CTL1reg
Singlechannelorasequenceofchannels
Alsosingleconversionorrepeatedconversions
3)Selectinputchannel(s):INCHxbitsinADCMCTLxregisters
>>ADC12has12(external)analoginputsignalsand4internalinputs
>ADC12'sExternalAnalogInputsA0A7andA12A15are
multiplexedwithPort6and7pins!
Ex:AssumeinputchannelsA6andA7aretobeusedwithADC12_A.ThePort
Selectionbitsforthosepinsshouldbesetto1=FunctionSelect

>>Internalinputchannels8,9&11(ADC12INCHx=1000,1001,1011)
areconnectedtodifferentchipreferencevoltages
Couldbeusedtodohealthmonitoring
>>Internalinputchannel10(ADC12INCH_10=1010)isconnectedtoan
internalTemperatureSensor.

4)EnableappropriateinterruptsADC12IEregister
Donothavetouseinterrupts,butusefulforrepeatedmeasurements
WriteISR(shouldhandleallpossibleADCinterruptswithsome
defaultbehavior...aswitchstatement)

5)EnableandStartConversion(s)ADC1CTL0register
Ex.Continuingonwiththedigitalcurrentmeter,assumethatthegainGissetso
1Aequalsthefullscalevoltageof2.5V.Assumethatthetheanaloginputvoltage
isappliedtoA0.HowwouldwesettheADC12registers?

// Some code to implement the current sensor example from last


// class. Input voltage range 0 to 2.5V corresponds to 0 to 1A.
unsigned int
in_value;
// Reset REFMSTR to hand over control of internal reference
// voltages to ADC12_A control registers
REFCTL0 &= ~REFMSTR;
//
//
//
//

Initialize control register ADC12CTL0 = 0000 1001 0111 0000


ADC12SHT0x = 9h (384 clk cycles), MCS = 0 = no burst mode
ADC12 REF2_5V = 1 (2.5V), ADCREFON = 1 = use internal ref volt
and ADC12ON = 1 = turn ADC on
ADC12CTL0 = ADC12SHT0_9|ADC12REFON|ADC12REF2_5V|ADC12ON;

//
//
//
//
//
//
//
//
//

Initialize control register ADC12CTL1 = 0000 0010 0000 0000


ADC12CSTART ADDx = 0000 = start conversion with ADC12MEM0,
ADC12SHSx = 00 = use SW conversion trigger, ADC12SC bits
ADC12SHP = 1 = SAMPCON signal sourced from sampling timer,
ADC12ISSH = 0 = sample input signal not inverted,
ADC12DIVx = 000= divide ADC12CLK by 1,
ADC12SSEL=00= ADC clock ADC12OSC (~5 MHz),
ADC12CONSEQx = 00 single channel, single conversion,
ADC12BUSY = 0 = no ADC operation active
ADC12CTL1 = SHP;

// Set conversion mem control register ADC12MCTL0 = 0001 0000


// EOS = 0, SREF =001 -->Voltage refs = GND to (Vref+)
// INCHx = 0000 = analog input from A0
ADC12MCTL0 = ADC12SREF_1 + ADC12INCH_0;
P6SEL |= BIT0; // Set Port 6 Pin 0 to FUNCTION mode for ADC
ADC12CTL0 &= ~ADC12SC;
// clear the start bit
//Enable and start (single) conversion (not using ADC int)
ADC12CTL0 |= ADC12SC + ADC12ENC;
// Poll busy bit waiting for conversion to complete
while (ADC12CTL1 & ADC12BUSY)
__no_operation();
in_value = ADC12MEM0 & 0x0FFF;

// keep only low 12 bits

>>HowwouldweusetheresultsfromtheADCinourprogram?

You might also like