cancel
Showing results for 
Search instead for 
Did you mean: 

DAC to ADC loop doesn't work

skon.1
Senior

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 ) ;
  }
}

1 ACCEPTED SOLUTION

Accepted Solutions
skon.1
Senior

I fixed it.

What solved the problem is setting the "End Of Conversion Selection" from:

"EOC flag at the end of single channel conversions"

to

"EOC flag at the end of all conversions"

View solution in original post

8 REPLIES 8
S.Ma
Principal

Trt first to use the adc channel that is right where the dac is... No wire needed, and make sure the dac buffer is on. What are the triggers for dac and adc? Pwm from timer? Better use external trigger signals so you can probe them.

"Trt first to use the adc channel that is right where the dac is... No wire needed"

I can use the same pin for DAC and ADC at the same time ?

"What are the triggers for dac and adc?"

Can you explain what you mean ?

S.Ma
Principal

Yes you surely can have adc and dac on the same pin... You need to control the flow for dac and adc, kick a new output or a new conversion by a trigger edge from trigger pin to get started. Generate a 500 khz pwm grom timer and connect it to adc and dac trigger pin. Use hw trigger. Don t just free run dac and adc.

skon.1
Senior

"Don t just free run dac and adc."

Why ? what problem can it create ?

S.Ma
Principal

it is better to control the adc and dac sampling rate. especially if you use dma for both of them. and it s quite easy to implement. this way you can see both dac wave ram table and adc dma sampled ram table and compare them one to one. also remember the dac has slew rate and adc minimum sampling time.

S.Ma
Principal

the core also need memory bus time to run some code... if you run as fast as possible, might make the core sluggish

skon.1
Senior

I fixed it.

What solved the problem is setting the "End Of Conversion Selection" from:

"EOC flag at the end of single channel conversions"

to

"EOC flag at the end of all conversions"

skon.1
Senior

Can someone explain this ?