cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L- how to set DAC reference voltage

vicki19880929
Associate III
Posted on September 18, 2013 at 00:22

Hi all,

I'm working on STM32L-discovery board and currently I'm trying to configure two analog outputs with DAC.  I am able to see the result from the output pin but there seems to be some bias from the zero reference voltage.  (Say, when I set the digital value to zero, the analog output is 90 mV)  How should I modify my code to get the value zero?  The following is my configuration:

void AO_Config()

{

GPIO_InitTypeDef GPIO_InitStructure;

DAC_InitTypeDef DAC_InitStructure;

RCC_AHBPeriphClockCmd(RCC_AHBPeriph_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;

 

GPI

O_

Init(GPIOA,&GPIO_

InitStructure

);

DAC_DeInit();

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_2, &DAC_InitStructure);

DAC_Cmd(DAC_Channel_

2

,ENABLE);

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_R, 0x0000);

DAC_SetChannel2Data(DAC_Align_12b_R, 0x0000);

}

[edit]

When I used the scope to monitor the pin, the result is as the following:

PA4:   0.558V@0, 2.312V@4095

PA5:   0.002V@0, 2.909V@4095

The range of PA4 becomes smaller?  Don't really know why is that... 

Thanks a lot!

#discovery #dac #stm32l
2 REPLIES 2
raptorhal2
Lead
Posted on September 19, 2013 at 06:14

Check if solder bridge SB2 and jumper JP1 are set for measuring Idd. This puts a load on PA4.

Regards, Hal

vicki19880929
Associate III
Posted on September 19, 2013 at 20:09

Thanks Hal!  It works after I turn the JP1 off and remove the SB2!