User Tools

Site Tools

한국어

cubloc:adin:index

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)

Return value Input voltage 0V 0 1023 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:

SOUT SIN ATN VSS P0 P1 P2 P3 P4 P5 P6 P7 1 2 3 4 5 6 7 8 9 10 11 12 24 23 22 21 20 19 18 17 16 15 14 13 VIN VSS RES VDD P15 P14 P13 P12 P11 P10 P9 P8 AD INPUT PORT SOUT SIN ATN VSS P0 P1 P2 P3 P4 P5 P6 P7 P8 P9 P10 P11 TX1 RX1 AVDD N/C P24 P25 P26 P27 P47 P46 P45 P44 P43 P42 P41 P40 VDD VSS RES N/C P16 P17 P18 P19 P20 P21 P22 P23 P15 P14 P13 P12 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 TTLTX1 TTLRX1 AVREF P48 P31 P30 P29 P28 P32 P33 P34 P35 P36 P37 P38 P39 AD INPUT PORT CB220 CB280

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.

Go CUBLOC home

cubloc/adin/index.txt · Last modified: 2016/04/14 11:07 (external edit)