LogoLogo
  • Welcome!
  • Mission Statement
  • Contributing Guidelines
    • Embed CADs in Wiki Articles
  • VEX Worlds Livestream Archive
    • VEX U
    • V5RC High School
    • V5RC Middle School
    • VIQRC Middle School
    • VIQRC Elementary School
    • JROTC
  • ⚙️Hardware
    • Design Fundamentals
      • Gear Ratios
      • Internal Forces (Stress)
      • Torque
      • RPM
      • Center of Mass
    • Introduction to VEX Parts
      • Structure
        • C-Channels and Angles
        • Fasteners
        • Retainers
        • Gussets and Brackets
        • Bearings
        • Plate Metal and Flat Bars
      • Motion
        • High Strength Components
        • Gears and Sprockets
        • Traction Wheels
        • Mecanum Wheels
        • Omnidirectional Wheels
        • Flex Wheels
    • Robot Decorations
      • Part Dyeing
      • Metal Coloring
      • License Plate Holders
    • Lifts
      • Double Reverse Four Bar (DR4B or RD4B)
      • Four Bar
      • Scissor Lift
      • Six Bar
      • Other Lifts
      • Best Practices
    • Shooting Mechanisms
      • Catapult
      • Flywheel
      • Linear Puncher
    • Drivetrains
      • Tank Drive
      • Mecanum Drive
      • Holonomic Drive
      • Designing a Drivetrain
      • Best Practices
    • Pivots & Joints
    • Pneumatics
      • Best Practices - Pneumatics
    • Intakes
    • Flip Out Mechanisms
    • Defensive Mechanisms
    • Misc. Building Techniques
    • VexU
      • Common Manufacturing Techniques
        • 3D Printing
        • Laser Cutting
      • Custom Manufactured Parts Library
      • Commercial Off The Shelf Parts Library
  • 👑Team Administration
    • New Team Resources
      • Creating The Team
      • Gaining Interest for Robotics Teams
      • Attending Competitions
        • Elimination Bracket
    • Team Dynamics
      • Organization Structure and Longevity
      • Member Allocation and Management
      • How *Not* To Run a Team
    • Team Finances
      • One-Year Team Financial Breakdown
      • Funding Your Teams
    • Hosting Competitions
      • Live Streaming
      • Tournament Manager
        • Competition Electronics
        • Creating a Tournament
        • Tools
          • Field Set Control
          • Connecting Mobile Devices
          • Connecting Raspberry Pis
        • Match Control
          • Inputting Match Scores
          • Inputting Skills Scores
          • Inputting Scores on TM Mobile
        • Displays
        • Alliance Selection
      • Additional Event Partner Resources
    • VexU Organization Management
      • Getting Started in VexU
      • Team / Personnel Management
      • Volunteering At Local Events
  • 📚The Judging Process
    • The Engineering Design Process
      • Test and Refine
    • The Engineering Notebook
      • Segments of the Notebook
      • BLRS2 '23-'24 Engineering Notebook
      • Integrating Inventor Models into Documentation
      • Engineering Notebook Rubric Breakdown
    • The Interview
      • Interview Rubric Breakdown
    • Using Notion for an Engineering Notebook
      • How to Setup a Notebook
      • How to Create Entries
      • How to Export a Notebook
      • Purdue SIGBots Notion Template
        • Game Analysis
        • Identify The Problem
        • Brainstorm Solution
        • Select Best Approach & Plan
        • Build Log
        • Programming Log
        • Testing Solution
        • Tournament Recap
        • Innovative Feature
  • 🖥️VEX CAD
    • CAD Programs
      • Inventor
      • Fusion 360
      • Solidworks
      • OnShape
      • Protobot
    • Making a Chassis
      • Inventor Chassis: The Basics
        • Installation
        • User Interface Overview
        • Dark Mode
        • Assemblies
        • Placing Parts
        • Navigating CAD
        • Changing Visual Style
        • Grounding
        • Connecting Two C-Channels
        • Modifying Existing Constraints
        • Toggling Visibility on Existing Parts
        • Completing Half of the Chassis
          • Inner Drive Channel
          • Bearing Flats
          • Motors
          • Wheels
          • Sprockets
          • Spacers, Washers and Standoffs
          • Spacers Cont.
        • Creating Mid-Plane
        • Mirroring
      • Inventor Chassis: Best Practices
        • File Structure
        • Subassemblies
        • Wheel Subassembly
        • Origin Planes
        • Cross Brace
        • Drive Channels
        • Simple Motor iMates
        • Replacing Simple Electronics
        • Completing Half of the Drive
          • Bearing Flats (Best Practice)
          • Wheels
          • Powered Gear
          • Spacer Boxing
          • Spacers, Washers and Standoffs (Best Practice)
        • Model Browser Folders
        • Mirroring (Best Practice)
        • Model Browser Folder (Right)
        • Main Assembly
      • Fusion 360 Chassis
      • Solidworks Chassis, Chain, and Custom Plastic
    • Remembering The Best
      • 62A Skyrise
      • 400X Nothing But Net
      • 2587Z Nothing But Net
      • 365X Starstruck
      • 62A In The Zone
      • 202Z In The Zone
      • 5225A In The Zone
      • 169A Turning Point
      • 929U Turning Point
      • 7K Tower Takeover
      • 5225A Tower Takeover
      • 62A Change Up
    • Scuff Controller
  • 💻Software
    • Odometry
    • Path Planning
    • Robotics Basics
      • Arcade Drive
      • Tank Drive
      • Joystick Deadzones
      • Curvature (Cheesy) Drive
      • Subsystem Toggling
    • Organizing Code
      • Code Style
      • Code Styling Guide
      • Writing Good Comments
      • Version Control
    • Control Algorithms
      • Bang Bang
      • PID Controller
      • Basic Pure Pursuit
      • Flywheel Velocity Control
      • Kalman Filter
      • Take Back Half (TBH) Controller
      • RAMSETE Controller
    • Competition Specific
      • Operator Control
      • Autonomous Control
    • C++ Basics for VEX Robotics
      • Basic Control Flow
      • Enumerations
      • Namespaces (::)
      • Multiple Files (C/C++)
    • VEX Programming Software
      • PROS
        • OkapiLib
      • vexide
      • Robot Mesh Studio (RMS)
      • EasyC
      • RobotC
      • VEXcode
      • Midnight C
    • General
      • Stall Detection
      • Register Programming
      • Sensors and Odometry in Autonomous
      • Embedded Programming Tips
      • Debugging
      • Bit Shift
      • Bit Mask
      • Autoformatting
      • Finite State Machine
      • Data Logging
    • Object Recognition
      • Red Green Buoy
      • AMS
      • OpenCV
      • OpenNI
    • 🤖AI in VRC: Pac-Man Pete
  • ⚡VEX Electronics
    • V5 ESD Protection Board
    • VEX Electronics
      • VEX V5 Brain
        • V5 Electronics Observations and Issues
      • VEX Controller
      • VEXnet and V5 Robot Radio
      • VEX Battery
      • VEX Motors
    • VEX Sensors
      • 3-Pin / ADI Sensors
        • Encoder
        • Potentiometer
        • Limit Switch
        • Bumper Switch
        • Accelerometer
        • Gyroscope
        • Ultrasonic
        • Line Tracker
        • LED Indicator
      • Smart Port Sensors
        • GPS Sensor
        • Rotation Sensor
        • Vision Sensor
        • Optical Sensor
        • Distance Sensor
        • Inertial Sensor (IMU)
        • 3-Wire Expander
    • V5 Brain Wiring Guide
    • Legacy
      • VEX Cortex
      • Power Expander
      • VEX Motor Controller
      • VEX Cortex Wiring Guide
  • General Electronics
    • General Topics
      • External Boards
        • ASUS Tinker Board S
        • Arduino
        • Beagleboard
        • Leaflabs Maple
        • LattePanda
        • Meadow F7 Micro
        • Netduino
        • ODROID-XU4
        • Pandaboard
        • Raspberry Pi
      • Analog-Digital Converter (ADC)
      • Bit-Bang
      • GPIO
      • I2C
      • Jitter
      • Line Noise
      • List of Tools
      • Output Drive
      • Power Consumption
      • Radius Array
      • Resettable Fuse (PTC)
      • SPI
      • Slew Rate
      • Stalling
      • USART
      • UART
      • 5 Volt Tolerant
      • DC Motor Basics
Powered by GitBook
LogoLogo

This work is licensed under a Attribution-ShareAlike 2.0 Generic License

On this page
  • Principles
  • Usage
  • Accuracy and noise
  • Sampling
  • Reconstruction
  • Sample code

Was this helpful?

Edit on GitHub
Export as PDF
  1. General Electronics
  2. General Topics

Analog-Digital Converter (ADC)

An analog-to-digital converter (or ADC for short) is a device or microcontroller feature which converts an analog input voltage to a numeric value which a user program can use.

The output resolution of the number received from and ADC can vary from 8-bit to 24-bit, corresponding to the number of digital discrete outputs and the smallest detectable difference between input voltage.

Principles

Digital circuits like a microcontroller or computer can only understand binary logic. However, sensors such as the VEX Line Tracker and VEX Gyro often provide a continuously varying output voltage level. Since a standard digital input would do a poor job, providing a useless 1-bit value, an analog-to-digital converter is used to convert the voltage to a number. Common ADCs vary from 8-bit to 16-bit precision, which dictates how many different values could theoretically be produced by an input voltage. In practice, noise limits the precision of any ADC to between 0.5 and 2 bits less than its stated value.

Many ADCs found in microcontroller applications operate on SAR (successive approximation register) principles. This method begins by guessing a number midway through the range of possible values, and performs a binary search by comparing the input voltage in the analog domain to the voltage produced by a digital-to-analog converter with the current guess as input. After a few iterations, the guesses will converge on the closest numeric representation to the specified input voltage. Alternatively, integrating ADCs are very slow but provide highly accurate readings, and sigma-delta ADCs are commonly used for applications requiring high bit depths at moderate sampling rates.

Analog inputs are seldom 5-volt tolerant if the microcontroller's I/O voltage is less than 5 volts, due to the high sensitivity of the conversion circuitry required.

Usage

Accuracy and noise

Analog inputs can be highly accurate, but are vulnerable to line noise generated by other sensors, VEX motors, and long cables. The effective number of bits, or ENOB, is a measure reflecting how many usable bits of precision an ADC has when noise is present. Noise inflicted from electromagnetic fields can be virtually eliminated by using twisted pair cables with a ground connection, as the field will be positive half the time and negative the other half to cancel out the noise. For particularly sensitive signals, steel parts can be used to act as RF shielding.

Noise also can come from direct electrical sources. Strategically inserting small-valued capacitors at key points near potential noise sources can reduce noise, especially that generated from digital circuits switching on and off. In particular, noise on the analog reference voltage will severely affect the reading. Isolating this supply pin from noisy digital circuits using capacitors or even a separate voltage regulator can pay dividends for ADCs.

Sampling

A common use for analog-to-digital converters is to sample a signal from a sensor at periodic intervals. While this may seem as simple as using analogRead in a repeating loop, there are hidden nuances, especially if the signal is to be later reconstructed. Software jitter and latency in the sampling loop must be minimized.

The input signal must also be band-limited to prevent aliasing problems like those shown in the picture, as the program can easily be misled into thinking that one frequency is present when another is actually the cause. To eliminate this problem, add a low-pass filter to prevent signals higher than 1/2 the sampling rate from reaching the ADC. Even with such a filter in place, one should sample at least four times faster than the fastest frequency that must be understood for reasons explained in the reconstruction section.

Sampling even faster (16 times the desired frequency or higher), known as oversampling, allows the precision of the ADC to be increased by averaging multiple samples together. This cancels out noise to increase the signal-to-noise ratio (SNR) and therefore the effective number of bits. A frequency analysis of the input signal using an Oscilloscope is the most useful way to determine the maximum expected frequency and appropriate filtering/sampling strategy.

Reconstruction

Oftentimes, a signal is sampled from an analog system with the intent on processing it and displaying the output to the user. Digital signal processing only operates on the signal at discrete points in time, so the signal values between these points must be filled in during display.

The simplest method, known as zero-order hold, draws horizontal lines with a step discontinuity at each sample. While extremely economical on processing power, the resulting signal often looks very blocky. The most common method, linear interpolation, draws lines to connect each sampled value to strike a balance between signal quality and CPU usage. While sinc interpolation produces a very smooth, accurate signal, it is computationally expensive.

Sample code

For the VEX Cortex using PROS, the following code structure is recommended:

// Function samples the ADC at 1 KHz
void sampleADC() {
    unsigned int port1, port2;
    clock_t now = millis();
    while (1) {
        // Read in the desired analog ports
        port1 = analogRead(1);
        port2 = analogRead(2);
        // Perform processing
        /* { } */
        // Precise delay function accounts for the time taken by processing
        // 1UL -> 1 ms (1 KHz), adjust as necessary for sensor used
        // Note that rates over 1 KHz cannot be achieved using user mode, as this
        // could starve the CPU. See the kernel mode drivers page for details.
        taskDelayUntil(&now, 1UL);
    }
}

// Called when the robot is powered on
void initialize() {
    // This will create a task that is always runnning, even if robot is disabled
    // To run the sampling task in only one mode (autonomous() or operatorControl()),
    // use taskRunLoop() instead.
    taskCreate(sampleADC, TASK_DEFAULT_STACK_SIZE, NULL, TASK_PRIORITY_DEFAULT + 1, NULL);
}

If the sensor value must be corrected for a zero-rate offset (a sensor like a Gyro or Accelerometer), use analogReadCalibrated() with an analogCalibrate() in the initialize function. When doing so, make sure that the robot is stable during power-on.

Teams Contributed to this Article:

  • BLRS (Purdue SIGBots)

PreviousRaspberry PiNextBit-Bang

Last updated 4 years ago

Was this helpful?