Stamp intermittently responding to serial input
maldridge
Posts: 37
I have written the following program to parse and act on serial data recieved from a program running on a PC. The data arrived in the following format.
The "~!" is a serial header that the stamp should wait on until it recieved before continuing program exicution. Each set of zeros represents the intensity of one channel (program controlls lights).
the problem comes in that the stamp only responds intermittently. e.g. the outputs may switch on, but take several cycles to turn off. Since the serial data is updated every 100ms, I would like the stamp to react that fast. By my calculations, the stamps clock speed should give it well over 84ms room after processing the data in the serial string before it needs to be ready to process again.
I think that some of my trouble comes in not fully understanding PBASIC arrays. Are they 0 indexed? Or does the index initialize randomly.
Here is the program:
For those who know the program, I am using Vixen 2.1.1.0 with the generic serial plugin and a text header of "~!" (without quotes).
~! 00 00 00 00 00 00 00 00
The "~!" is a serial header that the stamp should wait on until it recieved before continuing program exicution. Each set of zeros represents the intensity of one channel (program controlls lights).
the problem comes in that the stamp only responds intermittently. e.g. the outputs may switch on, but take several cycles to turn off. Since the serial data is updated every 100ms, I would like the stamp to react that fast. By my calculations, the stamps clock speed should give it well over 84ms room after processing the data in the serial string before it needs to be ready to process again.
I think that some of my trouble comes in not fully understanding PBASIC arrays. Are they 0 indexed? Or does the index initialize randomly.
Here is the program:
' {$STAMP BS2} ' {$PBASIC 2.5} 'Program: Lighting Firmware.bs2 'Author: Michael Aldridge 'Version: 1.0.5 'Purpose: To parse an incomming serial string from Vixen ' and relay the instructions to an SSR grid. restart: '--------------------Initialization-------------------------- dat VAR Byte(8) link CON 16 baud CON 84 index VAR Nib '-----------------------Main Loop---------------------------- DO SERIN link, baud,500,timeout, [WAIT("~!"),STR dat\8] FOR index = 0 TO 8 IF dat(index)>0 THEN HIGH index IF dat(index)=0 THEN LOW index NEXT LOOP '-------------------Timeout Condition------------------------ timeout: FOR index = 0 TO 7 LOW index NEXT GOTO restart
For those who know the program, I am using Vixen 2.1.1.0 with the generic serial plugin and a text header of "~!" (without quotes).
Comments
-Phil
The ASCII zeros in my example are what my serial terminal captured when I sent sample data from the program to the terminal instead of to the controller. I assumed that the terminal was translating binary data into a human readable format. I actually based that off of information I got from the people who wrote the software.
Unfortunately, changing the 8 to a 7 still has not helped the operation of the program. If anyone would like to check the program operation for themselves and confirm my observations, the program can be found here. It's a live program that just runs out of the folder you unzip it into.
At the moment, I am testing just with LED's connected to P0-P2. I assume that if it works on the first three lines, it will work on the other 5.
I'm not entirely sure the MAX 1 is necessary. I put it there assuming the LSB of the argument -- not its non-zeroness -- is assigned to the pin.
You will need to initialize DIRL at the top of your program to set the affected pins to outputs first.
-Phil
Perhaps my own stupidity has messed up something here. Any thoughts?
Can you drop to 4800 baud and do a test? Otherwise, your program looks the same as what I use. I don't think you'll actually process at the 100 mS rate, but the WAIT modifier will allow the Stamp to catch the next available string when its ready.
If you have to stay at 9600, a BS2sx will get you there easily.
Cheers,
The LSB corresponds to pin 0, not the MSB.
-Phil
'
The BS2's don't have an input buffer.So it takes some cool code to make it run at higher Baud Rates.
-Phil
Unfortunately, it still only operates intermittently. Also, I'm not sure why, but for some reason the channels are all being shifted up one pin.
Also, because I can't find any complete/easy to comprehend resource for the serin baud constant, can anyone tell me what it should be for 4800, 8, n, 1
"???"
PBASIC Help presents that - in tables - in the SERIN entry.
How could it be any plainer?
Think different.
I'm on a mac and I couldn't get the help file to even open.
Start at the lowest bps (say 2400) and work up to higher rates from there...