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. Serial port parameter configuration5. Write the program6. 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

Create a blank project empty in CCS.

image-20241126182939655

image-20241126183128934

Find and open the empty.syscfg file in the left workspace of CCS.

image-20241127152938881

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

image-20241128121242406

2. ADC parameter configuration

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

image-20241128121448616

Parameter Description:

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

ADC Clock Frequency: Displays the current ADC clock frequency.

Sample Clock Divider: Sample 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 as right-aligned so that we can directly calculate the converted data.

3. ADC acquisition channel configuration

image-20241128121816509

Parameter Description:

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

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

Device Pin Name: The 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

4. Serial port parameter configuration

This case uses the serial port output method to output the values ​​collected by the ADC to the host computer (computer) through the serial port, so the serial port sending function also needs to be configured. The undisplayed part is the default option.

image-20241128123039616

image-20241128123052300

Use the shortcut key Ctrl+S to save the configuration in the .syscfg file.

5. Write the program

In the empty.c file, write the following code

6. Compile

image-20241127155238783

If the compilation is successful, you can download the program to the development board.

4. Program Analysis

image-20241128140214440

The uart0_send_string function sends a string through the UART serial port. The while (*str != 0) loop iterates through each character until the end of the string (*str == 0). Before sending each character, DL_UART_isBusy(UART_0_INST) checks whether the UART is busy. Data can only be sent when the UART is idle. The current character is sent through DL_UART_Main_transmitData(UART_0_INST, *str++), and str points to the next character.

image-20241128141038067

This code reads ADC (analog-to-digital converter) data. By triggering ADC conversion and waiting for the conversion to complete, finally get the ADC sampling result and return.

image-20241128141224060

ADC's interrupt service function ADC_VOLTAGE_INST_IRQHandler is used to handle interrupt events and set the flag bit after ADC data acquisition is completed.

image-20241128142019647

This code implements reading ADC (Analog to Digital Converter) data, calculating voltage value, and outputting the result through UART serial port. Initialize system configuration and ADC interrupt. Enter the main loop, continuously read ADC data and calculate voltage. Send ADC value and calculated voltage to the terminal through UART serial port.

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 real-time voltage change between 0-3.3v in the serial port assistant receiving window.

image-20241121184248673