Question
Producing analog voltage from DAC
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