STM32-Peripheral’s-ADC: Continuous Mode

STM32-Peripheral’s-ADC: Continuous Mode

An analog to digital converter is a circuit that converts a continuous voltage value (analog) to a binary value (digital) that can be understood by a digital device which could then be used for digital computation. These ADC circuits can be found as an individual ADC ICs by themselves or embedded into a microcontroller. They’re called ADCs for short.

ADC Peripheral features: (STM32F429XX)

1. 12-bit, 10-bit, 8-bit or 6-bit configurable resolution.
2. Interrupt generation at the end of conversion, end of injected conversion, and in case of analog watchdog or
overrun events
3. Single and continuous conversion modes.
4. Scan mode for automatic conversion of channel 0 to channel x.
5. Data alignment with in-built data coherency.
6. Channel-wise programmable sampling time.
7. External trigger option with configurable polarity for both regular and injected conversion.
8. Dual/Triple mode (on devices with 2 ADCs or more).
9. Configurable DMA data storage in Dual/Triple ADC mode.
10. Configurable delay between conversions in Dual/Triple interleaved mode.
11. ADC conversion type (refer to the datasheets).
12. ADC supply requirements: 2.4 V to 3.6 V at full speed and down to 1.8 V at slower speed.
13. ADC input range: VREF(minus) = VIN = VREF(plus).
14. DMA request generation during regular channel conversion.

How to use this driver

Initialize the ADC low level resources by implementing the HAL_ADC_MspInit():
a. Enable the ADC interface clock using __HAL_RCC_ADC_CLK_ENABLE()
b. ADC pins configuration
◦ Enable the clock for the ADC GPIOs using the following function:
◦ Configure these ADC pins in analog mode using HAL_GPIO_Init()
c. In case of using interrupts (e.g. HAL_ADC_Start_IT())
◦ Configure the ADC interrupt priority using HAL_NVIC_SetPriority()
◦ Enable the ADC IRQ handler using HAL_NVIC_EnableIRQ()
◦ In ADC IRQ handler, call HAL_ADC_IRQHandler()
d. In case of using DMA to control data transfer (e.g. HAL_ADC_Start_DMA())
◦ Enable the DMAx interface clock using __HAL_RCC_DMAx_CLK_ENABLE()
◦ Configure and enable two DMA streams stream for managing data transfer from peripheral to
memory (output stream)
◦ Associate the initialized DMA handle to the CRYP DMA handle using __HAL_LINKDMA()
◦ Configure the priority and enable the NVIC for the transfer complete interrupt on the two DMA
Streams. The output stream should have higher priority than the input stream.

Execution of ADC conversions

1. ADC driver can be used among three modes: polling, interruption, transfer by DMA.
Polling mode IO operation
• Start the ADC peripheral using HAL_ADC_Start()
• To read the ADC converted values, use the HAL_ADC_GetValue() function.

For this blog we are going to use ADC in Continuous mode (Single Channel)

Creating STM32 executable projects steps are available on this link , please follow steps 1 to 10 as per blog, here we will start from step 11. PA9 & PA10 Pin used for debugging purpose as UART Tx & UART Rx respectively.

11. Enable ADC Functionality

Go to System mode > Analog > ADC > Enable IN0 >

Parameter Settings > Continuous Conversion mode > Enable

Figure 2: ADC Functionality

12.Enable DAC Functionality (only for debug purpose)

STM32CubeIDE - DAC  Functionality
Figure 3: DAC Functionality

13. Press below icon for code generation

STM32CubeIDE - Code generation
Figure 4: Code generation

14.For code demonstration we will connect DAC Output to ADC Input , already we have configured UART1 for debugging purpose. Output of DAC is set at 2048 which will be input of ADC pin.

15. Sample Code

	uint32_t dac_data = 2048U;
	uint32_t adcvalue;

	HAL_Delay(1000);	//2000 ms delay

	HAL_DAC_SetValue(&hdac, DAC_CHANNEL_1, DAC_ALIGN_12B_R, dac_data);

	uart1_printf_debug("DAC Value = %d  === ",dac_data);
	adcvalue = HAL_ADC_GetValue(&hadc3);
	uart1_printf_debug("ADC Value = %d\n",adcvalue);

	if (dac_data > 2100)
		dac_data = 2048;

16. Debug output (ADC in Continuous mode (Single Channel), debug output over UART Pins)

Debug Output
Figure 4: Debug Output
Software Tools:
  1. STM32CubeIDE
  2. STM32CubeMx
  3. Teraterm
Hardware Setup:
  1. STM32F429IDISCOVERY board
  2. Mini USB Cable
  3. Jumper wire

Successfully demonstrated ADC functionality in continuous mode (Single Channel), for testing purpose we have used DAC & UART for debug.

  1. STM32 HAL Library
  2. STM32 UM1718 document
Similar topics:

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: