how to compare if ?

davidwf

Senior Member
Part of my program reads an ADC value into w3 and 10 mins later reads it again into w4........

readadc10 2,w3
for w2=1 to 10000
pause 60 ....... ( 10 min delay)
next w2
readadc10 2,w4

I can specify that

if w4<w3 then goto ..........
or if w4>w3 then goto ..........

which all works OK but I need to add a bit of tolerance and say something like

if w4<w3+5 then goto.....
or if w4+5>w3 then goto.....

obviously it can't be done like that so any ideas how I can do this would be appreciated but pease keep it simple ! :)

Thanks in advance
 

mikie_121

Member
why can't you just add/subtract 5 and then compare? The value stored in the word variable is a number between 0 and 1024 so it should be possible.
 

BCJKiwi

Senior Member
pause 60 is NOT 10 Mins! Re-read the pause command.

Code:
If w4 >  w3 then
   w5 = w4 - w3
Else
   w5 = w3 - w4
EndIf
' Hysteresis is the value you want to change by before acting on the change
If w5 > hysteresis then goto .....
This might get you started - there is probably a more efficient way to do it but this works.
 

westaust55

Moderator
pause 60 * 10,000 is a 10 minute delay:

for w2=1 to 10000
pause 60 ....... ( 10 min delay)
next w2

Correct, but might be better written as:
Code:
FOR w2=1 TO 10  ; loop once for each minute of delay desired
  PAUSE 60000 ;  1 min delay per loop
NEXT w2
 

Dave-nz2

New Member
Comparison within a tolerance

Part of my program reads an ADC value into w3 and 10 mins later reads it again into w4........
--[snip]--
which all works OK but I need to add a bit of tolerance ...
--[snip]--
Thanks in advance
Hope this is of some help. It's one way of doing it.

Code:
'--untested code--
'Assuming you cannot use another variable for this... 
'Assuming we don't have to worry about an overflow 
' condition where  (values+margin) > 65535. 
'Uncomment the lines restoring old if required
 
symbol old = w3
symbol new = w4
symbol tol = 5   'tolerance
 
''readadc10 2,old   '(consider old=new at end)
'( 10 min delay)
'readadc10 2,w4
 
'--Compare if new has changed from old by more than tolerance. 
 
If new > tol then
   If new > old then
      goto hasrisen
   Else
      goto notrisen
   EndIf
Else
   If old > tol then
      goto notrisen
   Else
      goto within
   EndIf
EndIf
 
hasrisen:
old = old + tol
If new > old then
   'old = old - tol   'restores old
   goto risen
Else
   'old = old - tol   'restores old
   goto within
EndIf
 
notrisen:
old = old - tol
If new < old then
   'old = old + tol   'restores old
   goto fallen
Else
   'old = old + tol   'restores old
   goto within
EndIf
 
risen:   'the new value has risen
' ---------------------------
' your code here for value rise
' ---------------------------
goto end_comparison
 
fallen:   'the new value has fallen
' ---------------------------
' your code here for value fall
' ---------------------------
goto end_comparison
 
within: 
' ------------------------------------------------------
' your code here for values within tolerance of each other
' ------------------------------------------------------
 
end_comparison:
'old = new
'--all done here - end of routine
 

davidwf

Senior Member
pause 60 is NOT 10 Mins! Re-read the pause command. QUOTE]

For once I believe I am correct.....
the pause command I used is

for w2=1 to 10000
pause 60 ....... ( 10 min delay)
next w2

...the reason I used 10000 * 60 (rather than say 100 * 6000 or 10*60000) is to allolw a quicker manual interventiion later in the program....
 
Last edited:
Top