Shop OBEX P1 Docs P2 Docs Learn Events
BS2PX Fastest Input — Parallax Forums

BS2PX Fastest Input

heroldherold Posts: 66
edited 2005-06-04 05:10 in BASIC Stamp
I have a radom bit generator on the bread board (up to 10 Mhz). I am reading the 0 pin for 0 or 1 inputs and than tranfer then via serial port to the PC. In the PC·I have a program to analyze the data.

Still I am using the fastest chip the rate is very slow. Any ideas how to program the fastest way to imput the data and pass them on via serial interface?

What I am referring here is basically the sampling rate. How can I sample up to 1Mhz? What hardware is needed?

Right now I am doing this:


Bit_0·· VAR· Byte
Rand··· VAR· Byte

EventIn VAR IN0 ' event input pin

MAIN:
Bit_0 = EventIn

IF Bit_0 = 0 THEN
·· Rand = 1
ENDIF
IF Bit_0 = 1 THEN
·· Rand = 2
ENDIF

SEROUT 16,16780,[noparse][[/noparse]Rand]
GOTO Main

Post Edited (herold) : 6/2/2005 2:51:05 AM GMT

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-06-02 02:35
    What are you ultimately·trying to accomplish?

    In your example, the program (not the Stamp) is responsible for the apparent lack of speed.· Here's why:

    · --·You read the bit, then analyze·it with IF-THEN
    · -- You're transmitting a byte at 9600 baud (this takes a millisecond by itself, let alone instruction loading)

    If you want to speed things up, give this a try:


    EventIn··· PIN··· 0

    Baud······ CON··· 84 + $4000

    Main:
    · DO
    ··· SEROUT 16, Baud, [noparse][[/noparse]EventIn + 1]
    · LOOP

    This gets rid of a lot of unnecessary logic (that just consumes time)·and cranks the baud rate up to 38.4K (this is supported by the Debug Terminal [noparse][[/noparse]opened manually]; you can go even·faster if you're using an external program like HyperTerminal).· Note that the program would be even faster if your PC program could accept 0 and 1 instead of 1 and 2.· Getting rid of the "+ 1" in the SEROUT line would speed give you a bit more speed.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax

    Post Edited (Jon Williams (Parallax)) : 6/2/2005 2:38:56 AM GMT
  • heroldherold Posts: 66
    edited 2005-06-02 03:07
    Thank you very much, I am impressed of what you come up with. I will re-write my PC program in order to accept 0 and 1 and give it a try.

    Here is what I like to accomplish:
    I am experimenting with influencing the random bit generator by conciousness. Focus on tail for example will bring more order and therefore more 1's. In my PC program I have a stats program runing.

    I think the faster I can sample the better the results.
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-06-02 04:19
    Glad I could help. Since you're writing your own program, crank up the baud rate; the BS2px can go up to 115.2K (baud value is 14 + $4000).

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • heroldherold Posts: 66
    edited 2005-06-02 19:40
    I have troubles now getting a serial connection to work with my Realbasic PC program. Even I use a lower baud rate I don't get the 0's and 1's correctly into my PC.

    It looks like the BS2px has the same commands for the serial as the others. I understand that I have to use the same settings (baud, parity,stop etc) on both sides.

    Any ideas how to setup a basic test program?
  • NewzedNewzed Posts: 2,503
    edited 2005-06-02 19:46
    To clarify, you use the same baud RATE on both sides.· The SETTING for one side might be 16468 and on the other 16636. Signal must be either TRUE or INVERTED on both sides, and both sides must have the same bit and parity setting.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Sid Weaver
    Need a bezel for your LCD?

    Newzed@aol.com
    ·
  • heroldherold Posts: 66
    edited 2005-06-02 20:28
    On my Bs2px I use 16780 right now with this test program:

    serStr VAR Byte(5)

    serStr(0) = "H"
    serStr(1) = "E"
    serStr(2) = "L"
    serStr(3) = "L"
    serStr(4) = "O"

    Main:
    'DEBUG STR serStr
    SEROUT 16,16780,[noparse][[/noparse]STR serStr\5]
    PAUSE 200
    RETURN


    On the PC I have the following setting in my Real Basic Program:

    Baud = 9600
    1 Stop Bit
    No Parity
    8 Data Bits

    Anything else I have to set?
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-06-02 20:39
    If 16780 is the correct baudmode value (I refuse to look this stuff up anymore since it's some much easier to use conditional compilation constants) for your BASIC Stamp you need to fix the program as follows:

    Main:
    · SEROUT, 16780, [noparse][[/noparse]STR serStr\5, CR]
    · PAUSE 200
    · GOTO Main

    RETURN is used at the end of a subroutine (called with GOSUB) -- your use in this code is not correct.· Note that I added a CR to the SEROUT so that each output is on a new line (if using the Debug Terminal window; you need to append linefeeds to CRs in other terminal programs).· Without the CR you output would look like:

    HELLOHELLOHELLOHELLOHELLO...

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • heroldherold Posts: 66
    edited 2005-06-03 07:45
    Ok, I have it going with 115.2k Baud! It took me a while to get the communication with the PC program straight. I am getting about 3000-4000 numbers per second - can this be?

    EventIn PIN 0
    Baud CON 14 + 16384

    Main:
    DO
    SEROUT 16,Baud,[noparse][[/noparse]EventIn]
    Loop

    I had more zeros in the stream than one's so I did this:

    SEROUT 16,Baud,[noparse][[/noparse]EventIn+1]

    Now I could see on my PC that in 1% of the stream there were zeros. And I should get only 1's & 2's. Where do they come from???

    Thanks for all the support!
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2005-06-03 08:11
    Herold -

    By implicit definition, a one bit entity ( EventIn PIN 0 ) can only have a value of zero or one. If you add one (or any other value) to it, all you will get is the appropriate one bit value rounded per the rules of PBASIC.

    Regards,

    Bruce Bates
    ·
  • heroldherold Posts: 66
    edited 2005-06-03 19:07
    I did some more tests and it looks like 57600 Baud is the max. I can go with the BS2px.

    I have grounded the input pin 0 and run my simple test program:

    EventIn PIN 0
    Baud CON 49 + 16384 ' 57600 Baud

    Main:
    DO
    SEROUT 16,Baud,[noparse][[/noparse]EventIn+1]
    Loop

    As expected I get a stream of 1's as I add 1 to it.

    But if I go with 14+16384 (115.2k Baud) I get zeros in the serial stream (about 1-2%).

    I guess these are errors as of too much speed?

    Edit: If I pin the input to 5V than the serial stream is 100% number 2's as it should be. Maybe the random bit generator (up to 60 Mhz) on the breadboard influences th ewhole thing and it starts to resonate.

    Post Edited (herold) : 6/3/2005 7:27:29 PM GMT
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-06-03 19:43
    Since your desire is to make things happen as fast as possible, you have to do as little as possible on the Stamp end of things (the PC has more horsepower, so move the burden there). I would take the addition out of the SEROUT statement to start with.

    And keep in mind that 115.2 kBaud is really fast and pushing the limits of the BASIC Stamp. When you do the math for the baudmode calculation you get:

    ··· 4,000,000 / 115200 = 34.7 - 20 = 14.7

    If I were in your shoes I'd dump the equation in SEROUT and experiment with baudmode values of 14 and 15 to see which is the most reliable.

    If none of this works for you then consider the SX micro programmed in SX/B. Running a 50 MHz resonator you could do about any baud rate imaginable.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • heroldherold Posts: 66
    edited 2005-06-03 21:40
    Thank you again for your valuable input! I really appreciate your commends and the feedbacks.

    If I take out the +1 in the Serout command I have no way of testing for errors. As errors fall into the 0 bit. Than I get a wrong input into my PC - it will false all the calculations I do on the result of the income stream.

    In my PC program I sipmy filter the zeros out of them stream. Running at 57k I get about 1% error, with 115K I get 5% errors and it looks like I get only 40% more data in.

    By the way the 14 value works much better tahn the 15. The 15 produces lots of errors. I am happy so far with the amount of data - I think I can work with it.
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-06-03 22:25
    It might be more efficient for the Stamp to do the math outside the SEROUT command.· Do something like this:

    · testVal = IN0 + 1
    · SEROUT Sout, Baud, [noparse][[/noparse]testVal]

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • heroldherold Posts: 66
    edited 2005-06-03 23:18
    Makes sense, but this statement doesn't work: Error "Label is missing." Is there something else required?

    testVal = IN0 + 1
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-06-04 05:10
    Hello,

    ·· testVal must be declared as a variable.

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