打印
[STM8]

ADC问题

[复制链接]
765|12
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
yinxiangh|  楼主 | 2019-1-23 17:06 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
STM8L151K4T6
在一个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
......
请问正常吗?
沙发
wyjie| | 2019-1-23 17:08 | 只看该作者
用万用表监视VDD电压?

使用特权

评论回复
板凳
yinxiangh|  楼主 | 2019-1-23 17:11 | 只看该作者
3325mV,很稳定的

使用特权

评论回复
地板
chenjunt| | 2019-1-23 17:15 | 只看该作者
万用表是短时间取平均值。你用示波器看

使用特权

评论回复
5
kangzj| | 2019-1-23 17:17 | 只看该作者
如果有毛刺就对了,如果有,加一个小电容滤波就可以了

使用特权

评论回复
6
yinxiangh|  楼主 | 2019-1-23 17:21 | 只看该作者

好的,我明天去单位试一下,多谢各位大侠了哈,结贴了先        

使用特权

评论回复
7
观海| | 2019-2-18 10:08 | 只看该作者
硬件是如何连接的呢

使用特权

评论回复
8
木木guainv| | 2019-2-18 10:38 | 只看该作者
基准电压用的什么

使用特权

评论回复
9
xiaoqizi| | 2019-2-18 11:07 | 只看该作者
直接接地看看采集到的是多少

使用特权

评论回复
10
wowu| | 2019-2-18 12:14 | 只看该作者
对采样速率进行优化

使用特权

评论回复
11
wakayi| | 2019-2-18 12:47 | 只看该作者
可能是基准的问题哦

使用特权

评论回复
12
renzheshengui| | 2019-2-18 12:50 | 只看该作者
用一个恒压源接上 看看采样的结果是什么

使用特权

评论回复
13
heimaojingzhang| | 2019-2-18 14:20 | 只看该作者
波动的不是很厉害啊

使用特权

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

本版积分规则

723

主题

7134

帖子

2

粉丝