打印
[STM8]

ADC问题

[复制链接]
368|15
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
yinxiangh|  楼主 | 2020-12-1 23:30 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
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| | 2020-12-1 23:34 | 只看该作者
用万用表监视VDD电压?

使用特权

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

使用特权

评论回复
地板
pangb| | 2020-12-1 23:38 | 只看该作者
如果有空闲,则运行相应的ALM_IDL(), WRN_IDL(), IDL();

使用特权

评论回复
5
chenjunt| | 2020-12-1 23:45 | 只看该作者
万用表是短时间取平均值。你用示波器看

使用特权

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

使用特权

评论回复
7
yufe| | 2020-12-1 23:51 | 只看该作者
硬件是如何连接的呢

使用特权

评论回复
8
langgq| | 2020-12-1 23:54 | 只看该作者
基准电压用的什么

使用特权

评论回复
9
huanghuac| | 2020-12-1 23:57 | 只看该作者
直接接地看看采集到的是多少

使用特权

评论回复
10
yangxiaor520| | 2020-12-2 07:53 | 只看该作者
这个波多很正常

使用特权

评论回复
11
天意无罪| | 2020-12-2 08:33 | 只看该作者
在没做滤波处理的情况下,这个ADC的采样波动值算正常的。

使用特权

评论回复
12
chuxh| | 2020-12-2 18:47 | 只看该作者
对采样速率进行优化

使用特权

评论回复
13
pengf| | 2020-12-2 18:52 | 只看该作者
可能是基准的问题哦

使用特权

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

使用特权

评论回复
15
morrisk| | 2020-12-2 19:00 | 只看该作者
波动的不是很厉害啊

使用特权

评论回复
16
yinxiangh|  楼主 | 2020-12-2 19:03 | 只看该作者

其实还是不大明白,我再琢磨琢磨吧,多谢了哈先

使用特权

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

本版积分规则

723

主题

7134

帖子

2

粉丝