cancel
Showing results for 
Search instead for 
Did you mean: 

GPIO, ADC and DAC not simultaneous

RShre.2
Associate III

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 */

}
}
 

 

 

Screenshot (48).png

13 REPLIES 13

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? 

if (TIM2->SR & TIM_SR_UIF)
{
 
HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_6);
 
if(__HAL_ADC_GET_FLAG(&hadc1, ADC_FLAG_EOC)){
adc = HAL_ADC_GetValue(&hadc1);
}
 
DAC1->DHR12R1 = adc;
 
TIM2->SR = ~TIM_SR_UIF;  /* Clear all interrupts */
 
}
From your comment, I understood this but this doesn't solve the problem. 

Post a minimal but complete compilable code exhibiting the problem.

JW

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.