Serin problems
pdiefend
Posts: 27
Hi all,
I am working on a robot that has BS2's as a transmitter and a receiver, and I am using SERIN and SEROUT to send the data from the transmitter and receiver. The robot is supposed to count how many times it cycles through a piece of code using the code listed below. I am almost sure that the problem is that the serin command is waiting until it receives the data instead of looping after not receiving any data. Any ideas here why the serin is waiting instead of looping back to forward the way it should?
forward:
counter = counter + 1
SEROUT 14, 84, [noparse][[/noparse]$80, 0, 0, 120]
SEROUT 14, 84, [noparse][[/noparse]$80, 0, 2, 120]
SERIN 7, 16468, 20, forward, [noparse][[/noparse]WAIT ("!"), x.HIGHNIB, x.LOWNIB, y.HIGHNIB, y.LOWNIB]
'at this point the code continues
Thanks
pdiefend
I am working on a robot that has BS2's as a transmitter and a receiver, and I am using SERIN and SEROUT to send the data from the transmitter and receiver. The robot is supposed to count how many times it cycles through a piece of code using the code listed below. I am almost sure that the problem is that the serin command is waiting until it receives the data instead of looping after not receiving any data. Any ideas here why the serin is waiting instead of looping back to forward the way it should?
forward:
counter = counter + 1
SEROUT 14, 84, [noparse][[/noparse]$80, 0, 0, 120]
SEROUT 14, 84, [noparse][[/noparse]$80, 0, 2, 120]
SERIN 7, 16468, 20, forward, [noparse][[/noparse]WAIT ("!"), x.HIGHNIB, x.LOWNIB, y.HIGHNIB, y.LOWNIB]
'at this point the code continues
Thanks
pdiefend
Comments
Well your instruction looks good ... although, you didn't mention which Basic Stamp? So the 20 above in the timeout could be a different amount of time?
And your list of variables and formatters that tells SERIN what to do with incoming data has me a little confussed.
What does WAIT ("!") do? Is it a formatter, or a variable? I guess I'm not familuar with that one?
Use:
SERIN 7, 16468, 20, forward, [noparse][[/noparse]WAIT ("!"), x, y]··· 'Bytes
and then refer to the high and low nibs ( x.HIGHNIB, x.LOWNIB, y.HIGHNIB, y.LOWNIB)·of the bytes elsewhere in your code as you require.
Duffer
Sometimes people misunderstand what the timeout value means. In this case, 20 milliseconds means,
20 milliseconds of quiet on the line, it times out if and when pin 7 stays at zero volts for 20 milliseconds.
NOT it times out if it does not receive a "!" within 20 ms
NOT it times out if it does not receive a "!" and 4 bytes within 20 milliseconds
If you are working with a physical layer AM radio, the transmitter usually will transmit a dummy preamble, then the "!" and the data. The purpose of the preamble is to condition the automatic gain control in the receiver, so that it will slice out the subsequent 1s and 0s correctly.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
I have tried all of the mentioned fixes also, changing the x.HIGHNIB, x.LOWNIB to just x in both the transmitter and receiver, as well as testing the clearity of the system to no avail. Any other ideas.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
Is the serial input normally coming from the radio receiver? Is it normally low when not receiving anything?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
Do you happen to have an oscilloscope?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
The reason I say this is when I was writing some code using Two card reader I had to put a pause between the two reader so it would not hang
I also had used a wait command
This maybe the same thing where its doing a do nothing ·loop to fast
I hope this helps
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
··Thanks for any··that you may have and all of your time finding them
·
·
·
·
Sam
Post Edited (sam_sam_sam) : 1/4/2010 2:53:31 AM GMT
Any ideas? I have the motor controller going directly to the Vss bus, but it doesn't help any.
Also try putting a 1000 uf cap· or larger on your power supply and see if this helps
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
··Thanks for any··that you may have and all of your time finding them
·
·
·
·
Sam
Post Edited (sam_sam_sam) : 1/4/2010 3:11:24 AM GMT
Also are using one battery for the Microcontroller and one for the Motor controller or are they the same battery
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
··Thanks for any··that you may have and all of your time finding them
·
·
·
·
Sam
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
··Thanks for any··that you may have and all of your time finding them
·
·
·
·
Sam
Solutions to this are to put a capacitor across the motors + and - lines to reduce the noise coupled to the ground line.
DEBUG "Top"
at the top of the program should distinguish those cases.
It is true that current spikes from the motor controller could reset the stamp, or they could hang up the SERIN command. A motor running with PWM may generate RF hash that the receiver might pick up either through the wires or through the air. Heavy currents for the motors should come from and return to the power supply near the regulator, and not have to flow through the breadboard.
But another point of confusion, did you say it does not work even if the motors are detached?
One thing that might help with RF hash might be to install a couple of clamp-on ferrite filters on the motor leads. (Or wrap the motor leads near the Stamp around a heavy iron washer to make a toroid choke.)
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
·It almosts sounds like the motor controller is briefly shorting the power supply. It could be related to having a Forward command overlap with a Reverse command.
·It can happen that a transistor base/gate signal is not dropping quick enough during a transition.
· I'm with Tracy and agree that the reset or hangup at SERIN have to be sorted out with appropriate DEBUG statements.
· Cheers,
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tom Sisk
http://www.siskconsult.com
·
Would it help to connect a second voltage regulator just for the motor controller (and motors still connected to battery)?
Also the Debug commands did sort out where the code was stalling. It was stalling at the serin
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com