Stm32f103 DAC 最低電流輸出問(wèn)題
最近在做電流型信號(hào)輸出的項(xiàng)目,遇到了些問(wèn)題這里把這些解決方法做一個(gè)筆記方便以后運(yùn)用。在搞這個(gè)的時(shí)候因?yàn)槭謨?cè)這部分講的不是很詳細(xì),所以在使用上也遇到了些阻力。
用的是64封裝的芯, 此芯ADC的基準(zhǔn)Vref+和電源是同一個(gè)端口,Vref-共用電源地。在電池輸出時(shí)AD值為0時(shí) 取樣電阻100歐姆有0.66mA的電流輸出,只要在初始化時(shí)只要失能端口輸出緩沖,輸出可到0.0025mA。OK問(wèn)題就解決了。
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 }