Advanced Analog-to-Digital Conversion STM32 : External Trigger

by Marwen Maghrebi

Things used in this project

Software apps and online services:

1- STMicroelectronics STM32CubeMX

2- STMicroelectronics STM32CubeIDE

3- Proteus 8

Enhancing STM32 ADC Efficiency: Investigating External Triggers with Proteus Simulation

This project aims to investigate how external triggers enhance STM32 ADC functionality. By exploring how ADC conversions can be synchronized with external events, we seek to understand their impact on analog data acquisition. Through simple experiments, we’ll uncover how external triggers optimize efficiency, flexibility, and real-time processing in STM32 microcontrollers.

Significance of External Triggers in Embedded Systems:

In real-world applications, external triggers play a crucial role in embedded development. They offer synchronized data acquisition with external events, enhancing system efficiency, flexibility in operation, and facilitating real-time response to dynamic input signals. From industrial automation to IoT devices, the utility of external triggers extends across various industries, ensuring precise monitoring, control, and data acquisition.

Project Implementation Steps:

To begin this project, we’ll configure the ADC to read the analog voltage from the potentiometer. Then, we’ll enable regular conversion mode and set the external trigger source to EXTI Line11. Next, we’ll activate UART communication to interface the ADC value and external trigger status. Final ly, we’ll simulate the circuit design using Proteus software.

STM32CubeMX Configuration:

  • Open CubeMX & Create New Project Choose The Target MCU STM32F103C6 & Double-Click Its Name
  • Go To The Clock Configuration & Set The System Clock To 8MHz

Configuration for the GPIO Mode:

  • Configure GPIO Pins PA2 and PA3 as Output Pins, with one indicating the loop status and the other for callback notifications.

Configuration for the ADC Mode:

  • In the Categories tab, select the [ADC1, enable IN7]
  • In the Parameter settings tab, Enabler Regular Conversion Mode
  • In the NVIC settings tab, Enable ADC1 and ADC2 global Interrupts and [EXTI ligne [15:10] interrupts

Configuration for the UART Mode:

  • Enable USART1 Module (Asynchronous Mode)
  • Set the USART1 communication parameters (baud rate = 115200, parity=NON, stop bits =1, and word length =8bits)
  • Generate The Initialization Code & Open The Project In CubeIDE
  • Write The Application Layer Code

STM32CubeIDE Configuration :

In file name :main.c

#include "main.h"

ADC_HandleTypeDef hadc1;
UART_HandleTypeDef huart1;
/* USER CODE BEGIN PV */
uint8_t MSG [50]="wait for ADC External Trigger .. \n\r";
uint8_t MSG2 [50];
uint32_t ADC_VAL=0;
/* USER CODE END PV */

/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
ADC_VAL = HAL_ADC_GetValue(&hadc1);
sprintf(MSG2,"ADC VALUE = %d\n\r",ADC_VAL);
HAL_UART_Transmit_IT(&huart1, MSG2, sizeof(MSG2));
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, 1);
}
/* USER CODE END 0 */

int main(void)
{
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
MX_ADC1_Init();
MX_USART1_UART_Init();

/* USER CODE BEGIN 2 */
if(HAL_ADC_Start_IT(&hadc1)!=HAL_OK)
    {
    Error_Handler();
    }
/* USER CODE END 2 */

while (1)
{
    HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, 0);
    HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_3);
    HAL_UART_Transmit_IT(&huart1, MSG , sizeof(MSG));
    HAL_Delay(1000);
}
}

Proteus Configuration :

  • Open Proteus & Create New Project and click next

  • Click on Pick Device
  • Search for STM32F103C6 & POT & BUTTON & LED-GREEN & LED-REED
  • Click on Virtual Instruments Mode then choose VIRTUAL TERMINAL

  • Click on Terminal Mode then choose (DEFAULT & POWER &GROUND)
  • finally make the circuit below and start the simulation

That’s all!

If you have any questions or suggestions don’t hesitate to leave a comment below

You Might Also Like

Leave a Comment


Are you sure want to unlock this post?
Unlock left : 0
Are you sure want to cancel subscription?
-
00:00
00:00
Update Required Flash plugin
-
00:00
00:00