2010-11-29 03:07 PM
dac configuration
2011-05-17 05:16 AM
2011-05-17 05:16 AM
2011-05-17 05:16 AM
Oh, sorry, It was just a misspell.
I was doing it right. Still doesn't work. :(2011-05-17 05:16 AM
With
DAC_SetChannel2Data(DAC_Align_12b_R, i); I am able to drive my own wave form.2011-05-17 05:16 AM
int main(void)
{ GPIO_InitTypeDef GPIO_InitStructure; DAC_InitTypeDef DAC_InitStructure; TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; /* Enable DAC and GPIOC clock */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO | RCC_APB2Periph_GPIOA, ENABLE); RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC | RCC_APB1Periph_TIM2, ENABLE); /* Configure PA.04/05 (DAC) as output -------------------------*/ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA, &GPIO_InitStructure); #if 0 /* 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); /* TIM2 enable counter */ TIM_Cmd(TIM2, ENABLE); while (1) { } #else /* 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); while (1) { int i; for(i=0; i<4096; i++) DAC_SetChannel2Data(DAC_Align_12b_R, i); } #endif /* does not exit - kind of important */ return(1); }2011-05-17 05:16 AM
Hi clive1,
it worked, you're the guy! thank you very much. :)2011-05-17 05:16 AM
Hi rbpeter,
What was the tip to make it working ?MCU Lüfter2011-05-17 05:16 AM
The solution clive1 proposed generates an AC signal in the exit.
To generate a DC signal, you just have to set a value between 0 and 4095 on the DAC like: DAC_SetChannel2Data(DAC_Align_12b_R, value); and you don't have to put it into the loop, once the value is loaded to the register, the DAC keeps generating the corresponding voltage. I was also debugging with the osciloscope in the wrong capacitor. Thank you all2014-12-04 05:03 AM
Could you please check for me? It still doesn't work.
I'm using STM32F401VC Discovery.I dont see the define ''RCC_APB2Periph_AFIO'' in the library I'm using. Is there anything else I can use instead?I'm wondering if the PA4 and PA5 in my kit are out of order or not DAC1,2.Please help me!!int main(void){ GPIO_InitTypeDef GPIO_InitStructure; DAC_InitTypeDef DAC_InitStructure; /* Enable DAC and GPIOC clock */ RCC_APB2PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE); RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC , ENABLE); // Configure PA.04/05 (DAC) as output ------------------------- 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_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA, &GPIO_InitStructure); /* DAC channel1 Configuration */ DAC_InitStructure.DAC_Trigger = DAC_Trigger_None; DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None; DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Disable; DAC_Init(DAC_Channel_1, &DAC_InitStructure); DAC_Init(DAC_Channel_2, &DAC_InitStructure); DAC_Cmd(DAC_Channel_1, ENABLE); DAC_Cmd(DAC_Channel_2, ENABLE); while (1) { int i; for(i=0; i<4096; i++) { DAC_SetChannel1Data(DAC_Align_12b_R, i); DAC_SetChannel2Data(DAC_Align_12b_R, i); } } return(1);}2014-12-04 05:59 AM
This a four year old thread dealing with the STM32F1 parts, as I recall. The F4 pulls the AFIO functionality into the pin banks.
RCC_APB2PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
Should be AHB1 not APB2