Stuck
I have a C# app that has a trackbar on it I am trying to send the values to the propeller to update pulses, I can see the prop plug getting the data, but nothing is changing. Can I get advice on what I have so far. Thanks for all input.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
OBJ
servo : "Servo32v3"
uart : "FullDuplexSerialPlus"
CON
_clkmode = xtal1 + pll16x 'Sets clock to 16x input
_xinfreq = 5_000_000 'Sets clock to 80MHz (16x 5_000_000)
throttlePin = 18 'Sets pin to ESC on prop
VAR
long uartPulse, stack[noparse][[/noparse]100]
PUB Main | oldPulse
uart.start(31, 30, 0, 115200) 'Start FDS object for recieving data from com port
servo.set(throttlePin, 2200) 'Initializing ESC to full brake
servo.start
InitESC 'Arming Electrifly ESC as per to manual
cognew(servo.set(throttlePin, uartPulse), @stack)
''Loop constantly for a new pulse width
repeat
uartPulse := uart.rx 'Sets uartPulse to value coming in com port
'uart.StrToDec(uartPulse) 'Convert to dec
oldPulse := uartPulse 'Sets oldPulse to uartPulse for comparison
if uartPulse <> oldPulse 'If uartPulse changes for set for new pulse
servo.set(throttlePin, uartPulse)
if uartPulse == oldPulse 'If values dont change throttle stays the same
servo.set(throttlePin, oldPulse)
PUB RecieveData | throttle
''To be coded
PRI InitESC
servo.set(throttlePin, 2200) 'ESC full throttle
pause(5000)
servo.set(throttlePin, 1000) 'ESC full brake
pause(2000)
servo.set(throttlePin, 2200) 'ESC full throttle
pause(2000)
servo.set(throttlePin, 1000) 'ESC full brake
'pause(400)
PRI pause(ms)
waitcnt((clkfreq / 1000 * mS) + cnt)
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔

Comments
Use this:
PUB pauseForSeconds(value) '' ┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐ '' │ Pauses execution for any number of seconds. │ '' └───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ pauseForMilliseconds(value * 1000) PUB pauseForMilliseconds(value) : buffer '' ┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐ '' │ Pauses execution for any number of milliseconds. │ '' └───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ buffer := cnt repeat (value #> 0) buffer += (clkfreq / 1000) waitcnt(buffer)·Also, is that microseconds or milliseconds? Because you used a value of over 1000 which would pause the chip over a second with your setup.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nyamekye,
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nyamekye,
OBJ servo : "Servo32v3" uart : "FullDuplexSerialPlus" CON _clkmode = xtal1 + pll16x 'Sets clock to 16x input _xinfreq = 5_000_000 'Sets clock to 80MHz (16x 5_000_000) throttlePin = 18 'Sets pin to ESC on prop VAR long uartPulse, stack[noparse][[/noparse]100] PUB Main | oldPulse uart.start(31, 30, 0, 115200) 'Start FDS object for recieving data from com port servo.set(throttlePin, 2200) 'Initializing ESC to full brake servo.start InitESC 'Arming Electrifly ESC as per to manual ''Loop constantly for a new pulse width repeat uartPulse := uart.rx 'Sets uartPulse to value coming in com port 'uart.StrToDec(uartPulse) 'Convert to dec oldPulse := uartPulse 'Sets oldPulse to uartPulse for comparison if uartPulse <> oldPulse 'If uartPulse changes for set for new pulse servo.set(throttlePin, uartPulse) if uartPulse == oldPulse 'If values dont change throttle stays the same servo.set(throttlePin, oldPulse) PUB RecieveData | throttle ''To be coded PRI InitESC servo.set(throttlePin, 2200) 'ESC full throttle pauseForSeconds(5) servo.set(throttlePin, 1000) 'ESC full brake pauseForSeconds(2) servo.set(throttlePin, 2200) 'ESC full throttle pauseForSeconds(2) servo.set(throttlePin, 1000) 'ESC full brake PRI pauseForSeconds(value) pauseForMilliseconds(value * 1000) PRI pauseForMilliseconds(value) | buffer buffer := cnt repeat (value #> 0) buffer += (clkfreq / 1000) waitcnt(buffer)The values that are being sent from the trackerbar on my c# app serially are between 1000 and 2200.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Um, I'll just give you my whole library for pause rountines and string to integer conversion and vice versa. It should help get arround that problem for you by doing the conversions necessary. To transfer a string through serial and then convert it back to a number and etc.
Note, that you should not·use it to read directly from the serial buffers of the full duplex object but instead put the bytes received by that object into a local array and then call the conversion on the local array.
Also note that strings need to be terminated with zero you will have problems.
For debugging just test the device with some hard coded calues to se if it is sending and·receiving data propellerly.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nyamekye,
OBJ servo : "Servo32v3" uart : "FullDuplexSerialPlus" conv : "libraryEngine" CON _clkmode = xtal1 + pll16x 'Sets clock to 16x input _xinfreq = 5_000_000 'Sets clock to 80MHz (16x 5_000_000) throttlePin = 18 'Sets pin to ESC on prop VAR long uartPulse, inBuffer[noparse][[/noparse]4] PUB Main | oldPulse uart.start(31, 30, 0, 115200) 'Start FDS object for recieving data from com port servo.set(throttlePin, 2200) 'Initializing ESC to full brake servo.start InitESC 'Arming Electrifly ESC as per to manual ''Loop constantly for a new pulse width repeat inBuffer := uart.rx 'Sets uartPulse to value coming in com port uartPulse := conv.decimalToNumber(inBuffer) 'Convert to dec oldPulse := uartPulse 'Sets oldPulse to uartPulse for comparison if uartPulse <> oldPulse 'If uartPulse changes for set for new pulse servo.set(throttlePin, uartPulse) if uartPulse == oldPulse 'If values dont change throttle stays the same servo.set(throttlePin, oldPulse) PUB RecieveData | throttle ''To be coded PRI InitESC servo.set(throttlePin, 2200) 'ESC full throttle pauseForSeconds(5) servo.set(throttlePin, 1000) 'ESC full brake pauseForSeconds(2) servo.set(throttlePin, 2200) 'ESC full throttle pauseForSeconds(2) servo.set(throttlePin, 1000) 'ESC full brake PRI pauseForSeconds(value) pauseForMilliseconds(value * 1000) PRI pauseForMilliseconds(value) | buffer buffer := cnt repeat (value #> 0) buffer += (clkfreq / 1000) waitcnt(buffer)▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
As I mentioned before, the serial data object works in bytes only. If you want a value greater than 255 you should send the data as a string first.
As in form "1005" send "1", "0" "0" "5", 0 - notice the null terminating the string, very important or the library will run on forever converting stuff.
Then you would read all those bytes into a byte sized array in the main memory, and then call the converting function on the array (pass the address of the first element of the array), and the function will then return the value in decimal form.
Notice that in your code you only get one byte from the receiver (you need to get all the bytes in it before you can make the conversion). And remeber the null terminating zero at the end of the string.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nyamekye,
The sThrottle is a string. But I have also tried passing it like this
[color=#008000][color=#008000]serialPort1.Write(bThrottle, 0, 4);[/color][/color] [color=#008000][color=#008000]serialPort1.Write(new byte[noparse][[/noparse]] {0}, 0, 1); [/color][/color]·The bThrottle is an byte array
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nyamekye,
OBJ servo : "Servo32v3" uart : "FullDuplexSerialPlus" conv : "libraryEngine" CON _clkmode = xtal1 + pll16x 'Sets clock to 16x input _xinfreq = 5_000_000 'Sets clock to 80MHz (16x 5_000_000) throttlePin = 4 'Sets pin to ESC on prop VAR long uartPulse', inBuffer[noparse][[/noparse]5] byte inBuffer[noparse][[/noparse]5] PUB Main | oldPulse uart.start(31, 30, 0, 115200) 'Start FDS object for recieving data from com port servo.set(throttlePin, 2200) 'Initializing ESC to full brake servo.start InitESC 'Arming Electrifly ESC as per to manual repeat inbuffer := uart.rx uartPulse := conv.decimalToNumber(@inbuffer[noparse][[/noparse]0]) oldPulse := uartPulse if uartPulse <> oldPulse servo.set(throttlePin, uartPulse) else servo.set(throttlePin, oldPulse) PUB RecieveData | throttle ''To be coded PRI InitESC servo.set(throttlePin, 2200) 'ESC full throttle pauseForSeconds(5) servo.set(throttlePin, 1000) 'ESC full brake pauseForSeconds(2) servo.set(throttlePin, 2200) 'ESC full throttle pauseForSeconds(2) servo.set(throttlePin, 1000) 'ESC full brake PRI pauseForSeconds(value) pauseForMilliseconds(value * 1000) PRI pauseForMilliseconds(value) | buffer buffer := cnt repeat (value #> 0) buffer += (clkfreq / 1000) waitcnt(buffer)▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
So... Use this...
OBJ servo : "Servo32v3" uart : "FullDuplexSerialPlus" conv : "libraryEngine" CON _clkmode = xtal1 + pll16x 'Sets clock to 16x input _xinfreq = 5_000_000 'Sets clock to 80MHz (16x 5_000_000) throttlePin = 4 'Sets pin to ESC on prop VAR long uartPulse byte inBuffer[noparse][[/noparse]11] PUB Main | oldPulse, index uart.start(31, 30, 0, 115200) 'Start FDS object for recieving data from port servo.set(throttlePin, 2200) 'Initializing ESC to full brake servo.start InitESC 'Arming Electrifly ESC as per to manual repeat repeat index from 0 to 4 inbuffer[noparse][[/noparse]index] := uart.rx uartPulse := conv.decimalToNumber(@inbuffer[noparse][[/noparse]0]) if(uartPulse <> oldPulse) servo.set(throttlePin, uartPulse) else servo.set(throttlePin, oldPulse) oldPulse := uartPulse PRI InitESC servo.set(throttlePin, 2200) 'ESC full throttle conv.pauseForSeconds(5) servo.set(throttlePin, 1000) 'ESC full brake conv.pauseForSeconds(2) servo.set(throttlePin, 2200) 'ESC full throttle conv.pauseForSeconds(2) servo.set(throttlePin, 1000) 'ESC full brakeAnd, I really don't know if this will work but it should put you in the right direction. Note, that the number to be sent to the propeller chip needs to be sent with its leading digit first, as in "1" "2"·"3" "4", the zero does not need to follow it as this code has plenty of extra space in its buffer for a zeros (because the vars are cleared to zero on startup).
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nyamekye,
Post Edited (Kye) : 3/1/2009 3:10:03 AM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
inbuffer := uart.rx uartPulse := conv.decimalToNumber(@inbuffer) 'uart.GetStr(@inbuffer) 'pulse := uart.StrToDec(uartPulse) oldPulse := uartPulse 'pulseif uartPulse <> oldPulse servo.set(throttlePin, uartPulse)else servo.set(throttlePin, oldPulse)▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Post Edited (bboy8012) : 3/1/2009 5:59:55 AM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nyamekye,
OBJ servo : "Servo32v3" uart : "Extended_FDSerial" text : "tv_text" conv : "libraryEngine" CON _clkmode = xtal1 + pll16x 'Sets clock to 16x input _xinfreq = 5_000_000 'Sets clock to 80MHz (16x 5_000_000) throttlePin = 4 'Sets pin to ESC on prop VAR long uartPulse, pulse byte inBuffer[noparse][[/noparse]20] PUB Main | oldPulse, index uart.start(31, 30, 0, 115200) 'Start FDS object for recieving data from com port servo.set(throttlePin, 2200) 'Initializing ESC to full brake servo.start text.start(12) conv.pauseForSeconds(2) text.str(String("Starting ESC intialization", 13)) 'InitESC 'Arming Electrifly ESC as per to manual text.str(String("ESC intialization complete", 13)) conv.pauseForSeconds(1) text.str(String("Begin Loop", 13)) repeat 'inbuffer := uart.RxCheck 'if inBuffer <> -1 repeat index from 0 to 3 inBuffer[noparse][[/noparse]index] := uart.rx uartPulse := conv.DecimalToNumber(@inBuffer[noparse][[/noparse]0]) text.Str(uartPulse) text.Out(13)Now time to figure out how to get the results i want. I will post final code with c# code for others
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
If you have turned off the ability to see the little pipe arrows that tell you what an if or repeat statment is linked to I suggest you turn it back on.
I say that because you call the convert to decimal function multiple times instead of once in the code posted due to the way the compiler includes things in loops spacing.
The formating of the code I posted above is critical.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nyamekye,
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The output from you c# program is wrong. For "2200" you should send the lieral ACSII characters '2' '2' '0' '0' or in decimal 50, 50, 48, 48.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nyamekye,
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nyamekye,