{"id":12041,"date":"2024-01-31T08:45:26","date_gmt":"2024-01-31T06:45:26","guid":{"rendered":"https:\/\/deepbluembedded.com\/?p=12041"},"modified":"2024-02-01T09:40:14","modified_gmt":"2024-02-01T07:40:14","slug":"stm32-adc-injected-channel-conversion-mode-example","status":"publish","type":"post","link":"https:\/\/deepbluembedded.com\/stm32-adc-injected-channel-conversion-mode-example\/","title":{"rendered":"STM32 ADC Injected Channel Conversion Mode With Example"},"content":{"rendered":"\n

In this tutorial, we’ll discuss the STM32 ADC Injected Channel Conversion Mode<\/strong>, what makes it different from regular ADC channels, when to consider using an ADC channel as a regular vs injected, and how to configure the STM32 ADC injected channel to trigger on various events.<\/p>\n\n\n\n

The practical example we’ll implement in this tutorial is an STM32 power LED dimmer (10W\/12v) with shunt resistor current measurement. The driving PWM signal will be configured as center-aligned, and the current measurement ADC channel will be an injected channel with a timer trigger in the middle of the PWM HIGH period. Without further ado, let’s get right into it!<\/p>\n\n\n

Table of Contents<\/h2>\n
    \n
  1. STM32 ADC Injected Channel Conversion Mode<\/a>\n\n\n<\/li>\n\n<\/li>\n\n\n<\/li>\n\n
  2. STM32 ADC Injected Channel Conversion Example Project<\/a>\n\n<\/li>\n
  3. STM32 ADC Injected Channel With PWM Trigger Example<\/a>\n\n\n<\/li>\n\n
  4. Wrap Up<\/a>\n<\/li><\/ol>\n\n\n
    \n\n\n

    STM32 ADC Injected Channel Conversion Mode<\/strong><\/h2>\n\n\n

    The STM32 ADC gives you, the system designer\/programmer, the option to set several analog input channels as “injected channels”. A channel can either be configured as a regular or injected channel at any given time. When configured as an injected ADC channel, it’ll have a higher priority than regular channels and can also suspend any ongoing regular channel conversion when the injected channel\/group is triggered.<\/p>\n\n\n\n

    Below is an example diagram showing you a system where ADC1 is configured to have a regular group (CH0 to CH3) being converted while an injected channel (CH7) is triggered from a hardware source. The ADC suspends the ongoing conversion of the regular channels group, CH1 conversion is omitted, the injected CH7 is immediately sampled and converted, and then the regular group conversion is resumed starting from CH1 which was interrupted at the time of triggered-injection has occurred.<\/p>\n\n\n\n

    \"STM32<\/figure>\n\n\n\n

    <\/p>\n\n\n\n

    The STM32F103xx, for example, can have up to 16 regular channels as well as up to 4 injected channels per ADC module. This number will vary from one target microcontroller to another, so you need to refer to the MCU’s datasheet to know its actual capabilities.<\/p>\n\n\n

    STM32 ADC Injected Vs Regular Channels<\/strong><\/h3>\n\n\n

    Here is a summary of the features that differentiate the injected channels from regular channels. This may be the answer to your question “Should I configure my channel as a regular or injected channel for XYZ application?”. The injected ADC channels will have the following features:<\/p>\n\n\n\n