Shop OBEX P1 Docs P2 Docs Learn Events
Stuck — Parallax Forums

Stuck

bboy8012bboy8012 Posts: 153
edited 2009-03-06 05:11 in Propeller 1
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

  • KyeKye Posts: 2,200
    edited 2009-02-26 06:04
    Your pause routnine looks problematic.

    Use this:

    PUB pauseForSeconds(value)
     
    '' &#9484;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9488;
    '' &#9474; Pauses execution for any number of seconds.                                                                               &#9474;
    '' &#9492;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9496;
     
      pauseForMilliseconds(value * 1000)
     
    PUB pauseForMilliseconds(value) : buffer 
     
    '' &#9484;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9488;
    '' &#9474; Pauses execution for any number of milliseconds.                                                                          &#9474;
    '' &#9492;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9496; 
     
      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,
  • Mike GreenMike Green Posts: 23,101
    edited 2009-02-26 06:06
    You cannot start a new cog using a method in another object. In other words, "cognew(servo.set(throttlePin,uartPulse),@stack)" won't work. In your particular case, the servo object will already take care of sending servo pulses until you change the value involved. In other words, when you do a servo.start, the servo object starts up a new cog that handles all the servos that you've initialized. It will continuously issue control pulses about every 20ms using the last known value of the pulse width. If you call servo.set, this changes the pulse width on the next cycle. You don't need to do the cognew.
  • bboy8012bboy8012 Posts: 153
    edited 2009-02-26 16:25
    Thanks kye for the pause tips, i modified that part, also I removed the congnew call but still nothing. Should I be sedning the data from my c# app in bytes, are is sending the numbers as a string fine?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • KyeKye Posts: 2,200
    edited 2009-02-26 20:23
    Post your new code please.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nyamekye,
  • bboy8012bboy8012 Posts: 153
    edited 2009-02-27 02:49
    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.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • KyeKye Posts: 2,200
    edited 2009-02-27 04:02
    Okay, well do you know that the serial object transfers bytes at a time? That said, I can't see how you would get a value of more than 255 from it.

    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,
  • bboy8012bboy8012 Posts: 153
    edited 2009-02-27 04:45
    Updated code, it works almost. when I have the trackbar say at 1500 gives a reading of 2000. Its either 1ms or 2ms even when I have the the trackbar at all the way up to the max value of 2200.
    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)
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • KyeKye Posts: 2,200
    edited 2009-02-27 15:01
    Okay, how are you sending data to and from the propeller chip?

    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,
  • bboy8012bboy8012 Posts: 153
    edited 2009-02-28 22:24
    Im passing the data to the stamp using C# like this
    serialPort1.Write(sThrottle);
    serialPort1.Write([color=#a31515][color=#a31515]"0"[/color][/color]);
    
    

    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

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • KyeKye Posts: 2,200
    edited 2009-02-28 23:20
    Then you should be fine, look at your spin code however, I think you aren't getting the data into the array properly.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nyamekye,
  • bboy8012bboy8012 Posts: 153
    edited 2009-02-28 23:54
    Yea thats what I am trying to figure out how to do. I have been researching the manual, and looking at other code, but I kinda need to be shown and explained to how to do it, so I can learn from my mistakes. updated code
    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)
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • KyeKye Posts: 2,200
    edited 2009-03-01 02:54
    You do you that the pause routines can be also found in the library. so they do not need to be included into the code.
    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 brake
    
    

    And, 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
  • bboy8012bboy8012 Posts: 153
    edited 2009-03-01 03:05
    I corrected that, I just have been focusing on the get data correctly from fullduplexserial

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • bboy8012bboy8012 Posts: 153
    edited 2009-03-01 05:44
    Ok I am stuck can any one show me some spin code to get the string or bytes from FullDuplexSerial? I verified my C# app is sending zero terminated stings, for string "1034" I get 10340 with bytes of 0A-04-00-00-00. i know I am not getting the values correctly, and I have looked over the manual, and also the PE labs Objects. Here is the pertinant code:
    VAR
    

    long uartPulse, pulse, inBuffer[noparse][[/noparse]5]
      'byte inBuffer[noparse][[/noparse]5]
    

    repeat
    

        inbuffer := uart.rx
        uartPulse := conv.decimalToNumber(@inbuffer) 'uart.GetStr(@inbuffer)
        'pulse := uart.StrToDec(uartPulse)
        oldPulse := uartPulse 'pulse
    

        if uartPulse <> oldPulse
          servo.set(throttlePin, uartPulse)
    

        else
          servo.set(throttlePin, oldPulse)
    



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


    Post Edited (bboy8012) : 3/1/2009 5:59:55 AM GMT
  • Mike GreenMike Green Posts: 23,101
    edited 2009-03-01 06:17
    FullDuplexSerial reads one character at a time. If you want to handle zero-terminated strings on input, look at the Extended FullDuplexSerial object from the Object Exchange. This calls FullDuplexSerial to get the individual characters and combines them to provide zero-terminated strings or decimal values. Have a look at it and the included sample code.
  • KyeKye Posts: 2,200
    edited 2009-03-01 18:09
    Um, look at the code I posted... It shows you how to do that, use it and see what happens.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nyamekye,
  • bboy8012bboy8012 Posts: 153
    edited 2009-03-02 04:29
    The code worked, but not get results I want funny characters. but atleast I know there getting printed to the tv. You code was a big help kye thanks
    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

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • KyeKye Posts: 2,200
    edited 2009-03-02 05:22
    Um, from your code you seem to have the formatting all wrong... You do understand that the if statements and repeat loops and such define their internal statments as everything to the right underneath them.

    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,
  • bboy8012bboy8012 Posts: 153
    edited 2009-03-03 02:18
    Sorry that was a typo as I was editing. I have a question does the prop recieve bytes. The way I am sending them in C# is byte form 98-08-00-00-00 for 2200. Should I be sending them as characters. Still not getting the desired results

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • KyeKye Posts: 2,200
    edited 2009-03-03 05:06
    Send them as characters, thats what the library converts. Anything that is not in the set of {0..9} is treated as zero when added into the final converted value.

    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,
  • bboy8012bboy8012 Posts: 153
    edited 2009-03-06 03:27
    Here is the working C# App to prop communitcaions. Thanks to kye and all others that helped me on this. This is only a basis to control a brushless motor through an ESC.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • KyeKye Posts: 2,200
    edited 2009-03-06 05:11
    Cool, glad I could help.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nyamekye,
Sign In or Register to comment.