Stm32f103 DAC 最低電流輸出問題


Stm32f103 DAC 學習筆記

最近在做電流型信號輸出的項目,遇到了些問題這里把這些解決方法做一個筆記方便以后運用。在搞這個的時候因為手冊這部分講的不是很詳細,所以在使用上也遇到了些阻力。

用的是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 }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM