PDA

View Full Version : BS2PX Fastest Input



herold
06-02-2005, 10:23 AM
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,[Rand]
GOTO Main

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

Jon Williams
06-02-2005, 10:35 AM
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, [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 [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

herold
06-02-2005, 11:07 AM
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 Williams
06-02-2005, 12:19 PM
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

herold
06-03-2005, 03:40 AM
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?

Newzed
06-03-2005, 03:46 AM
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 (mailto:Newzed@aol.com)
ˇ

herold
06-03-2005, 04:28 AM
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,[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 Williams
06-03-2005, 04:39 AM
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, [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

herold
06-03-2005, 03:45 PM
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,[EventIn]
Loop

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

SEROUT 16,Baud,[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 Bates
06-03-2005, 04:11 PM
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
ˇ

herold
06-04-2005, 03:07 AM
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,[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 Williams
06-04-2005, 03:43 AM
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

herold
06-04-2005, 05:40 AM
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 Williams
06-04-2005, 06:25 AM
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, [testVal]

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

herold
06-04-2005, 07:18 AM
Makes sense, but this statement doesn't work: Error "Label is missing." Is there something else required?

testVal = IN0 + 1

Chris Savage
06-04-2005, 01:10 PM
Hello,

ˇˇ testVal must be declared as a variable.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com (mailto:csavage@parallax.com)