The syntax of the "A" command is:
A[ ]#
where [ ] means zero or more spaces,
"#" is a numeric value, 0 to 255, selecting the AIn(#) index.
any other value is undefinded (but may report some numeric value)
Notes:
No distinction is made between uppercase and lowercase.
Only a single numeric value is parsed.
The numeric value may be specified in either decimal or hexadecimal format.
Anything after the first numeric value is ignored.
This command retrieves a value from the array reserved for the Analog Input
values, or from the uVars.B[##] array, and prints it to the console, in
both hexadecimal and decimal format.
The ATmega microcontroller contains an Analog to Digital (AtoD or A2D)
Converter. It can convert only one of its eleven (11) Analog Inputs to a
10-bit (i.e., 0 to 0x3FF = 0 to 1,023) analog value at a time. MIRTOS can
be configured to automatically cycle through each Analog Input (AIn) in
turn, perform the AtoD conversion for that AIn, and save the resulting
value to the wAnalogInputs[ 11 ] array. This Background task is
enabled when the BIT_SM_A2D bit in
EEbSystemMode is set, which can be very easily
enabled using the "E 1 |= 1" command. If not enabled, the array of 11 WORD
value (or block of 22 BYTEs) will not be updated and may be used for
other purposes.
The wAnalogInputs[ 11 ] array in SRAM:
Index | SRAM Address |
Variable Name |
Description / Physical Location |
TQFP 32 pin |
0 | 256 = 0x0100 |
wAnalogInput0 | ADC0 - PORT C, PIN 0 |
23 |
1 | 258 = 0x0102 |
wAnalogInput1 | ADC1 - PORT C, PIN 1 |
24 |
2 | 260 = 0x0104 |
wAnalogInput2 | ADC2 - PORT C, PIN 2 |
25 |
3 | 262 = 0x0106 |
wAnalogInput3 | ADC3 - PORT C, PIN 3 |
26 |
4 | 264 = 0x0108 |
wAnalogInput4 | ADC4 - PORT C, PIN 4 |
27 |
5 | 266 = 0x010A |
wAnalogInput5 | ADC5 - PORT C, PIN 5 |
28 |
6 | 268 = 0x010C |
wAnalogInput6 | ADC6 - *PORT E, PIN 2 |
19 |
7 | 270 = 0x010E |
wAnalogInput7 | ADC7 - *PORT E, PIN 3 |
22 |
8 | 272 = 0x0110 |
wVccAnalogInput | Internal MCU Vcc |
- |
9 | 274 = 0x0112 |
wGroundAnalogInput | Internal MCU Ground |
- |
10 | 276 = 0x0114 |
wDieTempAnalogInput | Internal MCU Temperature |
- |
* Same ADC# name but the "PORT E" designation is
new, beginning with the ATmega328PB |
>DS+ 256 22
SRAM contents:
0100: 00 00 00 00 00 00 00 00-00 00 F1 03 4B 01 FF 03 ............K...
0110: E0 00 00 00 5E 01 ....^.
>
Note: The example above shows:
ADC0 - ADC4 | 0x0000 | OFF (configured as Discrete I/O) |
ADC5 | 0x03F1 | ON (configured as Discrete I/O) |
ADC6 | 0x014B | Floating midrange; always Analog |
ADC7 | 0x03FF | Maximum value; always Analog |
Vcc | 0x00E0 | Approximately 5.02 Volts |
Ground | 0x0000 |
Die Temperature | 0x015E |
If the index specified (e.g., the 0 in "A 0") is between 0 and 10, inclusive
(or 1 to 11, if BIT_OS_ONE_BASED in
EEbFlags_OS is set), then the 10-bit value
for that index is obtained from the corresponding wAnalogInputs[ 11 ]
WORD array, shown above. Using the "A" command to print the same values
as are shown above to the console:
>A0
Analog input = 0x0000 = 0
>A1
Analog input = 0x0000 = 0
>a2
Analog input = 0x0000 = 0
>a 3
Analog input = 0x0000 = 0
>a 4
Analog input = 0x0000 = 0
>A 5
Analog input = 0x03F1 = 1,009
>A 6
Analog input = 0x014B = 331
>A7
Analog input = 0x03FF = 1,023
>A8
Analog input = 0x00E0 = 224
>a 9
Analog input = 0x0000 = 0
>A 10
Analog input = 0x015E = 350
>
If the index is above 10 (or 11, if using 1-based indices), then a 10-bit
value is obtained from the uVars.B[##] array instead, using two consecutive
bytes. "LSByte" below means "Least Significant Byte", which are the low
8 bits and "MSByte" means "Most Significant Byte", or the high 8 bits.
>dv+ ; Display the uVars.B[##] array contents first:
SRAM contents:
0280: 00 00 00 00 00 00 00 00-00 00 00 01 02 03 01 02 ................
0290: 00 01 01 02 02 03 03 04-02 00 00 00 00 00 00 00 ................
02A0: 03 00 FF 01 FF 02 FF 03-00 00 00 00 00 00 00 00 ................
>a 11 ; WORD value at 0x28B (0x28B has the LSByte, 0x28C has the MSByte)
Analog input = 0x0201 = 513
>A 12 ; WORD value at 0x28C
Analog input = 0x0302 = 770
>A 13 ; WORD value at 0x28D
Analog input = 0x0103 = 259
>A 14
Analog input = 0x0201 = 513
>A 15
Analog input = 0x0002 = 2
>A 16 ; WORD value at 0x290
Analog input = 0x0100 = 256
>A 0x10 ; same WORD value at 0x290
Analog input = 0x0100 = 256
>A 0x11
Analog input = 0x0101 = 257
>A 0x12
Analog input = 0x0201 = 513
>A 19
Analog input = 0x0202 = 514
>A 20
Analog input = 0x0302 = 770
>A 21
Analog input = 0x0303 = 771
>a 0x15
Analog input = 0x0303 = 771
>A 0x16 ; WORD at 0x296 = 0x0403 (overrange), so it was discarded
>A 0x17 ; WORD at 0x297
Analog input = 0x0204 = 516
>A 0x18
Analog input = 0x0002 = 2
>a 24 ; Same as "A 0x18"
Analog input = 0x0002 = 2
>A 0x20 ; WORD at 0x201
Analog input = 0x0003 = 3
>A 32 ; Same as "A 0x20"
Analog input = 0x0003 = 3
>A 33 ; WORD at 0x2A1 = 0xFF00, which is overrange
>A 34
Analog input = 0x01FF = 511
>A 35 ; WORD at 0x2A3 = 0xFF01; overrange
>A 36
Analog input = 0x02FF = 767
>A 37 ; WORD at 0x2A5 = 0xFF02; overrange
>A 38
Analog input = 0x03FF = 1,023
>A 39
Analog input = 0x0003 = 3
>A 40
Analog input = 0x0000 = 0
>
Values above 1,023 (= 0x3FF) are considered invalid and discarded by the
"A" Command, as shown above. The ReadAtoD
System Call does not filter the value in that way. It will return whatever
16-bit value that it finds at that uVars.B[##] index. You are responsible
for "landing" on the correct index.
Notes:
There is also a debugging option which displays all eleven (11)
Analog Values once each second:
>E 4 ^= 4 ; Toggle the analog array display each second
>0x0000 0x0000 0x0000 0x0000 0x0000 0x0000 0x013F 0x03FF 0x00E0 0x0000 0x015D
0x0000 0x0000 0x0000 0x0000 0x0000 0x03F1 0x0140 0x03FF 0x00E0 0x0000 0x015E
0x0000 0x0000 0x0000 0x0000 0x0000 0x0000 0x0142 0x03FF 0x00E0 0x0000 0x015B
0x0000 0x0000 0x0000 0x0000 0x0000 0x03F1 0x013F 0x03FF 0x00E0 0x0000 0x015C
0x0000 0x0000 0x0000 0x0000 0x0000 0x0000 0x0140 0x03FF 0x00E0 0x0000 0x015D
0x0000 0x0000 0x0000 0x0000 0x0000 0x03F1 0x013F 0x03FF 0x00E0 0x0000 0x015D
0x0000 0x0000 0x0000 0x0000 0x0000 0x0000 0x013F 0x03FF 0x00E0 0x0000 0x015C
0x0000 0x0000 0x0000 0x0000 0x0000 0x03F1 0x013F 0x03FF 0x00E0 0x0000 0x015E
0x0000 0x0000 0x0000 0x0000 0x0000 0x0000 0x013E 0x03FF 0x00E0 0x0000 0x015C
e 4 ^= 4 ; Toggle it back off
>
See also:
The ReadAtoD System Function Call
documentation and the EEbA2DDelay
Analog Input settling time System Variable.