DA通道2输出正常,DA通道1输出不正常,懂的帮忙看一下
本帖最后由 风继续吹QAQ 于 2015-6-11 10:41 编辑static void DAC_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
DAC_InitTypeDefDAC_InitStructure;
/* 使能GPIOA时钟 */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
/* 使能DAC时钟 */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE);
/* DAC的GPIO配置,模拟输入 */
GPIO_InitStructure.GPIO_Pin =GPIO_Pin_4|GPIO_Pin_5 ;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_InitStructure.GPIO_Mode= GPIO_Mode_AN;
GPIO_InitStructure.GPIO_PuPd= GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* 配置DAC 通道1 */
DAC_InitStructure.DAC_Trigger = DAC_Trigger_Software; //使用软件触发
DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None; //不使用波形发生器
DAC_InitStructure.DAC_Buffer_Switch = DAC_BufferSwitch_Disable; //不使用DAC输出缓冲
DAC_Init(DAC1,DAC_Channel_1,&DAC_InitStructure);
/* 配置DAC 通道2 */
DAC_InitStructure.DAC_Trigger = DAC_Trigger_Software;
DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_Triangle;
DAC_InitStructure.DAC_Buffer_Switch = DAC_BufferSwitch_Disable;
DAC_Init(DAC1, DAC_Channel_2,&DAC_InitStructure);
/* 使能通道1 由PA4输出 */
DAC_Cmd(DAC1,DAC_Channel_1, ENABLE);
/* 使能通道2 由PA5输出 */
DAC_Cmd(DAC1,DAC_Channel_2, ENABLE);
}
void DAC_test(void)
{
DAC_Config(); //调用DAC初始化函数
DAC_DualSoftwareTriggerCmd(DAC1,ENABLE); //同时启用两个DAC通道触发器
DAC_SetChannel2Data(DAC1,DAC_Align_12b_R,0xfff); //设置通道1输出电压值大约为3.3V
DAC_SoftwareTriggerCmd(DAC1,DAC_Channel_1,ENABLE);//使能DAC通道1
DAC_SetChannel2Data(DAC1,DAC_Align_12b_R,0x555);//设置通道1输出电压值大约为1.1V
DAC_SoftwareTriggerCmd(DAC1,DAC_Channel_2,ENABLE);//使能DAC通道2
}
int main(void)
{
DAC_test();
while (1)
{
}
}//通道1输出最大的时候也只是0.6V,而且根本不按程序的值输出。
恭喜楼主已经解决了 我太粗心了,DAC_SetChannel2Data(DAC1,DAC_Align_12b_R,0xfff);把这句改成:DAC_SetChannel1Data(DAC1,DAC_Align_12b_R,0xfff); 就好了 不懂帮顶 三思而后行啊:L 不懂帮顶 多细心点就好了
页:
[1]