32-Channel ADC Object

Share on facebook
Share on twitter
Share on linkedin
Share on email
Share on print
Table of Contents
Description

The jm_analog_in_multi.spin2 object supports up to 32 ADC channels that can measure from 0 to 3.3v. The object is easily configured with a base pin, channel count, and low and high scaling factors that provide meaningful output from ADC channel readings. For example, using 0 and 3300 for the scaling factors provides the application readings from each channel in millivolts. After setup, individual channel scaling factors may be modified if desired. Each ADC channel is configured for 12 bits, using SINC2 filtering of 2048 samples per reading.

If you need more than 32 ADC channels, use a second instance of the object. 

We’ll use an actual Parallax customer request to demonstrate the object in a factory test fixture. The customer requested 16 UV Light Sensors connected to ADCs P0-P15. Shown above is the bench test proof of concept, with the sensors arranged adjacent to each other. The actual test fixture requires organizing the sensors in a 3D space around the device under test to detect UV light leakage. 

Two code archives are provided for download, below. The first one is the original object demo from Jon McPhalen, and the second is the modified version for the customer’s application with 16 UV Light Sensors. 

The following modifications were made for the customer’s application. Identify the first IO (P0) connected to the bank of UV Light Sensors. 

Sequence the additional ADC inputs from the same starting IO pin. CHANNELS = 16 assigns them from P0 to P15. 

Identify the low and high voltage ranges.

The pub setup() method configures the analog inputs by providing the constants and starts the terminal. It’s that easy —  jm_analog_in_multi.spin2 takes care of the measurements. 

The pub main() method receives the ADC values and displays them on Parallax Serial Terminal. The changes to the demo include the addition of a channels variable (CH ) to write the 16 channels of ADC to the terminal in a loop. This example works with both Parallax Serial Terminal and ANSI-compliant terminals (like the one in FlexProp). 

The waitct calculation stalls the application until 50 ms have elapsed from the first getct() value, making 20 updates per second. If the repeat loop requires more than 50 ms, this value should be increased. 

Programming Language
Tools and Operating System
Document Author
Source Code Author
Table of Contents
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments