本帖最后由 asun1388 于 2013-7-17 07:55 编辑
stm32f407 dac如何产生三角波,使用定时器
dac代码如下void DAC_Configuration(void)
{
DAC_InitTypeDef DAC_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC , ENABLE);
DAC_InitStructure.DAC_Trigger = DAC_Trigger_T2_TRGO; //选择定时器2作外部触发源
DAC_InitStructure.DAC_WaveGeneration =DAC_Wave_Triangle; //产生三角波
DAC_InitStructure.DAC_LFSRUnmask_TriangleAmplitude = DAC_TriangleAmplitude_2047; //三角波的高为2047 最高可以为4095
DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Disable; //无输出缓冲 提高驱动能力可以打开缓冲
DAC_Init(DAC_Channel_1, &DAC_InitStructure);
DAC_DMACmd(DAC_Channel_1, DISABLE); //不使用DMA
DAC_Cmd(DAC_Channel_1, ENABLE);
}
dac gpio口配置如下void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
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);
}
tim 配置如下void TIM_Configuration(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2 , ENABLE);
TIM_TimeBaseStructure.TIM_Period = 168;
TIM_TimeBaseStructure.TIM_Prescaler = 0x0;
TIM_TimeBaseStructure.TIM_ClockDivision = 0x0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
TIM_SelectOutputTrigger(TIM2, TIM_TRGOSource_Update); //使用更新事件作为触发输出
TIM_Cmd(TIM2, ENABLE);
}
如何和定时器联系起来,求解。 |
楼主解决没,求一份代码1723614701@qq.com谢谢