打印
[STM8]

求助:关于STM8L151K4T6 的ADC问题

[复制链接]
1344|3
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
mikenee|  楼主 | 2017-9-30 18:31 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
在一个STM8L151L的最小系统上,用例程测试了芯片的ADC功能,发现测量的数据不怎么稳定,请问正常吗?
ADC程序:
int main( void )
{
        char buf[64];
        u16 u16_adc1_value;  
        float fVal;

        CLK_PeripheralClockConfig (CLK_Peripheral_USART1,ENABLE);                                        //开启ADC/USART时钟
        CLK_PeripheralClockConfig (CLK_Peripheral_ADC1,ENABLE);                                                //开启ADC/USART时钟
        USART_Init(USART1,9600,USART_WordLength_8b,USART_StopBits_1,USART_Parity_No,USART_Mode_Tx);//USART初始化,9600,8N1
        USART_Cmd (USART1,ENABLE);                                                                                                        //使能USART

        /* Enable ADC clock */
        CLK_PeripheralClockConfig(CLK_Peripheral_ADC1, ENABLE);

        /* de-initialize ADC */
        ADC_DeInit(ADC1);

        /*ADC configuration
        ADC configured as follow:
        - Channel VREF
        - Mode = Single ConversionMode(ContinuousConvMode disabled)
        - Resolution = 12Bit
        - Prescaler = /1
        - sampling time 384 */

        ADC_VrefintCmd(ENABLE);
        delay_10us(3);


        ADC_Cmd(ADC1, ENABLE);         
        ADC_Init(ADC1, ADC_ConversionMode_Single,
        ADC_Resolution_12Bit, ADC_Prescaler_1);

        ADC_SamplingTimeConfig(ADC1, ADC_Group_FastChannels, ADC_SamplingTime_384Cycles);
        ADC_ChannelCmd(ADC1, ADC_Channel_Vrefint, ENABLE);
        delay_10us(3);
     
        while(1)
        {
                ADC_SoftwareStartConv (ADC1);//开启软件转换

                while(!ADC_GetFlagStatus (ADC1,ADC_FLAG_EOC));                                                        //等待转换结束
                ADC_ClearFlag (ADC1,ADC_FLAG_EOC);                                                                                //清除对应标志
                u16_adc1_value=ADC_GetConversionValue (ADC1);                                                        //获取转换值

                fVal = 1225;
                fVal *= 4096;
                fVal /= u16_adc1_value;
                         
                sprintf(buf,"VDD = %.1f mV \r\n",fVal);
                USART1_SendStr(buf);
     }
}

测量结果通过串口输出:
VDD = 3334.0 mV
VDD = 3338.4 mV
VDD = 3301.1 mV
VDD = 3301.1 mV
VDD = 3301.1 mV
VDD = 3301.1 mV
VDD = 3338.4 mV
VDD = 3301.1 mV
VDD = 3340.6 mV
VDD = 3318.5 mV
VDD = 3320.7 mV
VDD = 3327.3 mV
VDD = 3320.7 mV
VDD = 3334.0 mV
VDD = 3329.5 mV
VDD = 3309.8 mV
VDD = 3329.5 mV
VDD = 3340.6 mV
VDD = 3329.5 mV
VDD = 3338.4 mV
VDD = 3320.7 mV
VDD = 3301.1 mV
VDD = 3329.5 mV
VDD = 3329.5 mV
VDD = 3340.6 mV
VDD = 3340.6 mV
VDD = 3340.6 mV
VDD = 3338.4 mV
VDD = 3301.1 mV
VDD = 3338.4 mV
VDD = 3338.4 mV
VDD = 3338.4 mV
VDD = 3320.7 mV
VDD = 3334.0 mV
VDD = 3338.4 mV
VDD = 3338.4 mV
VDD = 3329.5 mV
VDD = 3325.1 mV
VDD = 3318.5 mV
VDD = 3334.0 mV
VDD = 3345.1 mV
VDD = 3334.0 mV
VDD = 3301.1 mV
VDD = 3340.6 mV
VDD = 3338.4 mV
VDD = 3318.5 mV
VDD = 3338.4 mV
VDD = 3338.4 mV
VDD = 3329.5 mV
VDD = 3338.4 mV
VDD = 3320.7 mV
VDD = 3329.5 mV
VDD = 3301.1 mV
VDD = 3336.2 mV
VDD = 3340.6 mV
VDD = 3301.1 mV
VDD = 3329.5 mV
VDD = 3336.2 mV
VDD = 3336.2 mV
VDD = 3338.4 mV
VDD = 3338.4 mV
VDD = 3338.4 mV
VDD = 3338.4 mV
VDD = 3301.1 mV
VDD = 3338.4 mV
VDD = 3329.5 mV
VDD = 3318.5 mV
VDD = 3329.5 mV
VDD = 3338.4 mV
VDD = 3329.5 mV
VDD = 3318.5 mV
VDD = 3338.4 mV
VDD = 3338.4 mV
VDD = 3338.4 mV
VDD = 3338.4 mV
VDD = 3329.5 mV
VDD = 3329.5 mV
VDD = 3334.0 mV
VDD = 3329.5 mV
VDD = 3329.5 mV
VDD = 3338.4 mV
VDD = 3329.5 mV
VDD = 3340.6 mV
VDD = 3329.5 mV
VDD = 3329.5 mV
VDD = 3338.4 mV
VDD = 3338.4 mV
VDD = 3338.4 mV
VDD = 3318.5 mV
VDD = 3334.0 mV
VDD = 3329.5 mV
VDD = 3338.4 mV
VDD = 3338.4 mV
VDD = 3340.6 mV
VDD = 3338.4 mV
VDD = 3329.5 mV
VDD = 3329.5 mV
VDD = 3336.2 mV
VDD = 3338.4 mV
VDD = 3301.1 mV
VDD = 3318.5 mV
VDD = 3340.6 mV
VDD = 3301.1 mV
VDD = 3338.4 mV
VDD = 3340.6 mV
VDD = 3334.0 mV
VDD = 3338.4 mV
VDD = 3338.4 mV
VDD = 3329.5 mV
VDD = 3320.7 mV
VDD = 3329.5 mV
VDD = 3301.1 mV
VDD = 3301.1 mV
VDD = 3301.1 mV
VDD = 3320.7 mV
VDD = 3301.1 mV
VDD = 3318.5 mV
VDD = 3338.4 mV
VDD = 3329.5 mV
VDD = 3334.0 mV
VDD = 3338.4 mV
VDD = 3345.1 mV
VDD = 3318.5 mV
VDD = 3340.6 mV
VDD = 3338.4 mV
VDD = 3329.5 mV
VDD = 3334.0 mV
VDD = 3301.1 mV
VDD = 3329.5 mV
VDD = 3340.6 mV
VDD = 3329.5 mV
VDD = 3320.7 mV
VDD = 3301.1 mV
VDD = 3338.4 mV
VDD = 3301.1 mV
VDD = 3340.6 mV
VDD = 3338.4 mV
VDD = 3340.6 mV
VDD = 3338.4 mV
VDD = 3340.6 mV
VDD = 3340.6 mV
VDD = 3340.6 mV
VDD = 3329.5 mV
VDD = 3318.5 mV
VDD = 3338.4 mV
VDD = 3329.5 mV
VDD = 3338.4 mV
VDD = 3318.5 mV
VDD = 3338.4 mV
VDD = 3329.5 mV
VDD = 3301.1 mV
VDD = 3338.4 mV
VDD = 3338.4 mV
VDD = 3329.5 mV
VDD = 3329.5 mV
VDD = 3320.7 mV
VDD = 3301.1 mV
VDD = 3338.4 mV
VDD = 3338.4 mV
VDD = 3320.7 mV
VDD = 3318.5 mV
VDD = 3320.7 mV
VDD = 3301.1 mV
VDD = 3340.6 mV
VDD = 3320.7 mV
VDD = 3301.1 mV
VDD = 3318.5 mV
VDD = 3338.4 mV
VDD = 3340.6 mV
VDD = 3338.4 mV
VDD = 3318.5 mV
VDD = 3318.5 mV
VDD = 3318.5 mV
VDD = 3329.5 mV
VDD = 3340.6 mV
VDD = 3338.4 mV
VDD = 3301.1 mV
VDD = 3301.1 mV
VDD = 3318.5 mV
VDD = 3329.5 mV
VDD = 3338.4 mV
VDD = 3320.7 mV
VDD = 3309.8 mV
VDD = 3340.6 mV
VDD = 3301.1 mV
VDD = 3329.5 mV
VDD = 3320.7 mV
VDD = 3318.5 mV
VDD = 3301.1 mV
VDD = 3329.5 mV
VDD = 3338.4 mV
VDD = 3338.4 mV
VDD = 3318.5 mV
VDD = 3301.1 mV
VDD = 3338.4 mV
VDD = 3334.0 mV
VDD = 3318.5 mV
VDD = 3338.4 mV
VDD = 3338.4 mV
VDD = 3338.4 mV
VDD = 3301.1 mV
VDD = 3301.1 mV
VDD = 3338.4 mV
VDD = 3318.5 mV
VDD = 3320.7 mV
VDD = 3320.7 mV
VDD = 3318.5 mV
VDD = 3309.8 mV
VDD = 3318.5 mV
VDD = 3301.1 mV
VDD = 3318.5 mV
VDD = 3338.4 mV
VDD = 3338.4 mV
VDD = 3320.7 mV
VDD = 3338.4 mV
VDD = 3340.6 mV
VDD = 3334.0 mV
VDD = 3318.5 mV
VDD = 3318.5 mV
VDD = 3340.6 mV
VDD = 3338.4 mV
VDD = 3309.8 mV
VDD = 3329.5 mV
VDD = 3338.4 mV
VDD = 3318.5 mV
VDD = 3318.5 mV
VDD = 3318.5 mV
VDD = 3301.1 mV
VDD = 3338.4 mV
VDD = 3301.1 mV
VDD = 3338.4 mV
VDD = 3334.0 mV
VDD = 3334.0 mV
VDD = 3329.5 mV
VDD = 3318.5 mV
VDD = 3301.1 mV
VDD = 3329.5 mV
VDD = 3338.4 mV
VDD = 3309.8 mV
VDD = 3338.4 mV
VDD = 3338.4 mV
VDD = 3318.5 mV
VDD = 3325.1 mV
VDD = 3340.6 mV
VDD = 3301.1 mV
VDD = 3329.5 mV
VDD = 3338.4 mV
VDD = 3334.0 mV
VDD = 3301.1 mV
VDD = 3318.5 mV
VDD = 3329.5 mV
VDD = 3338.4 mV
VDD = 3338.4 mV
VDD = 3338.4 mV
VDD = 3320.7 mV
VDD = 3318.5 mV
VDD = 3320.7 mV
VDD = 3329.5 mV
VDD = 3329.5 mV
VDD = 3318.5 mV
VDD = 3318.5 mV
VDD = 3338.4 mV
VDD = 3338.4 mV
VDD = 3340.6 mV
VDD = 3329.5 mV
VDD = 3301.1 mV
VDD = 3329.5 mV
VDD = 3334.0 mV
VDD = 3301.1 mV
VDD = 3329.5 mV
VDD = 3334.0 mV
VDD = 3338.4 mV
VDD = 3301.1 mV
VDD = 3329.5 mV
VDD = 3340.6 mV
VDD = 3338.4 mV
VDD = 3340.6 mV
VDD = 3318.5 mV
VDD = 3338.4 mV
VDD = 3334.0 mV
VDD = 3318.5 mV
VDD = 3338.4 mV
VDD = 3318.5 mV
VDD = 3345.1 mV
VDD = 3318.5 mV
VDD = 3340.6 mV
VDD = 3336.2 mV
VDD = 3318.5 mV
VDD = 3334.0 mV
VDD = 3338.4 mV
VDD = 3336.2 mV
VDD = 3320.7 mV
VDD = 3309.8 mV
VDD = 3338.4 mV
VDD = 3338.4 mV
VDD = 3338.4 mV
VDD = 3329.5 mV
VDD = 3340.6 mV
VDD = 3329.5 mV
VDD = 3318.5 mV
VDD = 3320.7 mV
VDD = 3320.7 mV
VDD = 3334.0 mV
VDD = 3329.5 mV
VDD = 3301.1 mV
VDD = 3320.7 mV
VDD = 3338.4 mV
VDD = 3329.5 mV
VDD = 3320.7 mV
VDD = 3338.4 mV
VDD = 3320.7 mV
VDD = 3301.1 mV
VDD = 3318.5 mV
VDD = 3338.4 mV
VDD = 3329.5 mV
VDD = 3329.5 mV
VDD = 3329.5 mV
VDD = 3338.4 mV
VDD = 3309.8 mV
VDD = 3320.7 mV
VDD = 3320.7 mV
VDD = 3309.8 mV
VDD = 3318.5 mV
VDD = 3301.1 mV
VDD = 3301.1 mV
VDD = 3345.1 mV
VDD = 3338.4 mV
VDD = 3334.0 mV
VDD = 3301.1 mV
VDD = 3329.5 mV
VDD = 3318.5 mV
VDD = 3327.3 mV
VDD = 3338.4 mV
VDD = 3320.7 mV
VDD = 3301.1 mV
VDD = 3340.6 mV
VDD = 3301.1 mV
VDD = 3338.4 mV
VDD = 3301.1 mV
VDD = 3336.2 mV
VDD = 3340.6 mV
VDD = 3338.4 mV
VDD = 3318.5 mV
VDD = 3340.6 mV
VDD = 3318.5 mV
VDD = 3334.0 mV
VDD = 3318.5 mV
VDD = 3318.5 mV
VDD = 3338.4 mV
VDD = 3338.4 mV
VDD = 3329.5 mV
VDD = 3340.6 mV
VDD = 3338.4 mV
VDD = 3340.6 mV
VDD = 3340.6 mV
VDD = 3340.6 mV
VDD = 3338.4 mV
VDD = 3338.4 mV
VDD = 3318.5 mV
VDD = 3345.1 mV
VDD = 3318.5 mV
VDD = 3336.2 mV
VDD = 3329.5 mV
VDD = 3338.4 mV
VDD = 3318.5 mV
VDD = 3320.7 mV
VDD = 3338.4 mV
VDD = 3318.5 mV
VDD = 3320.7 mV
VDD = 3336.2 mV
VDD = 3327.3 mV
VDD = 3338.4 mV
VDD = 3338.4 mV
VDD = 3340.6 mV
VDD = 3318.5 mV
VDD = 3340.6 mV
VDD = 3320.7 mV
VDD = 3338.4 mV
VDD = 3334.0 mV
VDD = 3338.4 mV
VDD = 3336.2 mV
VDD = 3301.1 mV
VDD = 3340.6 mV
VDD = 3329.5 mV
VDD = 3338.4 mV
VDD = 3345.1 mV
VDD = 3318.5 mV
VDD = 3327.3 mV
VDD = 3320.7 mV
VDD = 3336.2 mV
VDD = 3329.5 mV
VDD = 3318.5 mV
VDD = 3338.4 mV
VDD = 3336.2 mV
VDD = 3334.0 mV
VDD = 3338.4 mV
VDD = 3338.4 mV
VDD = 3345.1 mV
VDD = 3334.0 mV
VDD = 3338.4 mV
VDD = 3320.7 mV
VDD = 3340.6 mV
VDD = 3336.2 mV
VDD = 3301.1 mV
VDD = 3334.0 mV
VDD = 3338.4 mV
VDD = 3318.5 mV
VDD = 3320.7 mV
VDD = 3334.0 mV
VDD = 3340.6 mV
VDD = 3320.7 mV
VDD = 3329.5 mV
VDD = 3318.5 mV
VDD = 3338.4 mV
VDD = 3340.6 mV
VDD = 3318.5 mV
VDD = 3329.5 mV
VDD = 3329.5 mV
VDD = 3338.4 mV
VDD = 3320.7 mV
VDD = 3301.1 mV
VDD = 3318.5 mV
VDD = 3318.5 mV
VDD = 3340.6 mV
VDD = 3301.1 mV
VDD = 3318.5 mV
VDD = 3320.7 mV
VDD = 3320.7 mV
VDD = 3320.7 mV
VDD = 3340.6 mV
VDD = 3338.4 mV
VDD = 3329.5 mV
VDD = 3338.4 mV
VDD = 3329.5 mV
VDD = 3318.5 mV
VDD = 3320.7 mV
VDD = 3320.7 mV
VDD = 3318.5 mV
VDD = 3318.5 mV
VDD = 3334.0 mV
VDD = 3301.1 mV
VDD = 3329.5 mV
VDD = 3338.4 mV
VDD = 3329.5 mV
VDD = 3334.0 mV
VDD = 3329.5 mV
VDD = 3329.5 mV
VDD = 3340.6 mV
VDD = 3301.1 mV
VDD = 3301.1 mV
VDD = 3329.5 mV
VDD = 3318.5 mV
VDD = 3340.6 mV
VDD = 3338.4 mV
VDD = 3301.1 mV
VDD = 3336.2 mV
VDD = 3338.4 mV
VDD = 3334.0 mV
VDD = 3309.8 mV
VDD = 3318.5 mV
VDD = 3301.1 mV
VDD = 3340.6 mV
VDD = 3329.5 mV
VDD = 3338.4 mV
VDD = 3338.4 mV
VDD = 3340.6 mV
VDD = 3301.1 mV
VDD = 3338.4 mV
VDD = 3338.4 mV
VDD = 3301.1 mV
VDD = 3338.4 mV
VDD = 3301.1 mV
VDD = 3301.1 mV
VDD = 3334.0 mV
VDD = 3329.5 mV
VDD = 3340.6 mV
VDD = 3329.5 mV
VDD = 3338.4 mV
VDD = 3338.4 mV
VDD = 3340.6 mV
VDD = 3338.4 mV
VDD = 3301.1 mV
VDD = 3329.5 mV
VDD = 3325.1 mV
VDD = 3309.8 mV
VDD = 3338.4 mV
VDD = 3329.5 mV
VDD = 3309.8 mV
VDD = 3340.6 mV
VDD = 3301.1 mV
VDD = 3329.5 mV
VDD = 3338.4 mV
VDD = 3329.5 mV
VDD = 3340.6 mV
VDD = 3340.6 mV
VDD = 3329.5 mV
VDD = 3329.5 mV
VDD = 3320.7 mV
VDD = 3301.1 mV
VDD = 3301.1 mV
VDD = 3329.5 mV
VDD = 3340.6 mV
VDD = 3329.5 mV
VDD = 3329.5 mV
VDD = 3329.5 mV
VDD = 3301.1 mV
VDD = 3340.6 mV
VDD = 3320.7 mV
VDD = 3329.5 mV
VDD = 3334.0 mV
VDD = 3338.4 mV
VDD = 3318.5 mV
VDD = 3329.5 mV
VDD = 3318.5 mV
VDD = 3338.4 mV
VDD = 3329.5 mV
VDD = 3329.5 mV
VDD = 3338.4 mV
VDD = 3301.1 mV
......
请问正常吗?
沙发
mikenee|  楼主 | 2017-9-30 18:33 | 只看该作者
补充一下:用万用表监视VDD电压为3325mV,很稳定的

使用特权

评论回复
板凳
598330983| | 2017-10-1 22:24 | 只看该作者
万用表是短时间取平均值。你用示波器看

使用特权

评论回复
地板
598330983| | 2017-10-1 22:25 | 只看该作者
如果有毛刺就对了,如果有,加一个小电容滤波就可以了

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

4

主题

18

帖子

0

粉丝