DAC to ADC loop doesn't work
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-08-01 4:32 PM
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 ) ;
}
}
Solved! Go to Solution.
- Labels:
-
ADC
-
DAC
-
STM32CubeMX
-
STM32F7 Series
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-08-02 10:06 AM
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"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-08-01 9:18 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-08-01 11:30 PM
"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 ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-08-01 11:38 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-08-02 2:57 AM
"Don t just free run dac and adc."
Why ? what problem can it create ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-08-02 3:50 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-08-02 3:51 AM
the core also need memory bus time to run some code... if you run as fast as possible, might make the core sluggish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-08-02 10:06 AM
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"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-08-02 1:10 PM
Can someone explain this ?
