GetResult() is software filtering. I always got errors when filtering 10-bit AD before. I just got it right today.
The key is (unsigned long)(). If you don't add this, you will always get errors! Overflow during calculation, it seems that the bit is automatically reduced during calculation
ulong GetADCResult(uchar ch) { ulong AD_result; ADC_CONTR = ADC_POWER | ADC_SPEEDLL | ch | ADC_START; _nop_(); //Must wait before inquiry _nop_(); _nop_(); _nop_(); while (!(ADC_CONTR & ADC_FLAG));//Wait complete flag ADC_CONTR &= ~ADC_FLAG; //Close ADC AD_result=ADC_RES*4+ADC_RESL; return AD_result; //Return ADC result 10bit } ulong GetResult(uchar ch) //Filter segment { ulong AD_result=0,AD_result1=0; ulong AD_max,AD_min,AD_temp; char AD_i,AD_o; for(AD_i=0;AD_i<4;AD_i++) { AD_min=AD_max=GetADCResult(ch); AD_result=0; for(AD_o=0;AD_o<8;AD_o++) { AD_temp=GetADCResult(ch); if(AD_tempAD_max){AD_result =(unsigned long)(AD_result + (unsigned long)AD_max); AD_max=AD_temp;} else AD_result =(unsigned long)(AD_result + (unsigned long)AD_temp); } AD_result=(unsigned long)(AD_result/8); AD_result1=AD_result1+ (unsigned long)(AD_result); } AD_result1=(unsigned long)(AD_result1/4); return AD_result; //Return ADC result 10bit }
The method is based on: removing the maximum and minimum values and averaging. A total of 33 samples were taken and the average value of the results after removing 9 samples was obtained. I made the voltmeter myself and the speed is sufficient! If it is too slow, you can reduce the 4 in AD_i<4 or remove this loop.
Previous article:Design of intelligent water-saving control system for solar water heater based on STC single chip microcomputer
Next article:Colorful lights comprehensive C program
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- Sn-doped CuO nanostructure-based ethanol gas sensor for real-time drunk driving detection in vehicles
- Design considerations for automotive battery wiring harness
- Do you know all the various motors commonly used in automotive electronics?
- What are the functions of the Internet of Vehicles? What are the uses and benefits of the Internet of Vehicles?
- Power Inverter - A critical safety system for electric vehicles
- Analysis of the information security mechanism of AUTOSAR, the automotive embedded software framework
- Current Sensing Using Nanopower Op Amps
- Portable ESP32-S2 Web Server
- Looking for a microcontroller model
- Analysis of the problem that the program cannot run after F28004x online debugging reset
- Is the STM32 library function HAL_UART_Receive blocking?
- 【DIY Creative LED V2】Complete program
- The Engineer's Way of Quanhui, the author of "FPGA Timing Constraints and Analysis"
- ALTERA cyclone V sockit development board for sale at low price and can be exchanged for E coins
- GD32L233C-START Review——04. Comparison between analog IIC and hardware IIC driving OLED
- What is the driving voltage in LCD segment code screen?