打印
[STM8]

ADC问题

[复制链接]
1088|22
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
yinxiangh|  楼主 | 2023-1-7 09:50 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
320, ar, 3301, 30, vv, ADC
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| | 2023-1-7 09:52 | 只看该作者
用万用表监视VDD电压?

使用特权

评论回复
板凳
yinxiangh|  楼主 | 2023-1-7 09:54 | 只看该作者
3325mV,很稳定的

使用特权

评论回复
地板
chuxh| | 2023-1-7 09:57 | 只看该作者
如果有空闲,则运行相应的ALM_IDL(), WRN_IDL(), IDL();

使用特权

评论回复
5
dengdc| | 2023-1-7 09:59 | 只看该作者

万用表是短时间取平均值。你用示波器看

使用特权

评论回复
6
renyaq| | 2023-1-7 10:00 | 只看该作者
如果有毛刺就对了,如果有,加一个小电容滤波就可以了

使用特权

评论回复
7
heweibig| | 2023-1-7 10:05 | 只看该作者
硬件是如何连接的呢

使用特权

评论回复
8
gongche| | 2023-1-7 10:08 | 只看该作者
基准电压用的什么

使用特权

评论回复
9
bqyj| | 2023-1-7 10:10 | 只看该作者
直接接地看看采集到的是多少

使用特权

评论回复
10
jiahy| | 2023-1-7 10:16 | 只看该作者

这个波多很正常

使用特权

评论回复
11
jiahy| | 2023-1-7 10:17 | 只看该作者
在没做滤波处理的情况下,这个ADC的采样波动值算正常的。

使用特权

评论回复
12
chuxh| | 2023-1-7 10:19 | 只看该作者
对采样速率进行优化

使用特权

评论回复
13
supernan| | 2023-1-7 10:21 | 只看该作者
可能是基准的问题哦

使用特权

评论回复
14
zwll| | 2023-1-7 10:23 | 只看该作者
用一个恒压源接上 看看采样的结果是什么

使用特权

评论回复
15
liliang9554| | 2023-1-7 10:26 | 只看该作者
波动的不是很厉害啊

使用特权

评论回复
16
yinxiangh|  楼主 | 2023-1-7 10:28 | 只看该作者
其实还是不大明白,我再琢磨琢磨吧,多谢了哈先

使用特权

评论回复
17
tpgf| | 2023-2-6 14:24 | 只看该作者
adc使用的是外部电压基准还是内部电压基准啊

使用特权

评论回复
18
guanjiaer| | 2023-2-6 14:31 | 只看该作者
被采样信号是什么性质的信号啊 是不是采样频率不对啊

使用特权

评论回复
19
heimaojingzhang| | 2023-2-6 14:46 | 只看该作者
楼主自己写一个简单的取平均值的滤波算法

使用特权

评论回复
20
keaibukelian| | 2023-2-6 15:22 | 只看该作者
如果这个是原始数据的话  应该是还说得通的

使用特权

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

本版积分规则

723

主题

7134

帖子

2

粉丝