| Alters: |
R24, R25, R26, R27, and the FLAGS |
| Example: |
PrintAIn:
MOVW R24, R26 ; Assuming this is the parsing buffer, point
LDI R22, ' ' ; to it and find the value after the first
CALL AParseValueAfter ; space, parsing the A2D index (0 - 10) into
SBRS R21, BIT_PV_VALID ; R25:R24
RET ; Exit if the value is invalid
MOV R24, R22 ; Move the Low BYTE parsed to R24, selecting
CALL AReadAtoDValue ; which most recent AIn value to obtain
MOVW R26, R24 ; Preserve the value during the next CALL
MOVW R22, R24 ; Set the value to be printed in R23:R22
LDI R19, '=' ; Select " = " rather than a " " separator
LDI R25, 0x3B ; Print "Analog input" (at address 0x3B4F in
LDI R24, 0x4F ; the system ASCIIz table) then an " = "
CALL APrintDescAndHexWORD ; then the HEX WORD value in R23:R22
MOVW R24, R26 ; Reload R25:R24 with the value printed
CALL APrintEqualDecWORD ; in HEX and print it in decimal as well
JMP APrintNewLine
;----- These two lines in the code above:
; LDI R25, 0x3B ; Print "Analog input" (at address 0x3B4F in
; LDI R24, 0x4F ; the system ASCIIz table) then an " = "
;----- Could be coded instead as:
; ACSZ_AIn = 0x3B4F ; Specify the address as a WORD constant
;
; LDI R25, ACSZ_AIn >> 8 ; Let the assembler calculate the address
; LDI R24, ACSZ_AIn & 0xFF ; MSByte and LSByte components
;-----
|
| Notes: |
There are eight (8) raw Analog Inputs available and three (3)
internal Voltage Reference values. A single system BIT,
BIT_SM_A2D in EEbSystemMode
enables continuous, sequential conversions of all eleven (11)
Analog-To-Digital (A2D) channels using a system interrupt. The
"settling" time, or delay between the time the next A2D channel is
selected and the conversion is begun, is set using
EEbA2DDelay,
which can range from 6 mSec to 250 mSec (nominally 8 mSec, thereby
converting all 11 raw inputs about 10 times each second. Once
configured, the A-to-D conversions are performed automatically as a
BACKGROUND task by the Operating System (or until disabled.) |
|
If, however, the index is above 10 (or 11, if using 1-based
indices), then the 10-bit value is obtained from the uVars.B[##] array
instead. There are at least two instances when this is useful: |
| 1. |
The raw value needs to be processed in some way, "flipped", for
example. Sometimes Analog Inputs arrive such that 0 is the maximum
value and 1,203 is the minimum value. In those cases, the wiring may
not be able to be changed to fix the issue. The value can simply be
subtracted from 1,023 (i.e., "flipped") and stored into uVars.B[##]
in order to make it function like the others (or at least more
intuitively.) The internal MCU Vcc is one example of this. |
| 2. |
A raw Analog Input is being received from a remote site via the
nRF24L01 radio. It needs to treat it in the same way as local
Analog Input(s) is/are treated, such as scaled, flipped, smoothed
(e.g., add 7/8 of its old value to 1/8 of its new value), or
alarmed based on its value. |
| Also see: |
The "A" command displays an Analog Value or
a uVars.B[##] WORD value (if valid, i.e., 0 to 0x3FF). The
BIT_OS_ONE_BASED
in EEbFlags_OS selects 1 to 11 rather than the default 0 to 10 as
the range for the "A" command only. This system routine is ALWAYS
0-based. BIT_RTC_SEC_AINS
in EEbFlags_RTC causes the values of all eleven AIns (or A2D
channels) to be printed once each second. |