Readadc question..

xtech007

Senior Member
Hi all !
I have a question regarding the following code:

main:
readadc 0,b1
readadc 1,b2

if b2<20 and b2>230 then gosub stop
if b1<120 then check
if b1>135 then check
goto Main

Would anyone recommend a pause from the analog inputs?
Or would it be better to use readc10 (10 bit resolution)?
the reason I ask is because I'm trying to control a dc motor with this code but it jitters when position is reached.(this is not the full code) I could post it if anyone is interested.
Once again thanks for your help !!! :)
 

bgrabowski

Senior Member
Not only do you need to show the whole programme but also the full circuit diagram. Are you using the manual 3 circuit for motor control?
 

westaust55

Moderator
READADC and incorporating some tolerance to stop jitter

The READADC can "drift"/vary a little if the analogue voltage fluctuates slightly or if the analogue value is on the border between two binary values.

You need to consider a small "tolerance" such as:

Code:
SYMBOL proximity = b3
SYMBOL tolerance = 5
:
:
IF  b1 >  b2 THEN
  proximity = b1 – b2
ELSE
  Proximilty = b2 – b1
ENDIF

IF proximity < tolerance THEN
  ; do the stopping stuff
ELSE
  ; continue turning motor
 

BeanieBots

Moderator
No pauses required but a small cap on the ADC inputs might help if there is any noise.
Also, this line will never execute.
"if b2<20 and b2>230 then gosub stop"

b2 can never be less than 20 AND greater than 230!
 
Top