2023-03-10 03:50 AM
I was using HAL Driver for DAC, however, it turned out not to be suitable for my project because at high sampling frequency, using HAL_DAC_Setvalue() inside a timer interrupt caused problem. So i need to write my own driver for DAC. But I have no idea how to get started. Is there any material someone could link?
2023-03-10 04:07 AM
Which STM32?
> using HAL_DAC_Setvalue() inside a timer interrupt caused problem.
What problems?
What do you mean by "high sampling frequency"?
> Is there any material someone could link?
The reference manual to your STM32. Using DAC - after having configured it - is only one write to its data register.
JW
2023-03-10 04:15 AM
Correct, you can also use LL instead of the HAL or control the DAC in bare metal. With the LL library you come quite close to bare metal, so that you only need to activate it: in STM32CubeMX > "project" > Project Manager > Advanced Settings --> click on HAL to the right of the peripheral DAC and change to LL.
Regards
/Peter
2023-03-10 04:19 AM
STM32 nucleo G071RB
i am trying to generate a sine waveform using DDS and i was using timer interrupt. The trig_frequency(sampling rate) when increased from 100KHz to higher, the output frequency had shift(decreased in value). The HAL_DAC_SetValue() requires more than 2us to execute while for sampling rate, for instance, 500 KHz = 2us and the code that I had written to assign LUT into a variable runtime > 2us so I need to not use HAL Driver for the DAC Setvalue. Something that doesn't take too much time to execute.
2023-03-10 04:21 AM
Or just switch on compiler optimization.
Although, generally, high-frequency interrupts are not a good idea.
Also, you start hitting DAC's electrical limitations, see DAC chapter in datasheet (tSETTLING, tW-to-W). Note, that if buffer is ON, DAC is not rail-to-rail.
JW
2023-03-10 04:33 AM
2023-03-10 04:33 AM
if you meant this, i couldn't find that option "Project Manager"
I assume it's not for G0 series.
2023-03-10 04:39 AM
Not in the STM32CubeIDE, but in its sub-function STM32CubeMX, which is also available as a stand-alone programme.
To start this, double-click the IOC on the left in the Project Explorer. In the CubeMX window that appears, the Project Manager is the third tab from the left, and in the left-hand column you will find the Advanced Settings.
2023-03-10 04:39 AM
Yes, but that is what my project requires. Unfortunately.
2023-03-10 04:41 AM
However, with 500kHz, i.e. 2µs, you come quite close to the maximum frequency of the DAC. As you can see from the data sheet, the DAC needs about 1.6-1.7µs settling time with the buffer switched on - OK, for a full 12bit jump. Anyway, that's a challenge, especially using an interrupt routine as @Community member noted.