Rotary encoder and Basic Stamp 1.
Happytriger2000
Posts: 14
Hi everyone,
················ Im currently doing a project related to motion control, and the task is to read the quadrature signal output of a rotary encoder's channel A and channel B and feed into Basic Stamp 1 then output to a stepper motor. Can anyone give some tips to start with?
Freddy
················ Im currently doing a project related to motion control, and the task is to read the quadrature signal output of a rotary encoder's channel A and channel B and feed into Basic Stamp 1 then output to a stepper motor. Can anyone give some tips to start with?
Freddy
Comments
http://www.parallax.com/dl/docs/cols/nv/vol1/col/nv8.pdf
SJW
························ Thanks for the links. The Spin-and-Grin project use a rotary encoder and a LCD, may I know which part of the program of LCD need to be changed to fit the steeper motor?.
Im a begginner in Basic Stamp.
Freddy
1. Follow the rotory encoder step by step????
2. Speed motor up and down????
3. What kind of stepper motor do you have???? Bipolar or Unipolar????
Parallax App. note No. 6. describes how to use a BS1 and bi-polar stepper motor.
http://www.parallax.com/dl/appnt/stamps/bs1Appnotes.pdf
You will need a current amplifier/driver·for both.
SJW
·
Parallax App. note No. 6. describes how to use a BS1 and bi-polar BIPOLAR stepper motor.
http://www.parallax.com/dl/appnt/stamps/bs1Appnotes.pdf
http://www.parallax.com/dl/appnt/stamps/bs1Appnotes.pdf
···························· Sorry for the late reply.
Yes, I want the stepper motor to follow the rotary encoder step by step, or the same speed as the encoder.
Im using a rotary encoder of 500 p/r and a 1.8degree/step 6 wires stepper motor and as for the stepper driver it accepts Step and Dir. I know how to send the signal pulse to the stepper driver but dont know how to receive signal from the encoder.
Freddy
So, in a loop, check if A is hi. If it is, check B. If hi, add one to a counter, if low subtract one.
IF A = 1 THEN
IF B = 1 THEN
Cntr = Cntr+1
ELSE
Cntr = Cntr-1
ENDIF
ENDIF
So, in a loop, check if A is hi. If it is, check B. If hi, add one to a counter, if low subtract one.
Something like:
IF A = 1 THEN
IF B = 1 THEN
Cntr = Cntr+1
ELSE
Cntr = Cntr-1
ENDIF
ENDIF
old VAR Nib
new VAR Nib
ob VAR old.BIT0
nb VAR new.BIT1
cnt VAR Word
HIGH 14 'set driver direction pin
Start:
decode:
old=INC & 3 'get encoder state on pins 8 and 9
new=INC & 3
IF new=old THEN decode 'loop if no change
cnt=(ob^nb)*2-1+cnt ' calculate motion
IF (ob^nb)*2-1=-1 THEN LOW 14 'if reverse set driver pin to counter c/w
PULSOUT 15,25 'pulse motor driver pin 15
old=new
GOTO Start
I only have Basic Stamp 1 module, so the program has to be compatible with BS1.
The program below by SDY, is it a complete program? Because for If..then command, usually after·'THEN' there should be something else, isnt it?, for example, 'If A = 1 Then cw'.
IF A = 1 THEN
IF B = 1 THEN
Cntr = Cntr+1
ELSE
Cntr = Cntr-1
ENDIF
ENDIF
Currently Im experimenting the program to run the stepper motor by using a switch, I wrote:
check:
If pin·3 = high then cw ( a switch connected to pin 3·with 5v input to give a 'high')
if pin 4 = high the ccw ( a switch connected to pin 4· with 5v input to give a 'high')
goto check
cw:
···· Pulsout 1,200 (step signal to Driver board)
···· high 0·········· ( a low signal to DIR)
goto check
ccw:
······ pulsout 1,200
······
·······high 1
goto check
OK, is there anything wrong with the program I wrote above?
Freddy
Im presuming that as the logic is AND'ed that that is the way to type it rather than the statement
IF·a·AND b=1 THEN
or
IF a=1 AND b=1 THEN
which i would have thought would save eeprom space( or is this interpreted by the basic editor either way·and still uses use the same coding space whichever you choose?)
could this also be typed as
if a,b=1 then· or something similar say IF(a,b)=1
for the·other direction
that would type as
If A=1·AND b=0 THEN
is this a correct assumption?
Is there only one way of typing it then?
Post Edited (skylight) : 10/2/2007 6:52:22 AM GMT
You might do well to download a copy of the PBASIC Reference Manual, which can be downloaded for free from the Parallax web site. That contains all of the syntax and usage rules for the PBASIC language.
There are two constructs for IF ... THEN one of which is single-line and the other is multi-line. Each has its uses and as far as I'm aware, both generate the same amount of p-code.
As far as using connectives (AND, OR, etc) you must specify both conditions completely. In other words, the only proper way to check to see if two given variables are one and three respectively·is as follows:
IF variable1 = 1 AND variable2 = 3 ...
There are two ways to check if two variables are equal to the same value:
IF variable1 = 1 and variable2 = 1 ...
or
IF variable1 =1 and variable2 = variable1 ...
There is nothing implied in the IF ... THEN syntax, all parameters must be specified.
All of this information is also available in the PBASIC Help File which is accessible from the PBASIC IDE or separately if you have it set up that way.
Regards,
Bruce Bates
Post Edited (Bruce Bates) : 10/2/2007 8:19:32 AM GMT
Can I use Pulsin to measure the pulse output of the Encoder? If yes, can anyone provide a sample program?
Freedy