====== AdIn( ) ======
''variable = AdIn(channel)''
| //variable// | Variable to store results (No ''String'' or ''Single'') |
| //channel // | AD Channel Number (not I/O Pin Number) |
Cubloc has several 10bit Analog to Digital Converters (ADCs) and 16bit Pulse Width Modulators (PWMs). The user can use an ADC to convert analog signals to digital, or use a PWM to convert digital signals to analog.
The ''ADin'' command reads the analog signal's amplitude and stores the result in a variable. Depending on the model, the number of ADC ports may vary. For the CB280, there are 8 AD ports (P24 to P31). An ADC port **must be set to input** before use.
When a voltage between 0 and AVREF is applied, that voltage is converted to a value from 0 to 1023. AVREF can accept voltages from 2V to 5V. The default reference is 5V. If an AVREF of 3V is used, voltages from 0 and 3V are converted to a value from 0 to 1023.
(*Note: CB220 AVREF is fixed to 5V)
Dim A As Integer
Input 24 ' Set port 24 to input.
A = AdIn(0) ' Do a A/D conversion on channel 0 and store result in A
The CB220 and CB280 ADC ports are shown below:
Please refer to the following table for ADC channels.
| ^ CB220 ^ CB280 ^ CB290 ^ CT17xx ^ CB405 |
^ A/D channel 0 | I/O 0 | I/O 24 | I/O 8 | I/O 0 | I/O 16 |
^ A/D channel 1 | I/O 1 | I/O 25 | I/O 9 | I/O 1 | I/O 17 |
^ A/D channel 2 | I/O 2 | I/O 26 | I/O 10 | I/O 2 | I/O 18 |
^ A/D channel 3 | I/O 3 | I/O 27 | I/O 11 | I/O 3 | I/O 19 |
^ A/D channel 4 | I/O 4 | I/O 28 | I/O 12 | I/O 4 | I/O 20 |
^ A/D channel 5 | I/O 5 | I/O 29 | I/O 13 | I/O 5 | I/O 21 |
^ A/D channel 6 | I/O 6 | I/O 30 | I/O 14 | I/O 6 | I/O 22 |
^ A/D channel 7 | I/O 7 | I/O 31 | I/O 15 | I/O 7 | I/O 23 |
^ A/D channel 8 | | | | | I/O 32 |
^ A/D channel 9 | | | | | I/O 33 |
^ A/D channel 10 | | | | | I/O 34 |
^ A/D channel 11 | | | | | I/O 35 |
^ A/D channel 12 | | | | | I/O 36 |
^ A/D channel 13 | | | | | I/O 37 |
^ A/D channel 14 | | | | | I/O 38 |
^ A/D channel 15 | | | | | I/O 39 |
The ''ADIn'' statement does a single conversion per call. ''TADIn'' is a macro
that returns the average of 10 conversions, giving the user more precise
results. If you need more precision rather than speed, we recommend the
using ''TADIn'' instead of ''ADIn''. It is also possible to create your own
averaging or filtering code for better precision.
[[cubloc:index#system_library:|Go CUBLOC home]]