Embedded system design for ADC programs and theory

kanigiripoojitha51 11 views 7 slides Sep 16, 2024
Slide 1
Slide 1 of 7
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7

About This Presentation

For Education in Embedded systems design.


Slide Content

Light-dependent resistor (LDR) to measure ambient light intensity using the STM32 ADC. 

#include " main.h " #include<stdio.h> #include<string.h> ADC_HandleTypeDef hadc1; UART_HandleTypeDef huart2; uint16_t lux=0; char msg [20]; void SystemClock_Config (void); static void MX_GPIO_Init (void); static void MX_USART2_UART_Init(void); static void MX_ADC1_Init(void);

First we have to start the ADC in the interrupt mode by using the function below HAL_ADC_Start_IT (&hadc1); HAL_ADC_GetValuereads the value from ADC and stores it in the variable adc_val . Also note that if the continuousconversion mode is disabled, ADC will stop here and we have to again start the conversion in interrupt mode

HAL_ADC_Start (&hadc1); // start the adc HAL_ADC_PollForConversion (&hadc1, 100); // poll for conversion adc_val = HAL_ADC_GetValue (&hadc1); // get the adc value HAL_ADC_Stop (&hadc1); // stop adc HAL_Delay (500); // wait for 500ms

while (1) { HAL_ADC_Start (&hadc1); HAL_ADC_PollForConversion (&hadc1, 20); lux = HAL_ADC_GetValue (&hadc1); sprintf ( msg , "Light: %hu \r\n", lux); HAL_UART_Transmit (&huart2, (uint8_t *) msg , strlen ( msg ), HAL_MAX_DELAY); HAL_Delay (500); }

ADC PROGRAMMING EXERCISES STM32-based system for monitoring air quality using a gas sensor with analog output.  Embedded application using STM32 ADC to measure the output voltage of a solar panel for energy monitoring.  STM32-based system for monitoring soil moisture using a capacitive soil moisture sensor.  Light-dependent resistor (LDR) to measure ambient light intensity using the STM32 ADC. 
Tags