cancel
Showing results for 
Search instead for 
Did you mean: 

How to generate a DC level on STM32F4 DAC?

Rogers.Gary
Senior II
Posted on August 30, 2016 at 03:56

Hi,

I am using pin PA4 as a DAC output on an STM32F405. I then have a unity gain op-amp buffer. My supply is 3.3V.

What I want to do is rather than create a SINE output at some frequency, is to generate a DC signal. For example, at 2048 (ADC/2) I want a DC level of 1.65.

Basically, a DC level that is 3.3/4096.

Can someone please provide a sample DAC setup that would guide me on this, or some hints?

Thanks!

 

4 REPLIES 4
megahercas6
Senior
Posted on August 30, 2016 at 09:02

simple.

Fist, go to dac examples, delete dma/timer stuff, and use software register update function, that it !

GPIO_InitTypeDef GPIO_InitStructure;
DAC_InitTypeDef DAC_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE); 
RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOA, &GPIO_InitStructure);
DAC_InitStructure.DAC_Trigger = DAC_Trigger_None;
DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None;
DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Enable;
DAC_Init(DAC_Channel_1, &DAC_InitStructure);
DAC_Cmd(DAC_Channel_1, ENABLE);
DAC_SetChannel1Data(DAC_Align_12b_L, TYPE_DATA);

this may or may not work, but you can test it anyway
Walid FTITI_O
Senior II
Posted on August 30, 2016 at 15:31

Hi roofie01, 

I recommend the ''SimpleConversion'' example in

http://www.st.com/content/st_com/en/products/embedded-software/mcus-embedded-software/stm32-embedded-software/stm32cube-embedded-software/stm32cubef4.html

at this path: STM32Cube_FW_F4_V1.13.0\Projects\STM324xG_EVAL\Examples\DAC\DAC_SimpleConversion

You can enable the output buffer in the code there to reduce the output impedance, and to drive external loads directly without having to add an external operational amplifier

-Hannibal-

Rogers.Gary
Senior II
Posted on September 01, 2016 at 02:04

Thanks! Will try it.

Rogers.Gary
Senior II
Posted on September 01, 2016 at 02:06

Great, I did not know it could drive directly. As I designed the circuit, it was originally set up for an LPF active circuit, so I needed the op amp anyhow. Now requirements have changed and only a occasionally changing DC level is required. (about 1 to 2 Hz )

Thank you!