ADC acquisition

ADC acquisition1. Learning objectivesADC principleADC Basic Parameters2. Hardware Construction3. Experimental steps1. Open the SYSCONFIG configuration tool2. ADC parameter configuration3. ADC acquisition channel configuration4. Write the program5. Compile4. Program Analysis5. Experimental phenomenon

1. Learning objectives

  1. Understand the basic knowledge of ADC.
  2. Learn the basic use of ADC and display the collected values ​​on the serial assistant.

ADC principle

ADC (analog to digital converter) is an analog-to-digital converter used to convert analog signals (such as voltage) into digital signals. Analog signals change continuously, while digital signals are discrete binary numbers. ADC converts analog signals into digital data by sampling and quantizing them so that the processor or microcontroller can perform subsequent processing. According to its conversion principle, it is mainly divided into three types: successive approximation type, dual integration type, and voltage-frequency conversion type.

MSPM0G3507 uses a successive approximation (SAR) ADC, which is a common ADC working principle. The basic idea is to gradually approximate the digital representation of the input signal by comparing the magnitude relationship between the analog signal and the reference voltage. In a successive approximation ADC, the input signal and the reference voltage are compared through a differential amplifier to generate a differential voltage. This differential voltage is then input into a progressively approximated digital quantizer, which progressively compares it to a series of reference voltages. At each approximation stage, the quantizer compares the input signal to an intermediate voltage point and selects a higher or lower reference voltage as the reference for the next approximation stage based on the comparison result. This process continues until the quantizer finally approximates a digital output value.

ADC Basic Parameters

  1. Resolution:
  1. Sampling Rate:
  1. Voltage reference:

supports three voltage reference configurations:

  1. Sampling range:

These parameters together determine the performance of the ADC, including its accuracy, response speed and input voltage range.

2. Hardware Construction

MSPM0G3507 uses a successive approximation 12-bit ADC, which has 17 multiplexed channels for conversion. The 17 external channels all correspond to a pin of the microcontroller. This pin is not fixed. For details, please refer to the pin diagram or data sheet.

The A/D conversion of various channels can be configured into single, sequence conversion mode.

Single conversion mode: After each ADC conversion, the ADC will automatically stop and store the result in the ADC data register.

Repeated single conversion mode: When the ADC completes a conversion, it will automatically start another conversion and continue to convert until the continuous conversion is stopped by an external trigger or software trigger.

Multi-channel sequential single conversion mode: Used to convert multiple input channels in sequence. In this mode, the ADC will sample and convert multiple channels once according to the configured channel acquisition sequence.

Multi-channel sequential repeated conversion mode: Used to repeatedly convert multiple input channels in sequence. In this mode, the ADC will repeatedly sample and convert multiple channels according to the configured channel acquisition sequence.

In this case, the voltage of the PA27 pin is collected by the ADC. The potentiometer module and DuPont line used in the ADC acquisition experiment need to be purchased separately, and other input voltage methods can also be used.

image-20241121171911235

3. Experimental steps

This case will use the voltage of the PA27 pin as an experimental case. The voltage change is collected through ADC to print the voltage status on the serial port.

1. Open the SYSCONFIG configuration tool

Open the blank project empty in SDK in KEIL.

image-20241118204605335

Select and open, open the empty.syscfg file in the keil interface, with the empty.syscfg file open, then select to open the SYSCONFIG GUI interface in the Tools bar.

image-20241118204833195

In SYSCONFIG, select MCU peripherals on the left, find the ADC12 option and click to enter. Click ADD in ADC12 to add the ADC peripheral.

image-20241121161425066

2. ADC parameter configuration

The configuration of the serial port part refers to the Serial Port Communication course, which will not be described here.

The configuration selected here is to use 32Mhz ADC frequency, 4MHz sampling frequency, single repetitive conversion mode, trigger ADC to start sampling through software, and the data format is binary right-aligned.

image-20241121174628010

Parameter Description:

ADC Clock Source: ADC clock source. Set to SYSOSC(32MHz).

ADC Clock Frequency: Displays the current ADC clock frequency.

Sample Clock Divider: Sampling divider. Configured as 8 dividers.

Calculated Sample clock Freguency: Displays the sampling frequency after frequency division.

Conversion Mode: Conversion mode. Configured as Single, single shot.

Conversion Starting Address: Conversion starting address. Configure to start sampling from the 0th (related to the storage register behind).

Enable Repeat Mode: Whether to enable repeated conversion. Check here to enable.

Sampling Mode: Sampling mode. Set to Auto, automatic.

Trigger Source: ADC trigger mode. Configured as Software software trigger mode.

Conversion Data Format: ADC data conversion format. Configured as Binary unsigned, right aligned binary format right alignment mode.

The ADC of MSPM0G3507 supports multiple data alignment methods to adapt to different application scenarios. Common data alignment methods include left alignment and right alignment.

img

img

We configure it to right-aligned so that we can directly operate on the converted data.

3. ADC acquisition channel configuration

image-20241121180348131

image-20241121181208674

Parameter description:

Active Memory Control Blocks: ADC data storage address. Store ADC conversion results in register 0.

Input Channel: Input channel. Select channel 0 (each channel corresponds to a different pin).

Device Pin Name: Pin automatically selected according to the channel, the pin of channel 0 is PA27.

Reference Voltage: Voltage reference. Configured to use MCU power supply VDDA.

ADC Conversion Period: Displays the time it takes for the ADC to convert a single data.

image-20241121181906900

Parameter Description:

Conversion Resolution: The resolution is configured to 12-bits.

Desired Sample Time 0: The sampling time is set to 10ms.

Enable interrupts: Enable the interrupt for ADC acquisition completion. When the ADC acquisition is completed, the interrupt is triggered and we process the data.

image-20241128143228604

Click SAVE to save the configuration in SYSCONFIG, then turn off SYSCONFIG and return to keil.

image-20241119193346732

Select Yes to All in the pop-up window

image-20241119143728060

Similarly, we also need to confirm whether the ti_msp_dl_config.c and ti_msp_dl_config.h files are updated. Compile directly, and the compilation will automatically update to keil. If there is no update, we can also copy the file content in SYSCONFIG.

4. Write the program

In the empty.c file, write the following code

5. Compile

Click the Rebuild icon. The following prompt appears, indicating that the compilation is complete and there are no errors.

image-20241119150803274

image-20241119150902489

4. Program Analysis

Call the DL_ADC12_startConversion function to start ADC conversion. If the current ADC is still converting, the program enters low power mode through __WFE() until the interrupt sets the gCheckADC flag, indicating that the conversion is complete. After the conversion is completed, call DL_ADC12_getMemResult to get the conversion result and return

SysTick_Handler: tick timer interrupt service function, used to implement delay. Each time an interrupt occurs, delay_times is reduced by 1 until it reaches 0 to stop the delay.

ADC_VOLTAGE_INST_IRQHandler: ADC interrupt service function. When the ADC conversion is completed, check the ADC interrupt and set the flag gCheckADC to inform the main program that data can be read.

After initializing the system configuration, enable the interrupts of the serial port and ADC. In the main loop, call adc_getValue() to get the ADC data, convert it into a voltage value and print it.

5. Experimental phenomenon

After the program is downloaded, configure the serial port assistant as shown below, adjust the potentiometer knob, and you can see the effect of the real-time change of voltage between 0-3.3v in the serial port assistant receiving window.

image-20241121184248673