Simple Analog Input

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

This example demonstrates how to configure a P2 I/O pin to sample and capture an analog input, and display the raw values using DEBUG.

The PINSTART method is used to configure the I/O pin, in this case for the ADC mode, which is described in the Propeller 2 Spin2 Documentation:

The arguments used in the method are:

The pipe symbol (|) is a logical OR operator and merges the low-level 1x magnification ADC pin configuration with the ADC smart pin mode. The 13 selects 14-bit sampling. The 0 is only a filler for the unused Yval parameter.

The RDPIN command obtains the ADC sample value and puts it into the variable i:

which is output to a DEBUG display with a 100 ms delay between values:

The values are raw numbers which are proportional to the voltage. To display millivolts you need to record the I/O pin’s values using the ADC’s internal switches to GND and VIO to calculate a scale factor and offset. 

Source Code
Programming Language
Tools and Operating System
Document Author
Source Code Author
Table of Contents
0 0 votes
Article Rating
Notify of
Newest Most Voted
Inline Feedbacks
View all comments
Jose Rullan

Thank you! I was in fact looking into how to configure a pin for analog input. Thanks for this. I hope there would be one Quick Bytes for each feature or keyword or concept. Great initiative!