Shop OBEX P1 Docs P2 Docs Learn Events
Trying to send serial to speed controller — Parallax Forums

Trying to send serial to speed controller

stuartXstuartX Posts: 88
edited 2013-12-16 22:21 in Propeller 1
I'm new to propeller so I'm not too sure about my code.
I have a speed controller that is RS-232. I'm trying to send ASCII code "!G,2,71" to the speed controller to test.
I have a simple program loop that I thought would work. But I'm not sure of is how to do so with my code.
I'm output at pin 0. with a speed of 115200.
I tried to use pst.Start (TxPin, 115200) but it return an error. I tried to look up proper syntax but, could not find what I was looking for.
Any help would be appreciated.
My test code is below.

OBJ
  pst : "FullDuplexSerial.spin"
CON
 ' _clkmode = xta11 + p1116x
 ' _xinfreq = 5_000_000
  TxPin = 0
PUB Main
  pst.Start(TxPin, TxPin, %1000, 115_200)
  waitcnt(clkfreq + cnt)
  repeat
    pst.Str(String("!G,2,71"))
    waitcnt(clkfreq * 3 + cnt)
    pst.Str(String("!G,1,1000"))
    waitcnt(clkfreq * 3 + cnt)
    pst.Str(String("!G 1 1000")) 

«1

Comments

  • kuronekokuroneko Posts: 3,623
    edited 2013-12-16 19:04
    This code works for me provided the clock setup is present (currently commented out). Without it you are using RCFAST mode which is not accurate enough to cover 115200baud. Also, I'd expect some kind of line delimiter to be sent, e.g. CR or LF.
  • JonnyMacJonnyMac Posts: 9,107
    edited 2013-12-16 19:06
    Can you provide a link to the product documentation? That will help others help you.
  • stuartXstuartX Posts: 88
    edited 2013-12-16 19:08
    @kuroneko
    I wasn't quite sure what the %1000 was for but, I wanted to make sure that the ASCII was getting output @ 115200.
    Thanks for your input, if you have anything else to add...please feel free.
    Thanks again.
  • stuartXstuartX Posts: 88
    edited 2013-12-16 19:12
    The product doc link is:

    http://www.roboteq.com/index.php/docman/motor-controllers-documents-and-files/documentation/user-manual/7-nextgen-controllers-user-manual/file

    It should be page 111 "Serial (RS232/USB Operation)

    Thank you (in advance)
  • stuartXstuartX Posts: 88
    edited 2013-12-16 19:18
    The commands start on page 163.
  • kuronekokuroneko Posts: 3,623
    edited 2013-12-16 19:33
    I haven't verified the commands but the delimiter is definitely missing. Just extend your string definitions like this:
    pst.Str(String("!G,2,71"[COLOR="#FF0000"], 13[/COLOR]))
    
  • stuartXstuartX Posts: 88
    edited 2013-12-16 19:34
    ok, i'll go try it now. (its in the garage)
  • stuartXstuartX Posts: 88
    edited 2013-12-16 19:41
    None of the following worked. I also tried the 0x0D which is the carriage return.

    I tried that: pst.Str(String("!G,2,71", 13))
    Then I tried
    pst.Str(String("!G,2,71,13))

    Then I tried:
    pst.Str(String("!G,2,71, 0x0D", ))

    Then I tried
    pst.Str(String("!G,2,71", 0x0D)) 'I got a syntax error.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2013-12-16 19:47
    Hex is represented with a "$".

    $0D is what you'd use. It's identical to 13. The exact same bits are sent down the serial line when using either of the below code.
    pst.Str(String("!G,2,71", 13))
    
    pst.Str(String("!G,2,71", $0D))
    
  • stuartXstuartX Posts: 88
    edited 2013-12-16 19:49
    I'll go try it now.
  • kuronekokuroneko Posts: 3,623
    edited 2013-12-16 19:51
    stuartX wrote: »
    None of the following worked ...
    Do you know anything about the voltage levels required by the serial link? IOW, is it compatible with the 3.3V/0V interface of the propeller?
  • stuartXstuartX Posts: 88
    edited 2013-12-16 19:55
    I tried the following...still nothing.

    I tried the :
    pst.Str(String("!G,2,71", $0D))

    and
    pst.Str(String("!G,2,71,$0D"))
  • Duane DegnDuane Degn Posts: 10,588
    edited 2013-12-16 20:13
    Are the commas part of the message?

    Is there an example of the message you're trying to send in the documentation?

    Where is the "!G" command listed?

    Edit: Give "pst.Str(string("!G", 2, 71, 13))" a try.
  • stuartXstuartX Posts: 88
    edited 2013-12-16 20:19
    No Sir, the commas are not part of the message. I tried it with commas and without.
    I got the following information from the Roboteq folks:


    P. 168 and 169

    Syntax: !G [nn] mm
    Where: nn = motor channel
    mm = command value

    If you are trying to do this via a closed loop speed, then you need to set up your max speed value of your motor in the speed and acceleration parameter.

    Refer to the user manual for additional information.

    and


    To test, send the sring "?FID" terminated by a carriage return character. That is ASCII 0x0d.

    The nextgen controller works on 115200 kbps. Change the settings to 8N1 115200.

    The syntax should be !G 1 10000 0x0D.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2013-12-16 20:55
    stuartX wrote: »
    The syntax should be !G 1 10000 0x0D.

    So is it delimited by a space character?

    If so you'd send.
    pst.Str(string("G! 1 10000", 13))
    

    Or if the motor ID were stored in the variable "motor" and the speed stored in the variable "speed", you could use:
    pst.Str(string("G! "))
      pst.Dec(motor)
      pst.Char(" ")
      pst.Dec(speed)
      pst.Char(13)
    
  • stuartXstuartX Posts: 88
    edited 2013-12-16 20:58
    I'll go try it now.
  • stuartXstuartX Posts: 88
    edited 2013-12-16 21:05
    I tried it but I got an error on the following:
    pst.Char(" ")

    I made motor and speed a constant.
  • stuartXstuartX Posts: 88
    edited 2013-12-16 21:09
    The code looks like this:
    OBJ
      pst : "FullDuplexSerial.spin"
    CON
     ' _clkmode = xta11 + p1116x
     ' _xinfreq = 5_000_000
      TxPin = 0
      motor = 1
      speed = 1000
    PUB Main
      pst.Start(TxPin, TxPin, %1000, 115_200)
      waitcnt(clkfreq + cnt)
      repeat
        pst.Str(String("!G 1 10000", 13))
        waitcnt(clkfreq * 3 + cnt)
        pst.Str(String("!G,1,1000,13"))
        waitcnt(clkfreq * 3 + cnt)
        pst.Str(String("!G 1 1000 0x0d"))
        pst.Str(string("!G "))
        pst.Dec(motor)
        pst.Char(" ")                    'Received error here
        pst.Dec(speed)
        pst.Char(13)
    
  • Duane DegnDuane Degn Posts: 10,588
    edited 2013-12-16 21:13
    pst is usually the abriviation for "Parallax Serial Terminal.spin"

    FDS uses "tx" instead of "char". Replace all the "Char" calls with "tx".

    You have to have the clock settings commented out in order for the serial connection to work as mentioned earlier in the thread.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2013-12-16 21:17
    kuroneko wrote: »
    This code works for me provided the clock setup is present (currently commented out). Without it you are using RCFAST mode which is not accurate enough to cover 115200baud. . ..

    Make sure and do what kuroneko suggested. It won't work otherwise!
  • stuartXstuartX Posts: 88
    edited 2013-12-16 21:17
    ok, i'll try it again.
    'thanks/
  • Duane DegnDuane Degn Posts: 10,588
    edited 2013-12-16 21:22
    Don't use these lines.
    pst.Str(String("!G,1,1000,13"))
      
        pst.Str(String("!G 1 1000 0x0d"))
    

    I promise they use the wrong syntax.
  • kwinnkwinn Posts: 8,697
    edited 2013-12-16 21:24
    First you have to uncomment the two lines below to get a reliable clock for serial communications.

    ' _clkmode = xta11 + p1116x
    ' _xinfreq = 5_000_000

    Then, shouldn't it be "pst.Str(string("!G 2 71”, 13))" for the motor command?
    “!” indicates it is a command,
    “G” is the set motor command,
    “2” is the motor channel,
    “71” is the value to set it to, and a space is the separator.

    The characters between the quotes will be compiled as the ascii characters !G 2 71, and the decimal number 13 will be the ascii character 0D aka CR since it is outside the quotes.
  • stuartXstuartX Posts: 88
    edited 2013-12-16 21:29
    Ok, I replace the Char with the tx.
    and I commented out the earlier strings:
      pst.Str(String("!G,1,1000,13"))
      
        pst.Str(String("!G 1 1000 0x0d"))
    

    But nothing happened.
  • kwinnkwinn Posts: 8,697
    edited 2013-12-16 21:34
    stuartX wrote: »
    Ok, I replace the Char with the tx.
    and I commented out the earlier strings:
      pst.Str(String("!G,1,1000",13))
      
        pst.Str(String("!G 1 1000" 0x0d))
    

    But nothing happened.

    Try this, then check my previous post.
  • stuartXstuartX Posts: 88
    edited 2013-12-16 21:37
    i'll go try it now.
  • stuartXstuartX Posts: 88
    edited 2013-12-16 21:46
    @kwinn
    I tried that again:
      pst.Str(String("!G,1,1000",13))
      
        pst.Str(String("!G 1 1000" 0x0d))
    

    I received an error with the 0x0d 'it said must use characters from 1 to 255
    I placed it in the " ......still nothing happen when I ran the program.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2013-12-16 21:46
    Just so it's clear.

    You must have the clock mode and crystal settings set in order to use the high speed serial.

    As it's been mentioned multiple times, you must have:
    _clkmode = xtal1 + pll16x 
      _xinfreq = 5_000_000
    

    or something similar in your CON section.

    Do you have a 5MHz crystal on your Prop board? If not, what crystal are you using. You'll need a crystal to use a baud of 115,200 bps.
  • kwinnkwinn Posts: 8,697
    edited 2013-12-16 21:48
    Sorry, missed replacing the commas with spaces in the first line.

    Both of these should do the same thing. The 13 outside the quotes is treated as a decimal number and converted to a carriage return character. The 0x0d is treated as a hexadecimal number and converted to a carriage return.

    pst.Str(String("!G 1 1000",13))

    pst.Str(String("!G 1 1000" 0x0d))
  • stuartXstuartX Posts: 88
    edited 2013-12-16 21:50
    Yes Sir,
    the clock mode code is still there. I have the propeller board, the crystal is a T5.00
Sign In or Register to comment.