初中生
最后登录1970-1-1
在线时间 小时
注册时间2013-5-4
|
楼主 |
发表于 2013-5-8 14:28:05
|
显示全部楼层
我刚才测试了一下dac,
程序如下
/****main.c****/
#include "stm32f10x.h"
#include "dac.h"
int main()
{
SystemInit();
AnalogInit();
DAC1_update(2047);
DAC2_update(1023);
}
/*******dac.c******/
#include "dac.h"
void AnalogInit(void)
{
DAC_InitTypeDef DAC_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO | RCC_APB2Periph_GPIOA, ENABLE);
/* DAC Periph clock enable */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE);
/* 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);
/* Configure DAC channe1 output pin */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* DAC channel1 Configuration */
DAC_InitStructure.DAC_Trigger = DAC_Trigger_Software;
DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None;
DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Disable; //输出缓冲失能
DAC_InitStructure.DAC_LFSRUnmask_TriangleAmplitude = DAC_TriangleAmplitude_4095;
DAC_Init(DAC_Channel_1, &DAC_InitStructure);
/* DAC channel2 Configuration */
DAC_Init(DAC_Channel_2, &DAC_InitStructure);
/* Enable DAC Channel1: Once the DAC channel1 is enabled, PA.04 is
automatically connected to the DAC converter. */
DAC_Cmd(DAC_Channel_1, ENABLE);
/* Enable DAC Channel2: Once the DAC channel2 is enabled, PA.05 is
automatically connected to the DAC converter. */
DAC_Cmd(DAC_Channel_2, ENABLE);
}
//端口1AD值更新
void DAC1_update(u16 ch1)
{
ch1 = (ch1 <<4) & 0xfff0;
/* Set DAC Channel1 DHR12L register */
DAC_SetChannel1Data(DAC_Align_12b_L, ch1);
/* Start DAC Channel1 conversion by software */
DAC_SoftwareTriggerCmd(DAC_Channel_1, ENABLE);
}
void DAC2_update(u16 ch2)
{
ch2 = (ch2 <<4) & 0xfff0;
/* Set DAC Channel2 DHR12L register */
DAC_SetChannel2Data(DAC_Align_12b_L, ch2);
/* Start DAC Channel1 conversion by software */
DAC_SoftwareTriggerCmd(DAC_Channel_2, ENABLE);
}
发现用万用表测dac的输出值,那个值不对。野火的板子参考电压为3.3v,那输出结果2.80v和0.76v与预想值有偏差 |
|