2024-05-28 03:11 PM
Hi!
I am trying to run a 16-bit ADC on a Nucleo-H743ZI2 debug board. The measured voltage is DC, 1.25 Volts, obtained from the DAC output of the controller. ADC1 input is channel 5 (pin PB1 on the CN7 board connector is close to GNDA pin and a 6.8 µF tantalum capacitor is included between them). The measurement result is output every 0.3 seconds via USART3 to the terminal program on the PC. For programming I use CubeMX + IAR Workbench. Memory Protection Unit is enabled in the controller, as well as both caches: CPU ICache and CPU DCache. In the program generated by CubeMX, the internal voltage source VREFINT = 2.5 Volt is enabled. Fosc = 100 MHz. Asynchronous clock mode divided by 4. I used “Regular conversion launched by software” with “End of single conversion” and Sampling time = 8.5 cycles. Scan, continuous and discontinuous conversion modes – all of these modes have been disabled.
ADC1 is enabled as follows:
1) MX_ADC1_Init();
2) ADC_Disable(&hadc1);
3) ADC1->CR &= ~ADC_CR_DEEPPWD; // Deep-power-down disable;
4) ADC1->CR |= ADC_CR_ADVREGEN; // LDO enable;
5) ADC1->CR |= ADC_CR_BOOST; // Boost Mode enable (Fosc > 20 MHz);
6) HAL_ADCEx_Calibration_Start(&hadc1, ADC_CALIB_OFFSET_LINEARITY, ADC_SINGLE_ENDED);
7) ADC_Enable(&hadc1).
Initialization and connection of ADC1, Channel 5, are finished.
Of course, the results of execution of the functions specified in items 3 and 4 are checked in the corresponding loops.
Next, an infinite loop is enabled in which the ADC is started by the HAL_ADC_Start_IT(&hadc1) function. At the end of the measurement the interrupt calls the colback:
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc) {
if (hadc->Instance == ADC1) {
HAL_ADC_Stop_IT(&hadc1);
INTADC = 1;
}
} ,
where the bit “volatile bool INTADC” tells the program that the ADC conversion is finished and the result can be obtained:
__IO uint32_t uhADCxConvertedValue = HAL_ADC_GetValue(&hadc1);
Now, reset the INTADC bit and send the result via USART3 to the PC. However, instead of the expected measurement results, the screen displays random numbers in the range of approximately 8000 to 14000. If the ADC reference voltage = 2.5 Volts and the ADC input is 1.25 Volts, I expected to see a measurement result of about 32767 for a 16-bit ADC. However, I get a sequence of numbers that look like random numbers!
What have I left out of the program or turned on incorrectly? Please help!
2024-08-06 02:29 AM
Hello,
Did you already succeed with the following example in STM32CubeMx repository ?
NUCLEO-H743ZI\Examples\ADC\ADC_RegularConversion_Polling.
This example is a basic one with ADC1 conversion result polling.
Let me know if you further information,
Regards,
Simon
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.