Reading word variable

late_voyager

New Member
hi
I am trying to set a 24v low batt alarm.
i have volt dividers and adjusted to get reading ok
i have been trying to read w4 or b10 and b11 to add in code if w4 < 24xxx then alarm etc
cant seem to read w4 or b10,b11 and act on them however can display on screen
was trying:
if w4 < 23 then
goto lowbatt

or
if b10 <2 and b11<9 then
goto low batt

or
read w4, b27
if b27<24 then blah..

Code:
Symbol bbatt = w4        
Symbol batt = w8
symbol bbattv = 250
symbol battv = 38

readadc10 C.2, bbatt                                  ' 24v batt
     bbatt = bbatt *bbattv
      bintoascii bbatt,b10,b11,b12,b13,b14
readadc10 B.0, batt                                     ' 3v batt
     batt = batt *battv
      bintoascii batt,b18,b19,b20,b21,b22    

  
    serout C.0,N2400,(254,128) 
    serout C.0,N2400,("Batt ",b10,b11,"v - ",b18,".",b19,"v ")
 

Aries

New Member
(1) what values are you getting/expecting to get from your readadc10? Multiplying by 250 is a bit risky if your values can exceed 262 (out of a maximum of 1023)

There's nothing wrong with "if w4 < 23 then ...", provided w4 can actually be less than 23. However, if it is an integer multiplied by 250, it is either zero or greater than 250 (and certainly greater than 23) unless it overflows the 65535 maximum value for a word variable.

I don't think you mean "read w4,b27". That translates as
"take the value from the address in ROM gven by w4 (actually b8, because ROM is only 256 values) and put it in b27"
 

late_voyager

New Member
using 24v in
used 39k and 2.2k volt div to give 1.28v

Code:
FVRSETUP FVR2048      'Set Fixed Voltage Reference = 2.048 Volts
ADCCONFIG %011         'Set ADC to FVR
multiply by 1 instead of 250=
1543766744001.png
not looking for accurate +/- 1v is ok...
do i need readadc10 if not accurate?
 

Aries

New Member
using 24v in
used 39k and 2.2k volt div to give 1.28v

not looking for accurate +/- 1v is ok...
do i need readadc10 if not accurate?
readadc goes from 0 to 255 (i.e. +/-1 in 256), readadc10 goes from 0 to 1023. So, if you want +/- 1 in 24, readadc should be fine.
 
Top