973 views|3 replies

65

Posts

0

Resources
The OP
 

ADC Sampling Principle [Copy link]

 

Hello everyone! Recently I saw an ADC sampling code written by PIC18F45K80 series microcontroller. The main code is as follows:
ADC is 12-bit precision, one channel is sampled 64 times, and then the average value is calculated. However, I don’t understand the sentence V_SampleSum += (V_SampleData >> 4); V_SampleSum is the accumulated 64 AD sampling values. Why not just use V_SampleSum += ADC_SampleData;

I also hope that experts can explain the meaning of the code here, thank you!

#define        ShiftPoint            6
uint          V_SampleData = 0;                         //临时变量
ulong          V_SampleSum  = 0;                         //输出电压采集值累加
volatile    uint          V_SampleValueFilt = 0;                         //输出电压滤波采集值
 
ADC_SampleData = (uint)(((ADRESH&0x0F)<<8) + ADRESL);
 
case    S_54V:                    //54V采样电压通道
            {
                V_SampleData = ADC_SampleData + (V_SampleData - (V_SampleData >> 4));
                if(SampleFlag == 0)
                    V_SampleSum    += (V_SampleData >> 4);
                                        
                break;
            }
 
V_SampleValueFilt = (V_SampleSum>>(ShiftPoint));//求最终的ADC平均值

Latest reply

What is the sampling speed? Will the accuracy be much higher if the sampling is done in this way?   Details Published on 2024-3-4 10:02
 
 

6829

Posts

11

Resources
2
 

What is the sampling speed? Will the accuracy be much higher if the sampling is done in this way?

Comments

An interrupt will be generated after the AD conversion is completed  Details Published on 2024-3-4 10:30
 
 
 

65

Posts

0

Resources
3
 

Hello! The system clock FOSC is a crystal oscillator with a frequency of 11.0592, then multiplied by 4. The AD conversion clock is FOSC/64, and the AD result acquisition time TAD = 6

 
 
 

65

Posts

0

Resources
4
 
lugl4313820 posted on 2024-3-4 10:02 What is the sampling speed? Will the accuracy be much higher if the sampling is done in this way?

An interrupt will be generated after the AD conversion is completed

 
 
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews

Room 1530, Zhongguancun MOOC Times Building, Block B, 18 Zhongguancun Street, Haidian District, Beijing 100190, China Tel:(010)82350740 Postcode:100190

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list