ADC14¶
The MSP432P401R contains a single analog-to-digital converter (ADC) labelled ADC14. This module is capable of converting up to 32 independent analog inputs, or channels. It can be operated in a single-ended mode (using one channel) or differential mode (using two channels).
The module uses two references voltages, labelled \(V_\mathrm{R+}\) and \(V_\mathrm{R-}\) for the maximum and minimum voltage values, respectively. The maximum (positive) voltage reference, \(V_\mathrm{R+}\), is selectable among internally generated 1.2 V, 1.45 V, or 2.5 V sources; the 3.3 V power source; or can use an externally sourced reference (VREF+). The minimum (negative) voltage reference, \(V_\mathrm{R-}\), may either be selected as 0 V or from an externally sourced reference voltage (VREF-). The externally sourced references voltages, VREF+ and VREF-, must be greater than or equal to 0 V and less than or equal to the microcontroller’s power supply, e.g., 3.3 V.
For single-ended mode, the ADC14 conversion output follows the equation:
where \(N_\mathrm{bits}\) if the configured bitwise resolution of the ADC14 and \(V_\mathrm{in+}\) is the input voltage.
For differential mode, the ADC14 conversion output follows the equation:
where \(V_\mathrm{in-}\) is the second input voltage. Note that if \(V_\mathrm{in+}-V_\mathrm{in-} == 0\), the output will be: \(N_\mathrm{ADC} = 8192\) for a 14-bit resolution conversion.
The ADC14 also has 32 memory locations locations to store conversion results. These are configured to be associated with a single ADC input channel.
Many of the DriverLib functions provided below return a bool
type variable, which provides either a true
(1) or false
(0) for if the requested operation succeeded or failed.
Sample Modes¶
The ADC14 can operate in four distinct modes:
Single-channel, single-sample: Conversion of a single channel is performed when the ADC14 receive a conversion trigger.
Multi-sequence, single-sample: A single sample for a sequence of channels is converted when the ADC14 receives a conversion trigger.
Single-channel, continuous-samples: Conversion of a single channel in a repeated fashion. Once a conversion is complete, the process immediately restarts.
Multi-sequence, continuous-samples: A sequence of channels is converted continuously in order. Once a conversion is complete for all channels in the sequence, the process immediately restarts.
These modes are selected through either void ADC14_configureSingleSampleMode()
or void ADC14_configureMultiSequenceMode()
.
Configuration¶
A subset of the complete set of ADC14 configuration functions are provided below.
void ADC14_enableModule( void )
/bool ADC14_disableModule( void )
: Enable/disable the ADC14 module. If the ADC14 is disabled, no conversions are possible.bool ADC14_initModule( uint32_t clockSource , uint32_t clockPredivider ,
uint32_t clockDivider , uint32_t internalChannelMask )
: Provides initial configuration of the ADC14 module. The arguments are:uint32_t clockSource
: Select the clock source to drive the ADC14 module. Valid values are:ADC_CLOCKSOURCE_ADCOSC
: Use MODCLKADC_CLOCKSOURCE_SYSOSC
: Use SYSCLKADC_CLOCKSOURCE_ACLK
ADC_CLOCKSOURCE_MCLK
ADC_CLOCKSOURCE_SMCLK
<– A good option!ADC_CLOCKSOURCE_HSMCLK
uint32_t clockPredivider
: Specify the first division for theclockSource
. Valid values areADC_PREDIVIDER_x
wherex
is1
,4
,32
, or64
.uint32_t clockDivider
: Specify the second division for theclockSource
. Valid values areADC_DIVIDER_x
wherex
is1
to8
.internalChannelMask
: Configure the mapping of the internal lines of the ADC14. No mapping is required for this course. Always specify this argument as0
orADC_NOROUTE
.
bool ADC14_configureConversionMemory( uint32_t memorySelect , uint32_t refSelect ,
uint32_t channelSelect , bool differentialMode )
: Configure a conversion channel. The arguments are:uint32_t memorySelect
: Select the ADC14 memory location to configure. Valid values areADC_MEM0
throughADC_MEM31
.uint32_t refSelect
: Select the maximum and minimum sources for the reference voltages. Valid values are:ADC_VREFPOS_AVCC_VREFNEG_VSS
: Use the chip power supplies as the voltage references. When using the MSP432P401R, AVCC is 3.3 V and VSS is 0 V.ADC_VREFPOS_INTBUF_VREFNEG_VSS
: Use the voltage generated by the REF_A Module for the positive voltage reference and VSS (0 V) for the negative voltage reference.ADC_VREFPOS_EXTPOS_VREFNEG_EXTNEG
: Use the voltages connected to the external reference pins VREF+ and VREF- (pins P5.6 and P5.7).ADC_VREFPOS_EXTBUF_VREFNEG_EXTNEG
: Same asADC_VREFPOS_EXTPOS_VREFNEG_EXTNEG
except VREF+ is internally buffered.
uint32_t channelSelect
: Select the input channel to perform conversion on. Valid values areADC_INPUT_A0
throughADC_INPUT_A31
. If operated in differential the second channel will be selected as discussed for the next argument.bool differentialMode
:true
: Perform an ADC conversion to measure the difference between two input signals (differential mode). If in differential mode: two input channels will be used: A0+A1, A2+A3, A4+A5, etc.false
: Perform conversion of single channel (single-ended mode)
bool ADC14_configureSingleSampleMode( uint32_t memoryDestination , bool repeatMode )
: Configure the ADC14 to convert on only a single channel, either in a repeated fashion or once by request. The arguments are:uint32_t memoryDestination
: Select the ADC14 memory location to save the conversion result of the single channel. Valid values areADC_MEM0
throughADC_MEM31
.bool repeatMode
: Set the single channel to be continuously converted (true
) or converted only once per conversion trigger (false
).
bool ADC14_configureMultiSequenceMode( uint32_t memoryStart , uint32_t memoryEnd , bool repeatMode )
: Configure the ADC14 to convert a sequence of channels (sequentially in memory), either in a repeated fashion or once by request. The arguments are:uint32_t memoryStart
: Select the first ADC14 memory location to convert in sequence. Valid values areADC_MEM0
throughADC_MEM31
.uint32_t memoryEnd
: Select the last ADC14 memory location to convert in sequence. Valid values areADC_MEM0
throughADC_MEM31
.bool repeatMode
: Set the channel sequence to be continuously converted (true
) or converted only once per conversion trigger (false
).
void ADC14_setResolution( uint32_t resolution )
: Sets the number of bits in the ADC conversion. The default resolution is 14 bits; therefore, this function is not required in initial configuration if 14 bits is desired. The argumentuint32_t resolution
should beADC_xBIT
wherex
is8
,10
,12
, or14
.bool ADC14_setSampleHoldTrigger( uint32_t source , bool invertSignal )
: Select the ADC conversion trigger, or the event that will trigger an ADC conversion to start. The arguments are:uint32_t source
: Specifies the trigger source. Valid values are:ADC_TRIGGER_ADCSC
: Software trigger using the functionbool ADC14_toggleConversionTrigger()
.ADC_TRIGGER_SOURCE1
: Timer_A0 CCR1 EventADC_TRIGGER_SOURCE2
: Timer_A0 CCR2 EventADC_TRIGGER_SOURCE3
: Timer_A1 CCR1 EventADC_TRIGGER_SOURCE4
: Timer_A1 CCR2 EventADC_TRIGGER_SOURCE5
: Timer_A2 CCR1 EventADC_TRIGGER_SOURCE6
: Timer_A2 CCR2 EventADC_TRIGGER_SOURCE7
: Timer_A3 CCR1 Event
bool invertSignal
: By default (false
) the ADC trigger samples on a rising edge of the above signals. The may be changed to falling edge by specifying this value astrue
.
bool ADC14_enableSampleTimer( uint32_t multiSampleConvert )
: Select the sampling mode of the ADC14 and start it. Options foruint32_t multiSampleConvert
are:ADC_MANUAL_ITERATION
: Program must directly request a sample conversion,ADC_AUTOMATIC_ITERATION
: The ADC14 will automatically start the next conversion after the previous conversion completes.`
Important
The ADC clock as configured by bool ADC14_initModule()
must be between between 0.128 MHz and 25 MHz to produce accurate conversions. The final value for the clock may be calculated as: clockSource / (clockPredivider * clockDivider)
.
Ref_A Reference Voltage Generator¶
The reference voltage for the ADC14 module may be sources from an internal generator: Ref_A. While there are many DriverLib functions pertaining to this module, only three are useful in this course:
void REF_A_setReferenceVoltage( uint8_t referenceVoltageSelect )
: Configure the generated reference voltage level. Options are:1.2 V:
REF_A_VREF1_2V
1.45 V:
REF_A_VREF1_45V
2.5 V:
REF_A_VREF2_5V
void enableReferenceVoltage( void )
: Start the generation of the reference voltagevoid disableReferenceVoltage( void )
: Stop the generation of the reference voltage
Sampling Control¶
bool ADC14_enableConversion( void )
/bool ADC14_disableConversion( void )
: enable or disable (block) conversions from occurring. Conversions must be disabled to perform ADC14 reconfiguration. Conversions only need to be enabled once; they do not need to be continuously enabled.bool ADC14_toggleConversionTrigger( void )
: Software request for an ADC14 conversion.bool ADC14_isBusy( void )
: Check if the ADC14 is currently performing a conversion. This function will returntrue
if busy,false
if complete/free.uint16_t ADC14_getResult( uint32_t memorySelect )
: Fetch a completed ADC conversion from the ADC14 conversion memoryuint32_t memorySelect
. Valid values areADC_MEM0
throughADC_MEM31
.void ADC14_getMultiSequenceResult( uint16_t * results )
: Fill an input arrayresults
with the conversion results of the configured multi-sequence conversion. The length of arrayresults
must be equal to or greater than the length of the multi-sequence configuration.
Interrupts¶
The ADC1 has a possible 38 total events which may trigger the single ADC1 interrupt. These events are all identified through the uint64_t mask
argument. This argument is a bitwise OR of all active triggers. 32 of the trigger events are ADC_INT0
through ADC_INT31
; which are the interrupt trigger corresponding to the completion of a conversion for the ADC memories ADC_MEM0
through ADC_MEM31
, respectively. The remaining 8 event triggers are not used in this course.
void ADC14_enableInterrupt( uint64_t mask )
/void ADC14_disableInterrupt( uint64_t mask )
: Enable or disable the ADC14 interrupt and associated trigger(s).uint64_t ADC14_getEnabledInterruptStatus( void )
: Return the active interrupt triggers. The return format follows the same format for the value ofuint64_t mask
.void ADC14_clearInterruptFlag ( uint64_t mask )
: Acknowledge/clear the interrupt triggers specified byuint64_t mask
.