Readadc Max & Min help

xtech007

Senior Member
Hi all!
thanks for the support and time.
I'm trying to read from two 10k Potentiometers, one for control(b1) and the other for feedback(b2). In the code below everything works as specified.
I will like to implement that b1 can only have an Max output of 140, so when the input is greater it will always be 140, but also in the other direction the out put will never be less than 100. I hope I kinda explained my problem.
Here is the code:
Code:
'###################  
'MAIN LOOP
'###################  

main:
readadc 0,b1							' read value on ADC0 into variable b1 from pot on steering wheel
readadc 1,b2  	      	  		            ' read value on ADC1 into variable b2 from pot = actual position



if b2<20 and b2>230 then gosub Motor_stop             
if b1<120 then check 						
if b1>120 then check		 				

goto Main

check:	        
        IF  b1 >  b2 THEN
          proximity = b1 - b2
        ELSE
          proximity = b2 - b1
        ENDIF

        IF proximity < tolerance THEN 
          GOSUB Motor_stop                            ' stop motor as actual position = selected +/- tolerance
        
        ELSEIF b1 > b2 THEN
          GOSUB turn_left                             ' If steering wheel is further left than feedback (b2) then Go Left
        
        ELSEIF b1 < b2 THEN
          GOSUB turn_right  		                  ' If steering wheel is further right than feedback (b2) thenGo Right
        
        ENDIF

goto Main


'###################  
'SUBROUTINES
'###################  

Turn_right:
HI2COUT [%10110000], 0, (Right)
HI2COUT 2, (Speed_1)
return


Turn_left:
HI2COUT [%10110000], 0, (Left)
HI2COUT 2, (Speed_1)
return

Motor_stop:
HI2COUT [%10110000], 0, (M_Stop)
HI2COUT 2, (Speed_0)
RETURN
 

lbenson

Senior Member
Your title suggests the answer. Does the following not work for you?

b1 = b1 max 140 min 100
 

xtech007

Senior Member
Thanks !

Mr. Ibenson thanks for the support.
I had read the manual on min and max variables but I tough it had to be written only in mathematical form and in different line of code.
like b1=b2*10 Max 100
 
Top