Okay, I don't see the error here -- it is probably obvious too
TinkersALot
Posts: 535
I'm trying to drive a Parallax servo controller, and I've·cobbled this short bit of code together for that. Nothing happens on the servos (no movement). I see bits going by with an oscilloscope, so think the physical layer is alright. What have I done wrong?
Thanks to anyone that can help me see the (what has got to be an obvious) thing I am missing.
{{
}}
CON
· PIN_DEF_FOR_SERVO_CONTROL···· = 0
· HEAD_SENSOR_SERVO_PORT······· = 0
· HEAD_SENSOR_SERVER_STARBOARD· = 2
·
· IDX_SENSOR_SERVO_PORT········ = 0
· IDX_SENSOR_SERVER_STARBOARD·· = 1
· CENTER······················· = 750
· MAX_VALUE···················· = 1250
· MIN_VALUE···················· = 250
· MINIMUM_COUNT················ = 400····· ' Minimum waitcnt value to prevent lock-up
· STEP_SIZE···················· = 50
················································································
var
· Word SensorHeadPosition[noparse][[/noparse] 2 ]
· long MicroSeconds
··
PRI DoMotorCommand( WhichMotorPin, MoveTo )
· SendString ( PIN_DEF_FOR_SERVO_CONTROL, string( "!SC" ),············ 2400, 1, 8 )
· SendCharacter( PIN_DEF_FOR_SERVO_CONTROL, $000000FF & WhichMotorPin, 2400, 1, 8 ) ' channel
· SendCharacter( PIN_DEF_FOR_SERVO_CONTROL, $00,······················ 2400, 1, 8 ) ' ramp-rate
· SendCharacter( PIN_DEF_FOR_SERVO_CONTROL, $000000FF & MoveTo,······· 2400, 1, 8 ) ' position
· SendCharacter( PIN_DEF_FOR_SERVO_CONTROL, $0000FF00 & MoveTo,······· 2400, 1, 8 ) ' position
· SendCharacter( PIN_DEF_FOR_SERVO_CONTROL, $0D,······················ 2400, 1, 8 )
· PauseWait( 1000 )
PRI PauseWait( Duration ) | clkCycles
{{
·· Causes a pause for the duration in uS
·· Smallest value is 20 at clkfreq = 80Mhz
·· Largest value is around 50 seconds at 80Mhz.
···· BS2.Pause_uS(1000)·· ' 1 mS pause
}}
· clkCycles := Duration * MicroSeconds #> MINIMUM_COUNT·· ' duration * clk cycles for us
························································· ' - inst. time, min cntMin
· waitcnt(clkcycles + cnt)······························· ' wait until clk gets there····························
···
PRI SendCharacter( Pin, char, Baud, Mode, Bits ) | x, BR
{{
· Send asynchronous character (byte) on defined pin, at Baud, in Mode for #bits
· Mode: 0 = Inverted - Normally low······· Constant: BS2#Inv
······· 1 = Non-Inverted - Normally High·· Constant: BS2#NInv
··· BS2.Serout_Char(5,"A",9600,BS2#NInv,8)
}}
· BR·· := 1_000_000 / (Baud)························ ' Determine Baud rate
· char := ((1 << Bits ) + char) << 2················ ' Set up string with start & stop bit
· dira[noparse][[/noparse]pin]~~······································· ' set as output
· if MODE == 0······································ ' If mode 0, invert
··· char:= !char
···
· PauseWait(BR * 2 )································· ' Hold for 2 bits
· repeat x From 1 to ( Bits + 2 )···················· ' Send each bit based on baud rate
··· char := char >> 1
··· outa[noparse][[/noparse]Pin] := char
··· PauseWait( BR - 65 )
PRI SendDecimal(Pin, Value, Baud, Mode, Bits) | i
{{
· Send asynchronous decimal value (-1234) on defined pin, at Baud, in Mode for #bits/Char
· Mode: 0 = Inverted - Normally low······· Constant: BS2#Inv
······· 1 = Non-Inverted - Normally High·· Constant: BS2#NInv
··· BS2.SEROUT_dec(5,-1234,9600,1,8)·· ' Tx -1234
··· BS2.SEROUT_Char(5,13,9600,1,8)···· ' CR to end
}}
'' Print a decimal number
· if value < 0············································ ' Send - sign if < 0··············
··· -value···················································································
··· SendCharacter( Pin, "-", Baud, Mode, Bits )···················································
·····························································································
· i := 1_000_000_000·········································································
·····························································································
· repeat 10·················································· ' test each 10's place············
··· if value => i············································ ' send character based on ASCII 0·
····· SendCharacter( Pin, value / i + "0", Baud, Mode, Bits ) ' Take modulus of i···············
····· value //= i············································································
····· result~~···············································································
··· elseif result or i == 1··································································
····· SendCharacter( Pin, "0", Baud, Mode, Bits )············ ' Divide i for next place·········
··· i /= 10··························································································
PRI SendString( Pin, stringptr, Baud, Mode, bits )
{{
· Sends a string for serout
··· BS2.Serout_Str(5,string("Spin-Up World!",13),9600,1,8)
··· BS2.Serout_Str(5,@myStr,9600,1,8)
····· Code adapted from "FullDuplexSerial"
}}
· repeat strsize( stringptr )
··· SendCharacter( Pin,byte[noparse][[/noparse] stringptr++ ], Baud, Mode, bits )· ' Send each character in string
·
Thanks to anyone that can help me see the (what has got to be an obvious) thing I am missing.
{{
}}
CON
· PIN_DEF_FOR_SERVO_CONTROL···· = 0
· HEAD_SENSOR_SERVO_PORT······· = 0
· HEAD_SENSOR_SERVER_STARBOARD· = 2
·
· IDX_SENSOR_SERVO_PORT········ = 0
· IDX_SENSOR_SERVER_STARBOARD·· = 1
· CENTER······················· = 750
· MAX_VALUE···················· = 1250
· MIN_VALUE···················· = 250
· MINIMUM_COUNT················ = 400····· ' Minimum waitcnt value to prevent lock-up
· STEP_SIZE···················· = 50
················································································
var
· Word SensorHeadPosition[noparse][[/noparse] 2 ]
· long MicroSeconds
··
PRI DoMotorCommand( WhichMotorPin, MoveTo )
· SendString ( PIN_DEF_FOR_SERVO_CONTROL, string( "!SC" ),············ 2400, 1, 8 )
· SendCharacter( PIN_DEF_FOR_SERVO_CONTROL, $000000FF & WhichMotorPin, 2400, 1, 8 ) ' channel
· SendCharacter( PIN_DEF_FOR_SERVO_CONTROL, $00,······················ 2400, 1, 8 ) ' ramp-rate
· SendCharacter( PIN_DEF_FOR_SERVO_CONTROL, $000000FF & MoveTo,······· 2400, 1, 8 ) ' position
· SendCharacter( PIN_DEF_FOR_SERVO_CONTROL, $0000FF00 & MoveTo,······· 2400, 1, 8 ) ' position
· SendCharacter( PIN_DEF_FOR_SERVO_CONTROL, $0D,······················ 2400, 1, 8 )
· PauseWait( 1000 )
PRI PauseWait( Duration ) | clkCycles
{{
·· Causes a pause for the duration in uS
·· Smallest value is 20 at clkfreq = 80Mhz
·· Largest value is around 50 seconds at 80Mhz.
···· BS2.Pause_uS(1000)·· ' 1 mS pause
}}
· clkCycles := Duration * MicroSeconds #> MINIMUM_COUNT·· ' duration * clk cycles for us
························································· ' - inst. time, min cntMin
· waitcnt(clkcycles + cnt)······························· ' wait until clk gets there····························
···
PRI SendCharacter( Pin, char, Baud, Mode, Bits ) | x, BR
{{
· Send asynchronous character (byte) on defined pin, at Baud, in Mode for #bits
· Mode: 0 = Inverted - Normally low······· Constant: BS2#Inv
······· 1 = Non-Inverted - Normally High·· Constant: BS2#NInv
··· BS2.Serout_Char(5,"A",9600,BS2#NInv,8)
}}
· BR·· := 1_000_000 / (Baud)························ ' Determine Baud rate
· char := ((1 << Bits ) + char) << 2················ ' Set up string with start & stop bit
· dira[noparse][[/noparse]pin]~~······································· ' set as output
· if MODE == 0······································ ' If mode 0, invert
··· char:= !char
···
· PauseWait(BR * 2 )································· ' Hold for 2 bits
· repeat x From 1 to ( Bits + 2 )···················· ' Send each bit based on baud rate
··· char := char >> 1
··· outa[noparse][[/noparse]Pin] := char
··· PauseWait( BR - 65 )
PRI SendDecimal(Pin, Value, Baud, Mode, Bits) | i
{{
· Send asynchronous decimal value (-1234) on defined pin, at Baud, in Mode for #bits/Char
· Mode: 0 = Inverted - Normally low······· Constant: BS2#Inv
······· 1 = Non-Inverted - Normally High·· Constant: BS2#NInv
··· BS2.SEROUT_dec(5,-1234,9600,1,8)·· ' Tx -1234
··· BS2.SEROUT_Char(5,13,9600,1,8)···· ' CR to end
}}
'' Print a decimal number
· if value < 0············································ ' Send - sign if < 0··············
··· -value···················································································
··· SendCharacter( Pin, "-", Baud, Mode, Bits )···················································
·····························································································
· i := 1_000_000_000·········································································
·····························································································
· repeat 10·················································· ' test each 10's place············
··· if value => i············································ ' send character based on ASCII 0·
····· SendCharacter( Pin, value / i + "0", Baud, Mode, Bits ) ' Take modulus of i···············
····· value //= i············································································
····· result~~···············································································
··· elseif result or i == 1··································································
····· SendCharacter( Pin, "0", Baud, Mode, Bits )············ ' Divide i for next place·········
··· i /= 10··························································································
PRI SendString( Pin, stringptr, Baud, Mode, bits )
{{
· Sends a string for serout
··· BS2.Serout_Str(5,string("Spin-Up World!",13),9600,1,8)
··· BS2.Serout_Str(5,@myStr,9600,1,8)
····· Code adapted from "FullDuplexSerial"
}}
· repeat strsize( stringptr )
··· SendCharacter( Pin,byte[noparse][[/noparse] stringptr++ ], Baud, Mode, bits )· ' Send each character in string
·
Comments