|
最近在做电流型信号输出的项目,遇到了些问题这里把这些解决方法做一个笔记方便以后运用。在搞这个的时候因为手册这部分讲的不是很详细,所以在使用上也遇到了些阻力。 用的是64封装的芯, 此芯ADC的基准Vref+和电源是同一个端口,Vref-共用电源地。在电池输出时AD值为0时 取样电阻100欧姆 有0.66mA的电流输出,只要在初始化时只要失能端口输出缓冲,输出可到0.0025mA。OK问题就解决了。 - 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);
- }
|