Pbasic argument question...

Can anyone define the argument for Serout (255,255…)? What do the 255’s mean? Thanks.

The 255’s are simply signals to the output cpu telling it that this is the start of the stream of bytes.

If the o/p cpu were not to receive them (maybe it missed them on powerup), it woud sit there listening for 255,255. Once received (the next time the Stamp sends an output stream), the bits would be pigeonholed properly as bit ‘n’ from the start, bit ‘n+1’ and so on.

This is also why you should always limit your PWM values to 254 – NEVER allow them to be 255.

If you look at the output order, there is always a PWM value output between things that could possibly be a value of 255 (for instance you may want all relays ON, in this case relayA may be all 1’s which is $FF or 255. If this was next to another thing, say relayB that could also be 255, the master CPU would think, “A HA, This is the start of the data stream” But, Innovation First cleverly put a PWM value in between RelayA and RelayB. So, the only way to make a “255, 255” sequience is to foolishly allow the PWM value to equal 255.

This problem can cause very subtle errors. MOST of the time everything is right as rain, then BOOM! Thunder and lighting! your code crashes.

Do yourself a favor, make sure you get good at limiting the values of your PWM outputs to 0-254.

Joe J.

Last year, we spent a day trying to figure out why our robot would suddenly do a little dance and make the light blink on and off whenever we commanded full forward. We reduced the limit to 254 and it went away. Some software religious thing, I figured. It wasn’t until after shipping that I was able to go back and realized that the 255,255 was the serial output initialization identifier. Everytime the second STAMP processor sees a 255,255 it thinks that there is a new stream of data so the next byte is PWM1 and the one after that is RelayA, etc.

The good thing was that I was able to help out another team at Nationals with this tidbit of information and they were able to get their 'bot up and working. They were quite grateful.

If it helps, the robot controller to operator interface data stream is documented in the dashboard port specification that is located on InnovationFIRST’s website. We also have a link to it on our team’s website: http://www.cvhsrobotics.org/resources.htm

Kevin

thank you everyone!

Just for the fun of it… has anyone tried to force the controller to send out a value of 256? Or turned a byte variable into a word and given it some random signal of 300? After reading this post I thought about trying it and I plan to try it durring the off season. Just wondering if anyone has already tried it.

*Originally posted by GhettoTech *
**Just for the fun of it… has anyone tried to force the controller to send out a value of 256? Or turned a byte variable into a word and given it some random signal of 300? After reading this post I thought about trying it and I plan to try it durring the off season. Just wondering if anyone has already tried it. **

Before you go messing up your robot, you should read the section of the PBASIC manual about math, and you will find your answer.

256 would become 0, since it works much like a car’s odometer, if you go past the limit it starts all over again.

Before you go messing up your robot, you should read the section of the PBASIC manual about math, and you will find your answer.

I have read, re-read and recently reviewed the PBASIC manual’s section on math, but I still don’t know what will happen to the robot controller if, for example, I were to take the p1_y variable and change it from a byte variable, into a word variable, and give it a value larger than 254. Will any extended bits be trunkated before going through the serout command?

I’m not sure why you would want to do this, but I guess curiosity is a good thing. More than likely, the robot controller would see the first byte of your new p1_y word variable as the p1_y byte and the second byte as whatever the next variable is supposed to be, like RelayA. My only question then would be which byte of the word variable would the serout command send first, the high byte or the low byte? I didn’t see an answer after a quick perusal of the Stamp Manual, let us know if you find out.