Shop OBEX P1 Docs P2 Docs Learn Events
Monitor rs232 port > alter data > output to serial LCD solution - Page 2 — Parallax Forums

Monitor rs232 port > alter data > output to serial LCD solution

2»

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-04-09 20:04
    Perhaps a faster Stamp would help?· Or, better yet, since you're dealing primarily with serial data, perhaps you could use an SX (Possibly using SX/B) for this task.· You would certainly be able to process more serial data without timing issues on the SX.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • syxysyxy Posts: 25
    edited 2006-04-09 20:14
    Thanks Chris,

    I'll have a look at those.

    How do I construct code like this:

    If pin A receives data THEN goto case_A OR if pin B receives data THEN goto case_B?

    Cheers Richard
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-04-09 20:22
    There are a few ways to do this, actually.· How much code is being executed at the branched address?· You may be able to include that code into the IF...THEN section.
    IF x = 1 THEN
      GOTO Case1
    ELSE
      GOTO Case2
    ENDIF
    

    Now, if the the second conditional needs to be more specific you use:

    IF x = 1 THEN
      GOTO Case1
    ELSEIF x = 2 THEN
      GOTO Case2
    ENDIF
    
    

    You can also say:

    ON x GOTO Case1, Case2, Case3
    

    Or:

    SELECT x
      CASE = 1
        GOTO Case1
      CASE = 2
        GOTO Case2
    ENDSELECT
    

    I hope these give you a few ideas.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • syxysyxy Posts: 25
    edited 2006-04-09 20:33
    Chris,

    I looked all over the site but I cannot find any info on the SX/B stamp. Do you have a link? By the way, is there a chip which can handle 40 variables instead of the regular 26 available bytes?

    Cheers
  • ForrestForrest Posts: 1,341
    edited 2006-04-09 21:07
    SX/B isn't a Stamp - it's a version of Basic that runs on the SX Processor - see here www.parallax.com/sx/sx_products_overview.asp

    To program the SX chip, you'll need an SX-Key or the SX-Blitz, and a development board such as the www.parallax.com/detail.asp?product_id=45205 and an SX-28 chip
  • syxysyxy Posts: 25
    edited 2006-04-09 21:45
    Can the SX chips multitask? I.e monitor two ports simultaneously?

    How difficult is it to create a physical serial interface? Do I just hookup a line driver to the chip?

    Cheers

    Richard
  • syxysyxy Posts: 25
    edited 2006-04-09 21:54
    Chris,

    Seemed to have missed your answer, sorry about that. I have seen examples like your but the point is the first statement:



    IF x=1 then...ELSE...

    I need a stament that is like >

    Main:

    IF x=1 then case x OR IF y=1 then case y··

    (in other words, if serial data is presented to pin x then ..OR...if serial data is presented to pin Y then...)

    Case X:

    serin··/ serout routine

    goto main



    Case Y:

    serin / serout routine

    goto main
    Chris Savage (Parallax) said...
    There are a few ways to do this, actually.· How much code is being executed at the branched address?· You may be able to include that code into the IF...THEN section.
    IF x = 1 THEN
      GOTO Case1
    ELSE
      GOTO Case2
    ENDIF
    

    Now, if the the second conditional needs to be more specific you use:

    IF x = 1 THEN
      GOTO Case1
    ELSEIF x = 2 THEN
      GOTO Case2
    ENDIF
    
    

    You can also say:

    ON x GOTO Case1, Case2, Case3
    

    Or:

    SELECT x
      CASE = 1
        GOTO Case1
      CASE = 2
        GOTO Case2
    ENDSELECT
    

    I hope these give you a few ideas.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-04-10 05:43
    They don't have to use equal signs...I could've just as easily used >, <, >= or <= in these but they were just examples of ways to evaluate conditions and take action (multiple actions).

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • syxysyxy Posts: 25
    edited 2006-04-10 06:28
    Hi Chris,

    I understand what your saying and sorry for being a pain in the a at the moment but what I am trying to achieve is to find a statement whereby I can evaluate wethere there is any data at all whereby the statement looks like this:

    Main:
    If there's any data on serin pin A then goto label A OR if there's any data on serin pin B then goto label B

    Label A:
    code
    goto main

    Label B:
    code
    goto main

    I have a feeling that the first statement requires multitasking because it is constantly evaluating wether there's data on either pin and execute a particular routine afterwards and possibly still listen on the other pin whilst it is executing a block of code.

    If this is the case (multitasking) then a possible solution might be to speed up the code as much as possible so that the chance of missing data on pin A or B is minimised. This calls for the fastest loop solution.

    1) The possibilities are DO...LOOP or the GOTO type of statement. Can you tell me wether one is faster then the other.

    2) Secondly, is it faster to use SERIN,8,84+$4000,[noparse][[/noparse]str string\21] OR serin,baud,inverted,[noparse][[/noparse]str string\21] whereby baud and inverted have been declared as constants.

    3) Can the...[noparse][[/noparse]str string\21] be declared as a constant as well or can 84+$4000 be declared as a constant? I tried doing this but the code wouldn't tokenize.


    One last thing I wanted to mention is that I am having real problems with the output to the display when I don't use the entire string which has been captured. Compare both statements below:

    string VAR Byte(21)

    SERIN 8,84+$4000,[noparse][[/noparse]str string\21]
    SEROUT 11,84+$4000,[noparse][[/noparse]str string\21]
    This solution works and all the characters show up fine

    SERIN 8,84+$4000,[noparse][[/noparse]skip 10, str string\11]
    SEROUT 11,84+$4000,[noparse][[/noparse]str string\11]
    All of a sudden all characters show up as garbage....????????...instead of showing the last 11 characters of a 21 character string.

    Do you know what I am doing wrong?

    I appreciate your help.

    Regards,

    Richard
  • syxysyxy Posts: 25
    edited 2006-04-10 07:39
    Just to further clarify the point:

    g91string VAR Byte···· '(12)
    g68string VAR Byte···· '(14) 'max 26 variables - 21 works

    baud CON 84+$4000
    tolcd CON 11
    tog68 CON 10
    tog91 CON 12
    fromg68 CON 8
    fromg91 CON 9

    g91:
    SERIN fromg91,baud,[noparse][[/noparse]STR g91string\12]
    SERIN fromg68,baud,[noparse][[/noparse]STR g68string\21]
    SEROUT tolcd,baud,[noparse][[/noparse]STR g91string\12,STR g68string\21]
    GOTO g91

    The whole point is that I don't want to introduce a timout in the SERIN code. I want it to be indifferent, if there's data then that's fine and store it and move on. If there isn't any data then that's fine too but please move on to the next line and try there. If there isn't any data here too then don't bother waiting for it but start over.......
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-04-10 10:24
    Richard -

    Just as a bit of a warning, both of your data areas are presently defined as ONE byte each.

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    <!--StartFragment -->
  • syxysyxy Posts: 25
    edited 2006-04-10 10:35
    Hi Bruce,

    Are you referring to the fact that the following VAR statement(s):

    g91string VAR Byte '(12) is not like this: g91string VAR Byte(12) ?

    I tried both but it makes absolutely no difference in the output to the display. It wonders me why this is the case....


    Your guess is probably better than mine..
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-04-10 10:53
    Hi Richard -

    Indeed I am. PBASIC does no bounds checking, thus anything past g91string(0) like g91string(1) will clobber anything in the g68string. So long as you're aware of it, that's fine.

    There is nothing patently "illegal" about doing it, it's just that it can be dangerous. In the extreme worst of cases, you can actually wipe out pieces your program!

    I just like to point out potential "gotcha's" BEFORE folks tear their hair out, if I can smile.gif

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    <!--StartFragment -->
  • syxysyxy Posts: 25
    edited 2006-04-10 11:00
    Thanks Bruce, I'll adjust my code accordingly.

    By the way I am still open for suggestions concerning a fast loop (any better offers on this?)

    or ignoring a serial port if there's no data....
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-04-10 11:20
    Richard -

    For better or worse, whenever I start recommending products which Parallax doesn't sell, a brief chill runs up my spine. Be that as it may.

    Here is one method to overcome your apparent problem. Stop worrying about "getting there in time", or detecting the potential input as soon as it's available. Instead, buffer the inputs so that you can expand the time you have to make decisions. You can do so by using one of these buffers on each of the inputs:
    http://www.protean-logic.com/Product Info/periph/rsb509l1.htm

    Once that's done, the bottleneck is no longer the incoming data or when it arrives, as it will be available to you after the fact (you can't "miss" incoming data), and you can go about whatever logical program processes you choose to.

    Think outside the box smile.gif

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    <!--StartFragment -->
  • syxysyxy Posts: 25
    edited 2006-04-10 11:30
    Hi Bruce,

    I had a quick look and it seems that this is indeed the solution. I am aware that what I am asking from the stamp is really close to multitasking....

    Is it correct that I'd need one of these for each serial input ? Do I need to program it as well or is everything handled by the stamp?

    Would there be a benefit going the SX chip route instead?

    Cheers

    Richard
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-04-10 11:53
    Richard -

    The RSB509 is a "canned" solution, and no programming (per se) is required on your part, but you may have to set certain "options" to fit your needs. Without knowing a good deal more about the timing of your incoming data, and developing a predicatable timing sequence, I'd just go with two buffers and leave it at that. Sometimes the time you spend to solve a problem is worth a good deal more than the device to circumvent the problem.

    If you want to get involved with the necesary expense of becoming an SX programmer, and purchasing the tools, that's one thing. There is a lot to be learned, but there is a finite cost. and that cost is far greater than the cost of these buffers, even if you have to purchase two of them. If you want a clean, "canned" solution, and you have no greater aspirations, then the RS-232 buffers are the way to go. The answer really depends on your own goals.

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    <!--StartFragment -->
  • syxysyxy Posts: 25
    edited 2006-04-10 11:59
    Well Bruce,

    The stamp & buffers would be part of a new product which is to be sold (initially) in smaller quantities. The initial outlay for a SX based solution might be higher but chip costs for let's say 100 pieces is where differences start adding up.

    Don't know exactly yet how much the SX route is going to cost me...or how much these buffers cost.

    Any further thoughts?

    Cheers

    Richard
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-04-10 14:36
    syxy said...(trimmed)
    Main:
    If there's any data on serin pin A then goto label A OR if there's any data on serin pin B then goto label B
    1) The possibilities are DO...LOOP or the GOTO type of statement. Can you tell me wether one is faster then the other.
    2) Secondly, is it faster to use SERIN,8,84+$4000,[noparse][[/noparse]str string\21] OR serin,baud,inverted,[noparse][[/noparse]str string\21] whereby baud and inverted have been declared as constants.
    3) Can the...[noparse][[/noparse]str string\21] be declared as a constant as well or can 84+$4000 be declared as a constant? I tried doing this but the code wouldn't tokenize.
    One last thing I wanted to mention is that I am having real problems with the output to the display when I don't use the entire string which has been captured. Compare both statements below:
    string VAR Byte(21)
    SERIN 8,84+$4000,[noparse][[/noparse]str string\21]
    SEROUT 11,84+$4000,[noparse][[/noparse]str string\21]
    This solution works and all the characters show up fine

    SERIN 8,84+$4000,[noparse][[/noparse]skip 10, str string\11]
    SEROUT 11,84+$4000,[noparse][[/noparse]str string\11]
    All of a sudden all characters show up as garbage....????????...instead of showing the last 11 characters of a 21 character string.
    Okay,

    ·· I think I see what you're getting at now.· If you're expecting that kind of data (serial) from two different sources that's not going to happen.· The BASIC Stamp has no FIFO Buffer (although you could add one for each channel externally).· It is always advisable to declare baud rate parameters as constants.· This is also true of pin assignments, etc.· The reason being is that when you make one change all lines in the code are affected.· When you use the raw values on each line, if you need to change something you have to hunt down all affected lines and make the changes every time.

    ·· I don't understand your question about delcaring the array as a constant...Variables and constants are two different things.· As for your code not working, I'm not sure exactly what's happening there, but you are using the skip modifier, so perhaps that is slowing things down just enough to miss data in the serial stream.· Again, external FIFO buffers may be a better choice.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
Sign In or Register to comment.