Skip to main content
JEscu.2
Associate II
October 21, 2022
Solved

Signal Pass through using ADC and DAC

  • October 21, 2022
  • 4 replies
  • 4206 views

The equipment I am using is the following: Nucleo-Board L476RG, STM32CubeIde 1.10.1. I am attempting to design a simple dsp system that uses an ADC to send the data it receives from a function waveform generator to a DAC, and the DAC output will then be connected to an oscilloscope. I am trying to figure out how to use the TIM2 interrupt to drive sampling from PC2 with ADC1, and then immediately send the ADC data to DAC for output from PA4.

The function generator will generate a sin signal with a frequency of 100Hz.

Best answer by itsrabbit

You should set the timer interrrupt with the frequency you wish. It is calculated by:

TIM Interrup Frequency (Hz) = SYSCLK Freq / (ARR+1)*(PSC+1)

Then, in your interrupt callback function, you can just read the value of ADC:(HAL_ADC_GetValue(&hadcX);

After that, you can generate your DAC signal by writing the value you get. You can increase the interrupt frequency if you want a smoother DAC output signal. Do not forget to check the resolution values of ADC and DAC.

AC

4 replies

itsrabbit
itsrabbitBest answer
Associate
October 21, 2022

You should set the timer interrrupt with the frequency you wish. It is calculated by:

TIM Interrup Frequency (Hz) = SYSCLK Freq / (ARR+1)*(PSC+1)

Then, in your interrupt callback function, you can just read the value of ADC:(HAL_ADC_GetValue(&hadcX);

After that, you can generate your DAC signal by writing the value you get. You can increase the interrupt frequency if you want a smoother DAC output signal. Do not forget to check the resolution values of ADC and DAC.

AC

JEscu.2
JEscu.2Author
Associate II
October 25, 2022

I really appreciate the time you took to reply, your response provided very valuable information :)​

Javier1
Principal
October 21, 2022

0693W00000UoVlwQAF.pnghttps://community.st.com/s/question/0D50X0000AnrIsfSQE/stm32f0-peripheral-to-peripheral-dma-transfer

Specifics:

  • ADC in continous mode.
  • Tim2 triggering a DMA (peripheral-to-peripheral transfer) from the ADC result register to the DAC output register.

This way you could get very fast data transfers and your Core is almost free to do whatever you want.

I just checked RM0351 and your MCU should support peripheral to peripheral DMA transfers

0693W00000UoVqcQAF.png0693W00000UoVobQAF.png

hit me up in https://www.linkedin.com/in/javiermuñoz/
JEscu.2
JEscu.2Author
Associate II
October 25, 2022

Thank you for explaining how I can incorporate DMA, it helps clear up some questions I had about it. Although I asked for timer interrupt because I had an assignment that specifically asked to use that method.​

Acecream
Associate
February 24, 2023

Hello, I am just trying to do the same thing as you, could you please share a little more details about how I can read DAC from internal ADC.

I am using a voltage source and I can read the analog input from that on my screen. But how to transfer that into DAC and how to read the DAC value using a simple oscilloscope(like the hardware connection)?

Thank you for the help in advance!

Visitor II
February 27, 2025

Were you able to figure it out? I'm working on the same project.

Visitor II
February 27, 2025

Hey! I know it's been 2 years but did you figure out how to solve your problem? I am working on the same thing.