Welcome to MSPM0 Smart Robot Car repository
4.OLED display photosensitive value
OLED Display Photosensitive Value
OLED Display Photosensitive Value1. Software and Hardware2. Basic Principles2.1 Hardware Schematic2.2 Control Principle1. Resolution2. Sampling Rate3. Voltage Reference4. Sampling Range3. Project Configuration3.1 Description3.2 Pin Configuration4. Main Functions5. Experimental Phenomenon
1. Software and Hardware
KEIL
MSPM0G3507 Development Board
Type-C data cable or DAP-Link
For programming download or simulation to the development board
2. Basic Principles
2.1 Hardware Schematic
.png)
Physical Connection
.png)
2.2 Control Principle
ADC (analog to digital converter) is a device 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 through sampling and quantization so that processors or microcontrollers can perform subsequent processing. According to their conversion principles, they are mainly divided into three types: successive approximation type, dual-slope integration type, and voltage-frequency conversion type.
MSPM0G3507 uses a successive approximation (SAR) ADC, which is a common ADC working principle. Its basic idea is to gradually approach the digital representation of the input signal by comparing the magnitude relationship between the analog signal and the reference voltage. In successive approximation ADCs, the input signal and reference voltage are compared through a differential amplifier to produce a differential voltage. Then, this differential voltage is input to a successive approximation digital quantizer, which gradually compares it with a series of reference voltages. At each approximation stage, the quantizer compares the input signal with 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 approaches a digital output value.
A/D conversion of various channels can be configured in single, sequence conversion modes.
Single Conversion Mode: After each ADC conversion, the ADC automatically stops and stores the result in the ADC data register.
Repeated Single Conversion Mode: When the ADC completes one conversion, it automatically starts another conversion, continuously performing conversions until stopped by external trigger or software trigger.
Multi-channel Sequential Single Conversion Mode: Used to sequentially convert multiple input channels. In this mode, the ADC performs single sampling and conversion on multiple channels according to the configured channel acquisition sequence.
Multi-channel Sequential Repeated Conversion Mode: Used to sequentially and repeatedly convert multiple input channels. In this mode, the ADC repeatedly samples and converts multiple channels according to the configured channel acquisition sequence.
This case uses ADC to collect the voltage of the photosensitive resistor pin and then calculates the resistance value of the photosensitive resistor.
ADC Basic Parameters
1. Resolution
- Resolution represents the precision of the ADC converter output, usually measured in bits (bit), such as 8-bit, 10-bit, 12-bit, etc. The higher the resolution, the more discrete digital values the ADC can represent, thus providing higher precision.
2. Sampling Rate
- Sampling rate (also called conversion rate) represents the rate at which the ADC samples analog input signals, usually expressed in samples per second (SPS). It indicates how many analog-to-digital conversions the ADC can perform per second.
- MSPM0G3507 has a sampling rate of 4Msps (4 million samples per second), suitable for high-frequency signal acquisition and real-time data processing.
3. Voltage Reference
The voltage reference of an ADC is a reference voltage used to compare with analog input signals to ultimately achieve analog-to-digital signal conversion. The accuracy and stability of the voltage reference are crucial to the conversion accuracy of the ADC.
MSPM0G3507
Supports three voltage reference configurations:
- Internal configurable reference voltage: dedicated ADC reference voltages (VREF) of 1.4V and 2.5V.
- MCU power supply voltage (VDD) as reference voltage.
- External reference voltage provided through VREF+ and VREF- pins. If no voltage reference is configured, the MCU's power supply voltage (VDD) is used as the reference voltage by default.
4. Sampling Range
Sampling range represents the voltage range of analog input signals that the ADC can collect, usually closely related to the reference voltage settings. The range is as follows: VREF- ≤ ADC ≤ VREF+
- VREF-: Set negative terminal of reference voltage, usually 0V.
- VREF+: Set positive terminal of reference voltage, determined according to software configuration.
These parameters together determine the performance of the ADC, including its precision, response speed, and input voltage range.
MSPM0G3507 uses a 12-bit successive approximation ADC with 17 multiplexed channels that can be converted. 17 external channels all correspond to certain pins of the microcontroller. These pins are not fixed. For details, please refer to the pin diagram or data sheet.
3. Project Configuration
3.1 Description
You can refer to the basic tutorial to complete the development environment setup.
3.2 Pin Configuration
Add ADC peripheral configuration using sconfig tool as follows

We select sequence conversion for conversion mode, configure sampling mode as automatic sampling, configure trigger sampling method as software trigger, conversion data format as unsigned binary, and data right-aligned

Here we select all memory control blocks

Pin configuration is as follows

Add serial port configuration to print calculated values

4. Main Functions
Function: Get_ADC_Value
| Function Prototype | void Get_ADC_Value() |
|---|---|
| Function Description | Get ADC sampling value and process sensor data |
| Input Parameters | None |
| Output Parameters | None |
5. Experimental Phenomenon
Connect the car wires, connect the OLED module, after burning the program to MSPM0, connect the Type-C to the car, open the serial port assistant. The configuration and experimental phenomenon are as follows: cover the left and right photosensitive resistors of the car, and the resistance values of the photosensitive resistors displayed on the OLED and serial port will change.
VL: Voltage value of photosensitive resistor (left) converted through ADC
RL: Voltage value of photosensitive resistor (right) converted through ADC
RL: Resistance value of photosensitive resistor (left)
RR: Resistance value of photosensitive resistor (right)