最近在做电流型信号输出的项目,遇到了些问题这里把这些解决方法做一个笔记方便以后运用。在搞这个的时候因为手册这部分讲的不是很详细,所以在使用上也遇到了些阻力。
用的是64封装的芯, 此芯ADC的基准Vref+和电源是同一个端口,Vref-共用电源地。在电池输出时AD值为0时 取样电阻100欧姆有0.66mA的电流输出,只要在初始化时只要失能端口输出缓冲,输出可到0.0025mA。OK问题就解决了。
1 void AnalogInit(void)
2 {
3 DAC_InitTypeDef DAC_InitStructure;
4 GPIO_InitTypeDef GPIO_InitStructure;
5
6 RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO | RCC_APB2Periph_GPIOA, ENABLE);
7 /* DAC Periph clock enable */
8 RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE);
9
10 /* Configure DAC channe1 output pin */
11 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
12 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
13 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
14 GPIO_Init(GPIOA, &GPIO_InitStructure);
15
16 /* Configure DAC channe1 output pin */
17 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
18 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
19 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
20 GPIO_Init(GPIOA, &GPIO_InitStructure);
21
22
23 /* DAC channel1 Configuration */
24 DAC_InitStructure.DAC_Trigger = DAC_Trigger_Software;
25 DAC_InitStructure.DAC_WaveGeneraTIon = DAC_WaveGeneraTIon_None;
26 DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Disable; //输出缓冲失能
27 DAC_InitStructure.DAC_LFSRUnmask_TriangleAmplitude = DAC_TriangleAmplitude_4095;
28
29 DAC_Init(DAC_Channel_1, &DAC_InitStructure);
30
31 /* DAC channel2 ConfiguraTIon */
32 DAC_Init(DAC_Channel_2, &DAC_InitStructure);
33
34 /* Enable DAC Channel1: Once the DAC channel1 is enabled, PA.04 is
35 automaTIcally connected to the DAC converter. */
36 DAC_Cmd(DAC_Channel_1, ENABLE);
37 /* Enable DAC Channel2: Once the DAC channel2 is enabled, PA.05 is
38 automatically connected to the DAC converter. */
39 DAC_Cmd(DAC_Channel_2, ENABLE);
40
41 }
42
43 //端口1AD值更新
44 void DAC1_update(u16 ch1)
45 {
46 ch1 = (ch1 《《4) & 0xfff0;
47 /* Set DAC Channel1 DHR12L register */
48 DAC_SetChannel1Data(DAC_Align_12b_L, ch1);
49
50 /* Start DAC Channel1 conversion by software */
51 DAC_SoftwareTriggerCmd(DAC_Channel_1, ENABLE);
52 }
53
54 void DAC2_update(u16 ch2)
55 {
56 ch2 = (ch2 《《4) & 0xfff0;
57 /* Set DAC Channel2 DHR12L register */
58 DAC_SetChannel2Data(DAC_Align_12b_L, ch2);
59
60 /* Start DAC Channel1 conversion by software */
61 DAC_SoftwareTriggerCmd(DAC_Channel_2, ENABLE);
62 }