2010-11-29 03:07 PM
dac configuration
2011-05-17 05:16 AM
Rule#1 If it has a clock, it needs to be running.
Like : RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE);2011-05-17 05:16 AM
Thanks but still doesn't work.
2011-05-17 05:16 AM
Hi rbpeter,
Your code seems quite healthy. Check that VREF+ pas is connected to your reference voltage. Did you configure PA4 pin ? Cheers, MCU Lüfter2011-05-17 05:16 AM
here is the configuration for PA4
GPIO_Init(GPIOC, &GPIO_InitStructure); /* Once the DAC channel is enabled, the corresponding GPIO pin is automatically connected to the DAC converter. In order to avoid parasitic consumption, the GPIO pin should be configured in analog */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN; GPIO_Init(GPIOA, &GPIO_InitStructure); I'm using the development kit, so I think it's already connected do Vref+. It seems like it's generating voltages around 1,70V only. I have to generate the whole interval, between 0 and 3,3V. Thanks2011-05-17 05:16 AM
Hi rbpeter,
Just check that GPIOA clock is enabled as done for DAC using RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE); If already done, check if there is an external component that froces the level on PA4 (perhaps a problem of impedance adapt). Herzlich MCU Lüfter2011-05-17 05:16 AM
Don't ALL the DAC examples(V2.0.1) enable PA.4 like this :
void GPIO_Configuration(void) { GPIO_InitTypeDef GPIO_InitStructure; /* Configure DAC channe1 output pin */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_Init(GPIOA, &GPIO_InitStructure); } Differs from the manual I know, but humor me. You'll also need to enable the GPIOA clock, and ALL the examples enable the AFIO clock.2011-05-17 05:16 AM
Pretty much all releases of Keil over the last few years, including latest uV 4.12, have the following
Examples\ST\STM32F10xFWLib (V2.0.1 6/13/2008) The DAC source tree is attached. I'm not saying this is ideal, I haven't evaluated it. But I'm more inclined to think that a PP driver is more apt to generate some output, than a high impedance analogue input. Then again it might also explain the use of AFIO, but I can't find a clear illustration in the TRM to pin this down.2011-05-17 05:16 AM
Hi Clive1,
Where did you find this configuration ? In the example provided by ST, I have found that they use ''GPIO_Mode_AIN'' which seems to match the analog behavior of DAC but not ''GPIO_Mode_Out_PP'' Herzlich, MCU Lüfter2011-05-17 05:16 AM
I'm trying to tailor an example used to generate triangle wave signals which is working.
DAC_InitTypeDef DAC_InitStructure;
/* TIM2 Configuration */
TIM_TimeBaseStructInit(&TIM_TimeBaseStructure); TIM_TimeBaseStructure.TIM_Period = 0xF; TIM_TimeBaseStructure.TIM_Prescaler = 0xF; TIM_TimeBaseStructure.TIM_ClockDivision = 0x0; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);/* TIM2 TRGO selection */
TIM_SelectOutputTrigger(TIM2, TIM_TRGOSource_Update);/* DAC channel1 Configuration */
DAC_InitStructure.DAC_Trigger = DAC_Trigger_T2_TRGO; DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_Triangle; DAC_InitStructure.DAC_LFSRUnmask_TriangleAmplitude = DAC_TriangleAmplitude_4095; DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Disable; DAC_Init(DAC_Channel_2, &DAC_InitStructure);/* Enable DAC Channel2: Once the DAC channel2 is enabled, PA.05 is
automatically connected to the DAC converter. */ DAC_Cmd(DAC_Channel_2, ENABLE);/* Set DAC dual channel DHR12RD register */
DAC_SetChannel2Data(DAC_Align_12b_R, 0x100);/* TIM2 enable counter */
TIM_Cmd(TIM2, ENABLE);while (1)
{ }The Reference Manual describes that I have to use this instruction to load a value in the DAC and the generated voltage would be: Vref * Loaded_Value/4095.This is how I'm tailoring the example:
DAC_InitTypeDef DAC_InitStructure;
/* DAC channel1 Configuration */
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);/* Enable DAC Channel2: Once the DAC channel2 is enabled, PA.05 is
automatically connected to the DAC converter. */ DAC_Cmd(DAC_Channel_2, ENABLE);/* Set DAC dual channel DHR12RD register */
DAC_SetChannel1Data(DAC_Align_12b_R, 0x100);while (1)
{ }It doesn't work. It always generate 1.70V at the exit.I don't know what else to do. Do you have any idea?
Thanks