BS2PX Fastest Input
herold
Posts: 66
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
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
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
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
Applications Engineer, Parallax
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?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
Need a bezel for your LCD?
Newzed@aol.com
·
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?
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
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!
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
·
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
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
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.
· testVal = IN0 + 1
· SEROUT Sout, Baud, [noparse][[/noparse]testVal]
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
testVal = IN0 + 1
·· testVal must be declared as a variable.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com