radar system using PING sensor and stepper motor....
i wan build mini project about PING Sensor that detect distance... and i wan make this sensor work with stepper motor..
this is my simple radar will works:
start>>motor rotate in cw & ccw>>sensor detect the object>>motor stop>>show the distance
my coding:
' {$STAMP BS2}
' {$PBASIC 2.5}
Phase VAR OUTB 'phase control outputs
StpsPerRev CON 24 'whole steps per rev (24=180, 48-=360)
idx VAR Byte 'loop counter
stpldx VAR Nib 'step pointer
Steps DATA %0011, %0110, %1100, %1001
Setup:
DIRB=%1111 'make P4-P7 outputs
Main:
FOR idx= 1 TO StpsPerRev 'one revolution
GOSUB STEP_Fwd 'rotate clockwise
NEXT
PAUSE 1000 'wait 1 second
FOR idx = 1 TO StpsPerRev 'one revolutionGOSUB Step_Rev 'rotate counter-clockwise
NEXT
PAUSE 1000 'wait 1second
GOTO Main
END
Step_Fwd:
stpldx = stpldx+1//4 'point to next step
GOTO Do_Step
Step_Rev:
stpldx = stpldx+3//4 ' point to previous step
GOTO Do_Step
Do_Step:
READ(Steps+stpldx), Phase ' outputs new phase data
PAUSE 1000 ' delay between steps
'RECEIVE THE SIGNAL
cmconstant CON 2260
cmdistance VAR Word
time VAR Word
PULSOUT 15,5 'port 15
PULSIN 15,1,time
cmdistance=cmconstant**time
END
but not work... some can help?
this is my simple radar will works:
start>>motor rotate in cw & ccw>>sensor detect the object>>motor stop>>show the distance
my coding:
' {$STAMP BS2}
' {$PBASIC 2.5}
Phase VAR OUTB 'phase control outputs
StpsPerRev CON 24 'whole steps per rev (24=180, 48-=360)
idx VAR Byte 'loop counter
stpldx VAR Nib 'step pointer
Steps DATA %0011, %0110, %1100, %1001
Setup:
DIRB=%1111 'make P4-P7 outputs
Main:
FOR idx= 1 TO StpsPerRev 'one revolution
GOSUB STEP_Fwd 'rotate clockwise
NEXT
PAUSE 1000 'wait 1 second
FOR idx = 1 TO StpsPerRev 'one revolutionGOSUB Step_Rev 'rotate counter-clockwise
NEXT
PAUSE 1000 'wait 1second
GOTO Main
END
Step_Fwd:
stpldx = stpldx+1//4 'point to next step
GOTO Do_Step
Step_Rev:
stpldx = stpldx+3//4 ' point to previous step
GOTO Do_Step
Do_Step:
READ(Steps+stpldx), Phase ' outputs new phase data
PAUSE 1000 ' delay between steps
'RECEIVE THE SIGNAL
cmconstant CON 2260
cmdistance VAR Word
time VAR Word
PULSOUT 15,5 'port 15
PULSIN 15,1,time
cmdistance=cmconstant**time
END
but not work... some can help?
Comments
' {$STAMP BS2}
' {$PBASIC 2.5}
' {$PORT COM13}
Phase VAR OUTB 'phase control outputs
StpsPerRev CON 48 'whole steps per rev
idx VAR Byte 'loop counter
stpldx VAR Nib 'step pointer
stpDelay VAR Byte 'delay for speed control
Steps DATA %0011,%0110,%1100,%1001
Setup:
DIRB = %1111 'make P4..P7 outputs
stpDelay = 15 'set step delay
Main:
FOR idx = 1 TO StpsPerRev 'one revolution
GOSUB Step_Fwd 'rotate clockwise
NEXT
PAUSE 500 'wait 1/2 second
FOR idx = 1 TO StpsPerRev 'one revolution
GOSUB Step_Rev 'rotate counter-clockwise
NEXT
PAUSE 500 'wait 1/2 second
GOTO main
END
Step_Fwd:
stpldx = stpldx + 1 // 4 'point next step
GOTO DO_Step
Step_Rev:
stpldx = stpldx + 3//4 'point to previous step
GOTO DO_Step
Do_Step:
READ(Steps+stpldx), Phase 'output new phase data
PAUSE stpDelay 'pause between step
RETURN
cmconstant CON 2260
cmdistance VAR Word
time VAR Word
DO
PULSOUT 15,5
PULSIN 15,1,time
cmdistance=cmconstant**time
DEBUG HOME,"distance1=",DEC3 cmdistance,"cm"
PAUSE 1000
LOOP
END
motor work... sensor cant show distance.... just blue
this time motor work with PING sensor... but how to make... motor will stop after PING sensor detect the object below 314cm?
my coding:
' {$STAMP BS2}
' {$PBASIC 2.0}
' {$PORT COM13}
Phase VAR OUTB
StpsPerRev CON 48
idx VAR Byte
stpldx VAR Nib
stpDelay VAR Byte
Steps DATA %0011,%0110,%1100,%1001
cmconstant CON 2260
cmdistance VAR Word
time VAR Word
Setup:
DIRB = %1111
stpDelay = 15
Main:
FOR idx = 1 TO StpsPerRev
GOSUB Step_Fwd
NEXT
PAUSE 500
FOR idx = 1 TO StpsPerRev
GOSUB Step_Rev
NEXT
PAUSE 500
GOTO main
END
Step_Fwd:
stpldx = stpldx + 1 // 4
GOTO DO_Step
Step_Rev:
stpldx = stpldx + 3 // 4
GOTO DO_Step
Do_Step:
READ(Steps+stpldx), Phase
DO
PULSOUT 15,5
PULSIN 15,1,time
cmdistance=cmconstant**time
DEBUG HOME,"Distance From Radar=",DEC3 cmdistance,"cm"
PAUSE 1000
LOOP
PAUSE stpDelay
RETURN
Please, read the description of DO / LOOP in the Manual. Try removing the DO and LOOP in the Do_Step routine.