2023-07-24 09:19 AM - edited 2023-07-24 09:49 AM
I am using stm32 g071 and what I have done in the code is to toggle pin and send the value through adc and finally output through dac. Theoretically, the GPIO output and DAC output should be simultaneous but due to processing time and all, there will be delay, however, in this case, this is inverted. Could anyone help me explain this behavior?
In the picture, the blue signal is from GPIO pin from MCU and red signal is the adc signal converted to dac.
void TIM2_IRQHandler(void)
{
if (TIM2->SR & TIM_SR_UIF)
{
HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_6);
adc = HAL_ADC_GetValue(&hadc1);
DAC1->DHR12R1 = adc;
TIM2->SR = ~TIM_SR_UIF; /* Clear all interrupts */
}
}
Solved! Go to Solution.
2023-07-25 06:21 AM
to check if the conversion is complete,
if (HAL_ADC_PollForConversion(&hadc1, HAL_MAX_DELAY) == HAL_OK) {
adcflag = 1;// The conversion is complete
}
if(adcflag == 1){
adc = HAL_ADC_GetValue(&hadc1);
}
but this didn't work. I wonder if I did correctly?
2023-07-25 06:32 AM
2023-07-26 06:25 AM
Post a minimal but complete compilable code exhibiting the problem.
JW
2023-07-28 06:33 AM
Thank you. Will do that next time. I figured out the solution for this particular problem. Just had to clear the EOC before reading ADC.