Associate III
August 1, 2020
Solved
DAC to ADC loop doesn't work
- August 1, 2020
- 8 replies
- 2868 views
Hello,
I'm working with the NUCLEO-F722ZE EVB on STM32CubeIDE.
My design has a DAC output connected via a jumper wire to an ADC input (see the red wire in the attached picture.
The DAC is successfully generating a sawtooth wave - verified via an oscilloscope.
However the ADC isn't working properly. I'm using a break point to stop the code and I see "semi constant" values.
By "semi constant" I mean that the reading is changes between compilations but is constant during runtime and seems to be unaffected by the DAC that's driving it.
What am I doing wrong ?
This is my code:
#include "main.h"
ADC_HandleTypeDef hadc3;
DAC_HandleTypeDef hdac;
UART_HandleTypeDef huart3;
uint32_t voltage_in = 0 ;
uint32_t voltage_out = 0 ;
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_USART3_UART_Init(void);
static void MX_DAC_Init(void);
static void MX_ADC3_Init(void);
int main(void)
{
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
MX_USART3_UART_Init();
MX_DAC_Init();
MX_ADC3_Init();
HAL_ADC_Start ( & hadc3 ) ;
HAL_DAC_Start ( & hdac , DAC_CHANNEL_1 ) ;
while (1)
{
if ( voltage_out == 4095 )
{
voltage_out = 0 ;
}
else
{
HAL_DAC_SetValue ( & hdac , DAC_CHANNEL_1 , DAC_ALIGN_12B_R , voltage_out ) ;
voltage_out ++ ;
}
HAL_ADC_PollForConversion ( & hadc3 , 1000 ) ;
voltage_in = HAL_ADC_GetValue ( & hadc3 ) ;
}
}