wheel encoder
B.ASHISH
Posts: 28
This is my wheel encoder code in Spin language to display the readings of the Left and Right wheels of the Stingray Robot of Parallax with Propeller Microcontroller .But I'm receiving only zeros for both the wheels.Please suggest me the correct code for me to get the count value of the wheel encoders for both the wheels.
[CODE/]
CON
_CLKMODE = XTAL1 + PLL16X
_XINFREQ = 5_000_000
clock = 80_000_000
ms1= clock/1_000
XBEE_RX = 16
XBEE_TX = 17
XBEE_Baud =115200
OBJ
sr :"SRMotorcontrol"
CTR :"MyEncoder"
XB :"FullDuplexSerial"
'pst:"Parallax Serial Terminal"
PUB main |RCount,LCount
sr.Start
CTR.Start
XB.Start(XBEE_RX,XBEE_TX,%0000,XBEE_Baud)
'pst.Start(115200)
CTR.Start
sr.SetRamp(10)
repeat
sr.MoveForward(30)
waitcnt(clkfreq+cnt)
RCount:=RCount-CTR.RCount
LCount:=LCount-CTR.LCount
XB.Dec(RCount)
'pst.Dec(RCount)
XB.tx(9)
'pst.NewLine
XB.Dec(LCount)
'pst.Dec(LCount)
XB.tx(13)
'pst.NewLine
[/code]
[CODE/] for "MY ENCODER"
CON
_CLKMODE = XTAL1 + PLL16X
_XINFREQ = 5_000_000
'===========< IO Pin assignments >==========
EncdrLA = 16 'Left Wheel Encoder Phase A
EncdrLB = 19 'Left Wheel Encoder Phase B
EncdrRA = 2 'Right Wheel Encoder Phase A
EncdrRB = 3 'Right Wheel Encoder Phase B
Mask = |<EncdrLA + |<EncdrLB + |<EncdrRA + |<EncdrRB
'========< Counter mode values >=========
ModeNegEdge = %01110 << 26 'Negative Edge Detector for wheel encoders
ModeNCO = %00100 << 26 'Bit 31 overflow goes to pin for servo drives
PUB Start
' Left wheel counter
Frqa := 1
Phsa := 0
Ctra := ModeNegEdge + EncdrLA
' Right Wheel counter
Frqb := 1
Phsb := 0
Ctrb := ModeNegEdge + EncdrRA
PUB CZero
Phsa := 0
Phsb := 0
PUB RCount
return Phsb
PUB LCount
Return Ctrb
[/code]
[CODE/]
CON
_CLKMODE = XTAL1 + PLL16X
_XINFREQ = 5_000_000
clock = 80_000_000
ms1= clock/1_000
XBEE_RX = 16
XBEE_TX = 17
XBEE_Baud =115200
OBJ
sr :"SRMotorcontrol"
CTR :"MyEncoder"
XB :"FullDuplexSerial"
'pst:"Parallax Serial Terminal"
PUB main |RCount,LCount
sr.Start
CTR.Start
XB.Start(XBEE_RX,XBEE_TX,%0000,XBEE_Baud)
'pst.Start(115200)
CTR.Start
sr.SetRamp(10)
repeat
sr.MoveForward(30)
waitcnt(clkfreq+cnt)
RCount:=RCount-CTR.RCount
LCount:=LCount-CTR.LCount
XB.Dec(RCount)
'pst.Dec(RCount)
XB.tx(9)
'pst.NewLine
XB.Dec(LCount)
'pst.Dec(LCount)
XB.tx(13)
'pst.NewLine
[/code]
[CODE/] for "MY ENCODER"
CON
_CLKMODE = XTAL1 + PLL16X
_XINFREQ = 5_000_000
'===========< IO Pin assignments >==========
EncdrLA = 16 'Left Wheel Encoder Phase A
EncdrLB = 19 'Left Wheel Encoder Phase B
EncdrRA = 2 'Right Wheel Encoder Phase A
EncdrRB = 3 'Right Wheel Encoder Phase B
Mask = |<EncdrLA + |<EncdrLB + |<EncdrRA + |<EncdrRB
'========< Counter mode values >=========
ModeNegEdge = %01110 << 26 'Negative Edge Detector for wheel encoders
ModeNCO = %00100 << 26 'Bit 31 overflow goes to pin for servo drives
PUB Start
' Left wheel counter
Frqa := 1
Phsa := 0
Ctra := ModeNegEdge + EncdrLA
' Right Wheel counter
Frqb := 1
Phsb := 0
Ctrb := ModeNegEdge + EncdrRA
PUB CZero
Phsa := 0
Phsb := 0
PUB RCount
return Phsb
PUB LCount
Return Ctrb
[/code]
Comments
-Phil
- How do you have the encoders connected to the Stringray?
- What Propeller board are you using? Is it an MRS1 that came with the original full kit?
If you search for Stingray in the robotics forum you will turn up some examples of people using encoders with the robot and example code. Most people are using pins 8,9,10,11 for the encoders.
http://forums.parallax.com/showthrea...ingray+encoder
Robert
The values displayed in the Parallax Serial Terminal for the Left and right wheels are somewhat like
RIGHT LEFT
24678 254367
32145 349766
33679 32146
45673 46789
and so on ,and the values continue in this manner as long as the wheels rotate.
Sir ,can you please tell us exactly what these Count values exactly are,so that we can proceed further.