element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Embedded and Microcontrollers
  • Technologies
  • More
Embedded and Microcontrollers
Blog PID temperature controller for the EasyL1105 MSPM0 board - Pt. 2: ADC
  • Blog
  • Forum
  • Documents
  • Quiz
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Embedded and Microcontrollers to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: Jan Cumps
  • Date Created: 27 Sep 2025 7:46 PM Date Created
  • Views 295 views
  • Likes 7 likes
  • Comments 6 comments
  • MSPM0L1105
  • MSPM0
  • easyL1105
  • pid
Related
Recommended

PID temperature controller for the EasyL1105 MSPM0 board - Pt. 2: ADC

Jan Cumps
Jan Cumps
27 Sep 2025

 shabaz designed a development kit for the recent Texas Instruments MSPM0 microcontroller series. 
This 4 part blog series documents the steps to design a PID temperature controller. Part 2: add ADC to sample the temperature sensor

image
(post that introduces the kit)

Goal of this 2nd post

  • add single ADC conversion logic, based on TI adc12_single_conversion
  • use ADC hardware to return value in same Q16 format used in the PID library

Set up ADC SysConfig

image

The Conversion Data Format, 2s complement, left aligned, happens to be the same Q15 format that our PID library uses.

image

image

image

image

Code adaption from post 1:

I use a flag to check if sampling is done. The Result Loaded trigger will set that flag.

volatile bool gCheckADC;
uint32_t gAdcResult;

// ...

void ADC12_0_INST_IRQHandler(void) {
    switch (DL_ADC12_getPendingInterrupt(ADC12_0_INST)) {
        case DL_ADC12_IIDX_MEM0_RESULT_LOADED:
            gCheckADC = true;
            break;
        default:
            break;
    }
}

In main(), the IRQ gets enabled

int main(void) {
    SYSCFG_DL_init();

    // ...

    NVIC_EnableIRQ(ADC12_0_INST_INT_IRQN);
    gCheckADC = false;
    
    // ...

The perform_adc() placeholder that I wrote in the 1st post, gets implemented now:

void perform_adc() {
    DL_ADC12_startConversion(ADC12_0_INST);

    while (false == gCheckADC) {
        __WFE();
    }

    gAdcResult = (uint32_t)DL_ADC12_getMemResult(ADC12_0_INST, DL_ADC12_MEM_IDX_0);

    gCheckADC = false;
    DL_ADC12_enableConversions(ADC12_0_INST);
}

I could make gAdcResult a return value instead of a global variable. Maybe later ...

Thanks for reading. Next, get PWM working.

ccs project for EasyL1105: pid_EasyL1105_20250927.zip

Related posts

  • Sign in to reply
Parents
  • shabaz
    shabaz 2 days ago

    Hi Jan,

    We think alike, I too tried the single conversion, in exactly the same way, with the minor difference that I averaged like in your 14-bit code earlier, except I went for 16-bit result, because I had written a thermistor potential divider to temperature conversion routine that expected a 16-bit value (in reality, even 12-bit precision is fine).

    The thermistor code assumes a 3.3k resistor to 3.3V, and the 100k thermistor to ground, and it exposes these functions:

    float adc_to_temperature(uint16_t adc_val);

    int32_t adc_to_temperature100(uint16_t adc_val);

    float adc_to_voltage(uint16_t adc_val, float vref);
    The top two of those functions convert a 16-bit ADC value into temperature, either as a float (e.g. 25.0), or as an integer in hundredths of a degree C, such as 2500 for 25.00 deg C). The last of those three functions isn't needed, but will convert the ADC value into the measured voltage.

    I've attached the project so far, based on your earler PID code. I also added in UART (based on another of your blog posts), but only in the TX direction from the MSPM0, to be used for debug output, since I suspect we will definitely need to see that while tuning the PID.

    Since the printf may be heavy, I created uart.c/h with a few simple functions:

    void uart_print_text(const char *s); // prints a null-terminated string

    void uart_print_hex16(uint16_t value); // prints an unsigned 16-bit value as four hex digits

    void uart_print_dec16(uint16_t value); // prints an unsigned 16-bit value as a decimal
    The main() function currently waits for the ADC conversion and prints the hex value, and the decimal temperature, and loops just as a test.
    This is the testbed (literally just the thermistor and 3.3k resistor as mentioned):
    image
    When run, I see output like this (and it's plausible the temperature is about 23 deg C in this warm room):
    F7F9 -> 24 degC
    F7E7 -> 24 degC
    F7E8 -> 24 degC
    F7DE -> 24 degC
    F7E5 -> 24 degC
    F7F2 -> 24 degC
    F7F1 -> 24 degC

    What I don't know is how to feed the temperature conversion into the PID code. The temperature is currently represented either as a float, or as an integer multiplied by 100 as mentioned. The maximum temperature will never exceed a few hundred degrees, so maybe we could just divide by 10, then it will never exceed 15 bits, and then it could be fed into the PID, and therefore set the temperature in multiples of tenths of a degree?

    pid_EasyL1105.zip

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Jan Cumps
    Jan Cumps 2 days ago in reply to shabaz

    If you prefer to use floating point: this example (for another controller, but that doesn't matter) uses a PID lib that I ported from Arduino, using floating point: 

     MSP432 and TI-RTOS: PID Library Part 1 - Intro 

    I haven't looked too deep in what to enter in the PID (raw ADC or a converted value), and how to translate the output in PWM duty cycle. Was planning to do that later, when all peripherals are functioning.

    I've done it before, but forgot most of it after several years of not using this. I did a specialisation year on Feedback and Control Theory in the mid 80's, but that knowledge is just a vague memory now.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • shabaz
    shabaz 2 days ago in reply to Jan Cumps

    Same here, I vaguely remember bits : ) It wasn't as interesting when it was just math and there were more fun subjects at uni.

    I'll try to stick with integer, by passing in the set and feedback values into that PID code directly as degC x 100 values, simply by keeping the int32_t size that the PID code also happens to use. I think it's only the output result, that  uses the Q15.0 format according to the comments.

    Currently the code takes the ADC value, and changes it to a degC x 100 tempeature:

    int32_t t100;
    t100 = adc_to_temperature100(adcResult);
    So, it should be possible to simply replace that with:
    i32_Plant_Signal = adc_to_temperature100(adcResult);
    We will just need to make sure that i32_Target_Command is also in this degC x 100 format.
    Regarding that target command, maybe that can come from a potentiometer connected to a second ADC channel, with (say) adjustability from 50 deg C to 150 deg C (or anything really; can be #defined). 
    I added a second channel, the code is attached. The second channel uses GPIO PA15. Now the UART output shows:
    F816 -> 23 degC, Pot = 6425
    F81F -> 23 degC, Pot = 7100
    F81B -> 23 degC, Pot = 8790
    F81A -> 23 degC, Pot = 6387
    F80A -> 24 degC, Pot = 6011
    F809 -> 24 degC, Pot = 8448
    F819 -> 23 degC, Pot = 8462
    (The pot ADC input is currently floating, I have not wired it, but have confirmed it goes from zero to almost 65535 when I short PA15 to 0V or 3.3V).
    pid_EasyL1105_dual_adc_chan.zip
    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • shabaz
    shabaz 2 days ago in reply to Jan Cumps

    Added UART RX too (using the old RX pin, so you may need to change that).

    In uart.c, using the UART interrupt to detect a received character, I call a function called append_uart_buffer, which will simply collects up characters typed by the user, until they press Enter (max 16 chars). Then, a global var called uartLineReceived is set to 1. That can be checked any time in the main() function for instance. 

    This could be useful for (say) dynamically changing the PID parameters during experimentation. I'll write a little CLI for it, that can be <parameter> <value>, e.g. the user could type "Kp 100" etc.

    pid_EasyL1105_with_uart_rx.zip

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • shabaz
    shabaz 1 day ago in reply to Jan Cumps

    I've added a simple CLI.

    It accepts lines with the syntax:

    <paramname> <value>

    or 

    <paramname>?

    Currently it only supports kp, ki and kd params (all lower-case).

    So, to query what kp is set to, the user can type:

    kp?

    To set it to a new value (e.g. 500):

    kp 500

    The CLI is quite generic, so it can be used for other MSPM0 programs (or any microcontroller).

    The uart.c code is responsible for filling uart_buffer as characters arrive, and setting a global variable uartLineReceived whenever a line of text has been typed.

    Commands are parsed and processed in cli.c / cli.h using a function called process_line.

    In the main() function, the following is used to call process_line:

    if (uartLineReceived) {
        process_line((char *)uart_buffer);
        uartLineReceived = false;
    }

    I still need to connect up a potentiometer, and wire a MOSFET, I'll do that next.

    pid_EasyL1105_with_cli.zip

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
Comment
  • shabaz
    shabaz 1 day ago in reply to Jan Cumps

    I've added a simple CLI.

    It accepts lines with the syntax:

    <paramname> <value>

    or 

    <paramname>?

    Currently it only supports kp, ki and kd params (all lower-case).

    So, to query what kp is set to, the user can type:

    kp?

    To set it to a new value (e.g. 500):

    kp 500

    The CLI is quite generic, so it can be used for other MSPM0 programs (or any microcontroller).

    The uart.c code is responsible for filling uart_buffer as characters arrive, and setting a global variable uartLineReceived whenever a line of text has been typed.

    Commands are parsed and processed in cli.c / cli.h using a function called process_line.

    In the main() function, the following is used to call process_line:

    if (uartLineReceived) {
        process_line((char *)uart_buffer);
        uartLineReceived = false;
    }

    I still need to connect up a potentiometer, and wire a MOSFET, I'll do that next.

    pid_EasyL1105_with_cli.zip

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
Children
No Data
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube