yahboom
HomeLearn
Solution
Blog
Online Store
About Us
EN/中文
MSPM0 Smart Robot Car📖
1.Quick Start Guide
  • 1. Assembly Videos
  • 2. Quick Start Videos
  • 3. Battery charging
  • 4. Notes
2.Introduction to the MSPM0 Car
  • 1.About MSPM0
  • 2.Development board interface description
3.Development environment setup and usage
  • 1.CCS Theia development
  • 2.MDK Arm development
  • 3.Uniflash burning
  • 4.External crystal oscillator configuration
  • 5.Project Migration
4.MSPM0 basic course
  • 1. LED light control (GPIO)
  • 2. Buzzer Control (GPIO)
  • 3. Button Control (EXTI)
  • 4. Serial Port (UART)
  • 5. Voltage Detection (ADC)
  • 6. Temperature Detection (ADC)
  • 7. Independent Watchdog (WWDG)
  • 8. Window Watchdog (WWDG)
  • 9. Timer (TIM)
  • 10. Breathing LED (PWM)
  • 11. I2C Communication (I2C)
  • 12. External Flash (SPI)
  • 13. Internal Flash (Flash)
  • 14. DMA
  • 15. FreeRTOS
5.Sensor basic course
  • 1.Servo control
  • 2.Ultrasonic servo PTZ basic use
  • 3.Motor PID control
  • 4.OLED display photosensitive value
  • 5.Infrared avoid sensor
  • 6.1 Infrared line tracking sensor-8 channel infrared tracking sensor module
  • 6.2 Infrared line tracking sensor-4 channel infrared tracking sensor module
  • 7.Infrared remote control
  • 8.Ultrasonic ranging
  • 9.RGB light drive
  • 10.MPU6050 raw data acquisition
  • 11.MPU6050 data fusion
  • 12.K210 vision recognition module
  • 13.K230 vision recognition module
6.Smart car course
  • 1.1 Car line tracking-8 channel infrared tracking sensor module
  • 1.2 Car line tracking-4 channel infrared tracking sensor module
  • 2.1 Drawing a circle-8 channel infrared tracking sensor module
  • 2.2 Drawing a circle-4 channel infrared tracking sensor module
  • 3.Ultrasonic following
  • 4.Ultrasonic avoid
  • 5.Ultrasonic avoid(Servo PTZ)
  • 6.Infrared sensor avoid
  • 7.Light following
  • 8.Gyroscope calibration straight-line walk
  • 9.Infrared remote control
  • 10.Autonomous driving car
7.Vision application course
  • 1.K210 autonomous driving
  • 2.K210 color tracking
  • 3.K210 handwritten digit action
  • 4.K210 color response
  • 5.K210 road sign indication action
  • 6.K210 following machine code
  • 7.K210 QR code command
  • 8.K230 vision line tracking
  • 9.K230 color tracking
  • 10.K230 machine code tracking
  • 11.K230 QR code command
  • 12.K230 autonomous avoid
  • 13.K230 license plate tracking
  • 14.K230 face tracking
  • 15.K230 gaze direction tracking
  • 16.K230 palm tracking
  • 17.K230 target tracking
  • 18.K230 human body tracking
  • 19.K230 OCR character recognition
8.Extended application course (Sold separately)
  • 1.Voice interaction module communication
  • 2.Voice interaction control
  • 3.K230 road sign indication action(Voice)
  • 4.K230 color response(Voice)
  • 5.K230 gesture control(Voice)
  • 6.K230 rock-paper-scissors(Voice)
  • 7.8-channel grayscale color line tracking
  • 8.Bluetooth remote control
  • 9.K210 Scenario-based autonomous driving
  • 10.K230 Scenario-based autonomous driving
Download
  • Code
  • SCH
  • 3D Model File
  • MSPM0 Data Sheet
  • Voice firmware
  • Hardware interface manual
Download ZIP

Welcome to MSPM0 Smart Robot Car repository

6. Temperature Detection (ADC)

Temperature Detection

Temperature DetectionI. Learning ObjectivesII. Hardware SetupIII. Experiment StepsIV. Program AnalysisV. Experiment Phenomenon

I. Learning Objectives

  1. Understand basic ADC knowledge.
  2. Learn basic ADC usage, printing collected internal temperature values through serial port.

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 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 approximate 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 approximates to a digital output value.

ADC Basic Parameters

  1. Resolution:

    • Resolution represents the precision of the ADC converter output, usually measured in bits, such as 8-bit, 10-bit, 12-bit, etc. The higher the resolution, the more discrete digital values the ADC can represent, thereby providing higher precision.
  2. Sampling Rate:

    • Sampling rate (also called conversion rate) represents the rate at which the ADC samples the analog input signal, 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 ADC voltage reference is a reference voltage used to compare with the analog input signal to ultimately achieve analog-to-digital signal conversion. The accuracy and stability of the voltage reference are crucial to the ADC conversion precision.

    • MSPM0G3507

      supports three voltage reference configurations:

      • Internal configurable reference voltage: 1.4V and 2.5V dedicated ADC reference voltage (VREF).
      • 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 setting. The range is as follows: VREF- ≤ ADC ≤ VREF+

      • VREF-: Set reference voltage negative terminal, usually 0V.
      • VREF+: Set reference voltage positive terminal, determined according to software configuration.

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

II. Hardware Setup

The data sheet feature description states that MSPM0 has an integrated temperature sensor that can roughly feedback chip temperature

image-20251014121659537

The temperature sensor is internally connected to ADC channel 11 and channel 12. Here we take ADC0 peripheral conversion channel 11 as an example

image-20251103164839727

The following is the data sheet description of the temperature sensor

A unit-specific single-point trim value (TEMP_SENSE0.DATA) is provided in each device's factory constant memory. This value represents the output voltage of the temperature sensor at the factory temperature (TSTRIM), expressed in ADC result code format. The ADC result code in TEMP_SENSE0. Data is based on 12-bit sampling mode, and the temperature sensor outputs a voltage linearly related to temperature. The temperature coefficient (TSc) is the slope of the temperature-voltage relationship (in mV/C), given in the specifications section of the device-specific data sheet (as shown in the table below)

image-20251014150503232

image-20251014151534265

III. Experiment Steps

Import Project

In KEIL, open our serial communication project from the previous section, or you can use the project template from the 80MHz clock frequency configuration chapter or the empty project from the SDK.

After selecting and opening, in the KEIL interface, open the empty.syscfg file. With the empty.syscfg file open, select Open SYSCONFIG GUI interface from the Tools menu.

Add ADC Peripheral Configuration

The source code for this tutorial is based on the source code from tutorial 4 Serial Communication.

In SYSCONFIG, select MCU peripherals on the left, find ADC12 option and click to enter. In ADC12, click ADD to add ADC peripheral. Here we name it Temperature

image-20251014122146824

The configuration selected here is to use 32MHz ADC frequency, sampling frequency of 4MHz, single repeat conversion mode, ADC sampling is triggered by software, data format is binary right-aligned. We set the sampling time to 10ms

Enable channel 0 result load interrupt

image-20251013162734536

Configure as ADC0 as conversion peripheral

image-20251014122357681

Parameter description:

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

ADC Clock Frequency: Shows the current ADC clock frequency.

Sample Clock Divider: Sampling divider. Configured as divide by 8.

Calculated Sample clock Frequency: Shows the sampling frequency after division.

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

Conversion Starting Address: Conversion start address. Configured to start sampling from the 0th (related to the storage register below).

Enable Repeat Mode: Whether to enable repeat conversion. Checked here, enabled.

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

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

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

MSPM0G3507's ADC supports multiple data alignment methods to adapt to different application scenarios. Common data alignment methods include left-aligned and right-aligned.

  • Right-aligned mode: In right-aligned mode, the ADC data is right-aligned to the least significant bits after conversion, with insufficient bits filled with 0 in the high bits. Right-aligned mode allows for better dynamic range without precision loss.

img

  • Left-aligned mode: In left-aligned mode, the ADC data is left-aligned to the most significant bits, with insufficient bits filled with 0 in the low bits. Left-aligned mode can improve resolution but results in reduced dynamic range.

img

We configure as right-aligned method, so we can directly perform calculations on the converted data.

ADC conversion channel configuration puts conversion results in memory 0

image-20251014122512286

image-20251014161702936

Parameter description:

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

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

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

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

ADC Conversion Period: Shows the time for ADC to convert a single data

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

image-20241119193346732

Select Yes to All in the pop-up window

image-20241119143728060

IV. Program Analysis

Like the previous section, we create new bsp_vol_adc.c, bsp_vol_adc.h under the BSP file, configured as follows

temperature_adc.h

xxxxxxxxxx
#ifndef __BSP_TEMPRATURE_H__
#define __BSP_TEMPRATURE_H__
​
#include "ti_msp_dl_config.h"
​
​
#define TEMP_TS_TRIM_C                                            ((uint32_t)30)  //
#define TEMP_TS_COEF_mV_C                                             (-1.75f) 
#define ADC_VREF_VOLTAGE                                                  (3.3f)  
#define ADC_BIT_RESOLUTION                                   ((uint32_t)(1)<<12)
​
​
extern volatile bool gCheckADC;
extern volatile float gTemperatureDegC;
extern volatile float gTemperatureDegF;
​
​
#endif
​

temperature_adc.c

xxxxxxxxxx
#include "temperature_adc.h"
​
volatile bool gCheckADC;
volatile float gTemperatureDegC;
volatile float gTemperatureDegF;
​
/**
 * @brief Temperature ADC interrupt service routine
 * @brief 温度ADC中断服务函数
 */
void Temperature_INST_IRQHandler(void)
{
    //Check and process ADC interrupt sources
    //检查并处理ADC中断源
    switch (DL_ADC12_getPendingInterrupt(Temperature_INST)) {
     
        //ADC MEM0 result loaded interrupt
        //ADC MEM0结果加载中断
        case DL_ADC12_IIDX_MEM0_RESULT_LOADED:
            //Set ADC completion flag
            //设置ADC完成标志位
            gCheckADC = true;
            break;
        
        //Other interrupt cases
        //其他中断情况
        default:
            break;
    }
}

empty.c

xxxxxxxxxx
#include "ti_msp_dl_config.h"
#include "temperature_adc.h"
#include "uart0.h"
#include <math.h>
​
int main(void)
{
    //ADC sampling result / ADC采样结果
    uint32_t adcResult;
    
    //tempDegC: Celsius temperature / 摄氏温度
    //tempDegF: Fahrenheit temperature / 华氏温度  
    //vSample: Current voltage / 当前电压
​
    //vTrim: Output voltage of temperature sensor at factory calibration temperature TEMP_TS_TRIM_C
    float vSample, vTrim, tempDegC, tempDegF;
​
    //System configuration initialization
    SYSCFG_DL_init();
    
    //Get factory calibration value and convert to voltage
    //DL_SYSCTL_getTempCalibrationConstant reads ADC value from TEMP_SENSE0.DATA
    vTrim = (DL_SYSCTL_getTempCalibrationConstant() - 0.5f) * ADC_VREF_VOLTAGE / ADC_BIT_RESOLUTION;  
    //Enable temperature ADC interrupt
    NVIC_EnableIRQ(Temperature_INST_INT_IRQN);
​
    gCheckADC = false;
    while (1) {
        //Start ADC conversion
        DL_ADC12_startConversion(Temperature_INST);
​
        //Wait for conversion to complete
        while (false == gCheckADC) {
            __WFE(); 
        }
        gCheckADC = false;
​
        //Stop ADC conversion
        DL_ADC12_stopConversion(Temperature_INST);
        
        //Collect ADC value of current temperature
        adcResult = DL_ADC12_getMemResult(Temperature_INST, Temperature_ADCMEM_ADC_CH0);
​
        //Convert ADC result to voltage value
        vSample = (adcResult - 0.5f) * ADC_VREF_VOLTAGE / ADC_BIT_RESOLUTION;
​
        //Calculate temperature (Celsius)
        //Formula: Temp = (V_sample - V_trim) * Coeff + Trim_Temp
        tempDegC = (vSample - vTrim) * TEMP_TS_COEF_mV_C * 1000.0f + TEMP_TS_TRIM_C; 
        
        //Note: Coefficient TEMP_TS_COEF_mV_C comes from data sheet
        
        //Multiply by 1000 above converts millivolts to volts, because vSample and vTrim units are volts (V)
        //Calculate Fahrenheit temperature
        tempDegF = tempDegC * 9.0f / 5.0f + 32.0f;
        //Update global temperature variables
        gTemperatureDegC = tempDegC;
        gTemperatureDegF = tempDegF;
        
        //Print temperature value (retain 1 decimal place)
        printf("%3.1f℃ \r\n", gTemperatureDegC);
    }
}
​

V. Experiment Phenomenon

We connect Type-C to the computer and the car, then open the serial debugging assistant, baud rate 9600, eight data bits, one stop bit, no parity.

Note that when using Type-C as debugging serial port output, it is not recommended to connect other sensors to serial port 0!

image-20251014161831980

 

 

Voltage Detection (ADC)
Independent Watchdog (WWDG)

COMPANY

  • About us
  • Team Style
  • Blog

LEARNING & EXPLORATION

  • Tutorials
  • Edge AI hardware
  • Educational robots
  • Embedded intelligent hardware

WHERE TO BUY

  • Yahboom Online Store
  • Amazon
  • Alibaba
  • AliExpress
  • Mercado

TECHNOLOGY SUPPORT

  • Email: support@yahboom.com

BE A DISTRIBUTOR

  • Email: sales@yahboom.com
QR Code

Copyright © 2017-2026 Yahboom. All Rights Reserved.

EN/中文