cancel
Showing results for 
Search instead for 
Did you mean: 

Producing analog voltage from DAC

theory
Associate
Posted on June 11, 2015 at 21:29

Hi all,

I am trying to produce a constant voltage, say 2V, from DAC without using any external input source. In other words, the code will send in digital signal to DAC, producing 2V. I have attempted to set up the code but it does not work (~mV output), I am using the equation from specs V_DAC = V_REF*(DOR/4095). So if V_DAC = 2V, V_REF = 3.37V, then DOR = 24 Any thoughts? Thanks in advance.

int
main() {
…
uint16_t digital_2v = 0x097E; 
//digital signal: DOR = 2430 = 0x097E 
digital2analog_init(); 
//configuration function
delay_ms(500);
…
DAC_Cmd(DAC1, DAC_Channel_2, ENABLE);
DAC_SoftwareTriggerCmd(DAC1, DAC_Channel_2, ENABLE); 
//trigger DAC1 Channel2
DAC_SetChannel2Data(DAC1, DAC_Align_12b_R, digital_2v); 
//set digital signal to DHR1CH2
…
}
void
digital2analog_init() {
GPIO_InitTypeDef GPIO_InitStructure;
DAC_InitTypeDef DAC_InitStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
//DAC1 Channel2 output pin initialization
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOA, &GPIO_InitStructure);
//DAC1 Channel2 output configuration
RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC1, ENABLE);
DAC_InitStructure.DAC_Trigger = DAC_Trigger_Software;
DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None;
DAC_InitStructure.DAC_LFSRUnmask_TriangleAmplitude = DAC_LFSRUnmask_Bits2_0;
DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Enable;
DAC_Init(DAC1, DAC_Channel_2, &DAC_InitStructure);
DAC_Cmd(DAC1, DAC_Channel_2, ENABLE);
return
;
}

Shu #stm32f373cc
3 REPLIES 3
Posted on June 11, 2015 at 21:38

What's the pin attached too? Just a volt-meter, or a lot of other load?

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
theory
Associate
Posted on June 11, 2015 at 22:07

Hi Clive,

The pin's (PA5) is directly measured using a probe from a multimeter, without a load.

PS. I have also tried configuration using DAC_Trigger_None and called DAC_SetChannel2Data(...); does it make a difference?

Thanks alot,

Shu

Posted on June 11, 2015 at 22:23

I'd try it without the triggering, with/without the buffer, and both channels.

If it still isn't working, double check the voltage at VREF and AVDD. Output different values and single step through the code.

Make sure you're looking a the right pin, configure as a GPIO and drive high/low
Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..