Never used a stamp! Need advice!
Archiver
Posts: 46,084
I need to come up with something and I thought one of these stamps
would work.
I'm working on a 24 vdc system. If I have to I can do something to
drop the input voltages to 12 vdc but it would be nice to stay at 24
vdc.
This project requires 4 inputs and 1 output.
Input #1 or #2 goes high then output #1 goes high immediately.
Input #1 and #2 goes low then output goes low after 5 minute delay.
Input #3 goes high then output #1 goes high after 5 minute delay.
Input #3 goes low then output #1 goes low immediately.
(Input #4 is a square wave signal from 0 hz to 5000 hz)
Output #1 goes high immediately if ANY pulses are detected.
Output #1 goes low if no pulses detected for 5 minutes.
What stamp would be the best for this any what accessories may be
useful? (I used 5 minute delays but I may need longer...whats the
maximum time I can program?)
thanks for your ideas and comments!
Fred
would work.
I'm working on a 24 vdc system. If I have to I can do something to
drop the input voltages to 12 vdc but it would be nice to stay at 24
vdc.
This project requires 4 inputs and 1 output.
Input #1 or #2 goes high then output #1 goes high immediately.
Input #1 and #2 goes low then output goes low after 5 minute delay.
Input #3 goes high then output #1 goes high after 5 minute delay.
Input #3 goes low then output #1 goes low immediately.
(Input #4 is a square wave signal from 0 hz to 5000 hz)
Output #1 goes high immediately if ANY pulses are detected.
Output #1 goes low if no pulses detected for 5 minutes.
What stamp would be the best for this any what accessories may be
useful? (I used 5 minute delays but I may need longer...whats the
maximum time I can program?)
thanks for your ideas and comments!
Fred
Comments
> I need to come up with something and I thought one of these
> stamps would work.
>
> I'm working on a 24 vdc system. If I have to I can do
> something to drop the input voltages to 12 vdc but it
> would be nice to stay at 24 vdc.
>
> This project requires 4 inputs and 1 output.
> [noparse][[/noparse]...]
> What stamp would be the best for this any what accessories
> may be useful? (I used 5 minute delays but I may need longer...
> whats the maximum time I can program?)
>
To handle the last part first, the only practical limit is your power
source. That is, the Stamp will stop if you let the battery run down, or if
wall power fails. Otherwise, the duration is pretty much as long as you
like. For example:
PAUSE 1000
will stop executing instructions for about one second. Put that in a small
loop:
FOR I=1 TO 60
PAUSE 1000
NEXT
and you have a short routine that will pause one minute. Change the '60' to
'3600' and you have a loop that will pause for an hour. But see
"accessories" below for a warning about this.
Which Stamp: The logic you describe could be managed on the simplest Stamp,
the BS1, and that model on a prototyping board is quite economical as well.
If the extra cost is not an issue, using a BS2 is probably a better way to
learn about Stamps and programming overall. But if you just want to get this
one chore done, then a BS1 on its "carrier board" should be all you need.
Except for that very non-specific "Output #1" which I discuss below.
Accessories:
1. A programming or "carrier" board. You do want to buy the Stamp with a
programming board to make your life simple. That is, don't buy the
stand-alone chip. (OEM configuration? Whatever the marketing term is...) If
you do, you have to fiddle with wirewrapping and other problems that just
aren't worth it for a one-off solution. Even if you plan fifty of these
little controllers eventually, do the prototype with a Parallax board. Buy
one of the kits, which will include all the miscellaneous tidbits you want
as well.
2. External timer chip. The next thing you need is an external timer, but
not because of the intervals you're dealing with. Five minutes or five hours
is trivial. The subtle part is that the Stamp when using "PAUSE" is timing
the interval by pausing its own execution for those time periods. That means
it is NOT paying attention to the state of the input pins. You really want
an external timer because you have events taking place that can override the
rule that started the interval. I'm thinking specifically of "Input #3 goes
low then output #1 goes low immediately." (Incidentally, you have a pretty
problem on your hands making sure that set of rules will produce the
behavior you expect. Some interesting interaction is going on there.)
In any case, timer chips are cheap and easy devices. You want to be able to
configure the timing interval in advance, or download it to the timer under
program control, and then trigger the timer with one Stamp output pin so it
raises Output 1", and then override and cancel the timer with another output
pin. Something like that is needed.
Voltage control:
Working with 24VDC is quite practical with Stamps. People do it all the
time, but you do need to limit the voltage reaching the linear power supply
chip on the Stamp board so the heat can be dissipated elsewhere. (In other
words, that regulator would handle the voltage briefly, but things would
start to get wayyyy too warm in a little while.) Any of several chips will
do this for a pittance. That takes care of the power source for the Stamp
itself.
Now the input pins. These must see TTL levels. ("Transistor-to-Transistor
Logic") That means nothing more than 5V. You're going to need external chips
to react to the changes in your 24V signals by producing 0-5 outputs. Not
difficult, but I haven't time to describe the alternatives now.
The "Output #1" signal. You need to say more before the group can help you
with this one. What are you driving with that output? Is it a pump drawing 5
amps at 24 volts? Or a logic signal drawing 50 microamps at +5? In other
words, the Stamp can raise an output pin that will drive logic that will
produce this Output #1, but that external logic needs to be designed. It
probably won't be difficult, nor is it likely to take more than one pretty
cheap part, but it does need to be tailored to whatever you're trying to
accomplish.
The merit of the Basic Stamp product family is how simple they make it to
implement a set of rules like those you posted. That universal simplicity
also means they don't include circuits on the board to do anything someone
might wish, just a couple of the common ones that almost everyone uses.
For some purposes you might have in mind for Output #1, you might want a
specialty chip that happens to offer one easy way to interface to the Stamp.
Let's say that easy interface is the I2C protocol or One-Wire or X-10. For
any of those, you save a lot of trouble by buying the BS2P, which has those
interfaces provided already. Even though the logical rules don't require
anything beyond a BS1, you would be saving a lot of effort and external
parts cost by buying the model that has the interfaces you want in order to
use a particularly well-suited chip from somebody else.
Alternatively, if you're controlling high-power devices with that output,
you want to look at the industrial control interfaces. So again, the
particular model we might advise would depend on the specifics of your
problem. Especially that protean "Output #1"<g>.
Hope this helps,
Gary
relay so using a 5vdc relay would be no problem.
Back to the timing, could I include some if statements inside the
loops so that if an input state changes I could then exit the loop?
I would have a nice mess of if, else, else if and then statements but
I would think it could work.
We have a number of Allen Bradley PLC-5 and SLC-500 controllers.
(this project will be totally seperate) I see they have a "Stamp
Controller Interface Board" Their web page states: "The Stamp
Controller Interface allows the BASIC Stamp to connect directly to
industrial type digital I/O control boards produced by Opto22,
Grayhill, Allen-Bradley, and others that accept 0-5 VDC voltage
control levels." The PDF file doesn't explain much more. Not sure
what this is going to do unless you just connect a 5v stamp output to
a 5v AB input card's input. (if thats all it does why would I need
this interface....being that the stamp already outputs a 5 vdc signal)
The Stamp PLC looks real interesting though wish it was a bit cheaper!
thanks again!
Fred
Interface Board is to REPLACE a PLC-5 on the
DIN rail, so you can control all the stuff the
PLC-5 was controlling, BUT you can do it with
a BS2, or a Javelin.
--- In basicstamps@yahoogroups.com, "fredm54_fla" <fredm54_fla@y...>
wrote:
> Great information! The output will just drive a relay. I can use
any
> relay so using a 5vdc relay would be no problem.
>
> Back to the timing, could I include some if statements inside the
> loops so that if an input state changes I could then exit the loop?
> I would have a nice mess of if, else, else if and then statements
but
> I would think it could work.
>
> We have a number of Allen Bradley PLC-5 and SLC-500 controllers.
> (this project will be totally seperate) I see they have a "Stamp
> Controller Interface Board" Their web page states: "The Stamp
> Controller Interface allows the BASIC Stamp to connect directly to
> industrial type digital I/O control boards produced by Opto22,
> Grayhill, Allen-Bradley, and others that accept 0-5 VDC voltage
> control levels." The PDF file doesn't explain much more. Not sure
> what this is going to do unless you just connect a 5v stamp output
to
> a 5v AB input card's input. (if thats all it does why would I need
> this interface....being that the stamp already outputs a 5 vdc
signal)
>
> The Stamp PLC looks real interesting though wish it was a bit
cheaper!
>
> thanks again!
>
> Fred
> Great information! The output will just drive a relay. I can
> use any relay so using a 5vdc relay would be no problem.
>
Piece of cake, if it's just a DC relay, Fred.
> Back to the timing, could I include some if statements inside
> the loops so that if an input state changes I could then exit
> the loop? I would have a nice mess of if, else, else if and
> then statements but I would think it could work.
>
No, you don't really need much complexity to do that. In fact, the more you
add the less well it works with that technique. We call that a "real time
loop" and an important measure of its performance is cycles per second. That
is, how many times per second do you examine the state of the inputs to
decide whether you need to change your course of action. I coded such a loop
when Cindy bought me a Toddler robot as a gift last year. Such a loop looks
like this:
DO UNTIL (<reason to quit>) 'See below for reasons
<check inputs>
<change the goal conditions appropriately>
<take any actions the goals require>
LOOP
<shut down or prepare for other mode of action or...>
You may never have a reason to quit the primary loop that isn't brought
about by powering off. But even in such cases, you might prefer to shut down
gracefully. Perhaps recording the state of things at shut-down in the EEPROM
memory, or what have you. You do that by making one of the inputs mean "Shut
yourself down". The Stamp controls its own power on/off in such a
configuration. A couple of app notes are available about doing that. Al
Williams made it a Project of the Month a while back.
The other three steps are fairly obvious I suppose. And this is why I said
your logic problem is straightforward. You just check each of three inputs
to decide whether you want that relay on or not. Well, three inputs in two
possible states means a maximum of eight possibilities. So you connect those
three inputs to pins 0, 1, and 2 let's say. Then you treat that nibble as a
number like this:
PinStates VAR NIB 'Declare a four bit variable
Goal VAR BIT 'Declare a one-bit yes/no variable
So checking the input states is one statement:
PinStates=INA&%0111 'Mask off the bit for pin 3 which we aren't using
and setting the goals is another:
Goal=conRuleByte>>PinStates
That uses an important coder's technique: shift a control byte right by the
number of bits given by PinStates, and take action based on whether the low
order bit position is then a zero or a one. So earlier in the declarations,
we declared a "constant" that is the set of rules for turning the output on
or off.
Have to go now, but the limitation of this technique is first how many times
per second you can check the inputs. If they changes more quickly than that,
you miss changes, so you have to "latch" the inputs. Second, it's a pain in
the whatsis to have the timing of the loop change everytime you modify the
code at all. Since external timers are so cheap, I'd personally put a 555 to
handle the five minute intervals (or whatever) and in this control loop I'd
just stop or start or eset the timer appropriately instead of counting real
time loops to come with up the interval.
By the way, I haven't time to check that syntax back there. It might a mish
mash of several computer languages typing as I think. Will check later.
Gotta go,
Gary
>
> PinStates VAR NIB 'Declare a four bit variable
> Goal VAR BIT 'Declare a one-bit yes/no variable
>
> So checking the input states is one statement:
>
>
> and setting the goals is another:
>
> Goal=conRuleByte>>PinStates
>
> That uses an important coder's technique: shift a control byte right by
the
> number of bits given by PinStates, and take action based on whether the
low
> order bit position is then a zero or a one. So earlier in the
declarations,
> we declared a "constant" that is the set of rules for turning the output
on
> or off.
>
>
> By the way, I haven't time to check that syntax back there. It might
> a mish mash of several computer languages typing as I think.
> Will check later.
>
Without actually coding this problem, the syntax looks right for a BS2.
Anything that can be programmed with PBasic 2.5. The statement
> PinStates=INA&%0111 'Mask off the bit for pin 3 which we aren't using
is masking a byte, not a nibble, so it is good practice to write it instead
as:
PinStates=INA&%00000111
but the result will be the same for now.
The point I didn't have time to make is that with this technique you
decrement a counter each time you go through the loop. If it reaches zero,
that's one more input condition to be considered and you might be better off
with 16-bit control word instead a control byte. Basically, each bit
position of that word tells you whether the relay should be on or off, and
the input conditions tell you which bit to examine. That means you as the
programmer do all the work ahead of time by making up a little table of all
the combinations of inputs and deciding whether the relay needs to be on or
off for each combination. If the bit is a one and the last time through it
was zero, then we reset the counter. Or if we have an external timer, we
reset it.
That's all I have time for again. Busy day<g>.
Good luck,
Gary
in? It's range is 0 hz and can go as high as 5000 hz. All I need
the stamp to do is if there are any pulses detected then turn the
output on (energize that relay) if there are no pulses for 5 minutes
then turn the output off.
thanks again!
ps: that adapter board can't replace a PLC5, in fact a plc5 can't
mount on a din rail. Our PLC5s have 4 i/o slots, each slot has 32
inputs or outputs, from 5 v ttl to 220 vac levels, analog in and out
and more! It must somehow interface to the PLC5.
> thanks for all the input! How would I handle the pulse train coming
> in? It's range is 0 hz and can go as high as 5000 hz. All I need
> the stamp to do is if there are any pulses detected then turn the
> output on (energize that relay) if there are no pulses for 5 minutes
> then turn the output off.
>
That's an example of an event that will be too fast to catch with a real
time loop on a Stamp. At least, you won't catch it reliably, because you
only look at the pin state during a brief interval when you test it, and the
incoming pulse may rise and fall again before you ever get back to that
statement.
We latch such signals, which means we detect them and set a latch -- a flip
flop in old-fashioned terms -- that will stay set until we reset it.
Choosing the right detector would let you latch signals that have a billion
hertz rate, like gigabit ethernet. When you come along lazily sampling the
input pin every twenty milliseconds or so, you're really looking at the
output of the latch, not the incoming pulse itself. That's okay, because the
voltage level of your inputs is too high for the Stamp pins anyway. You're
going to have to put detector circuits to reduce the level to TTL for each
of the inputs, so you might as well latch them as not. It's always good
practice when you're sampling at a rate that may be slower than the fastest
possible transition for an input.
So you do that PinStates=INA&%00000111 business (modified according to
however many pins you end up sampling) and then you clear the latches with a
statement something like:
PULSOUT LatchResetPin, 1
If you didn't clear them, of course, they'd report stale data the next time
you sampled.
Incidentally, if you latch a discrete input like a button instead of a
pulse, it can get a little trickier, depending on what the button is
supposed to tell you. Done right, a latch can "debounce" the switch. (A term
you can look up if it happens to you<g>.) But you may want to know how long
the button actually stayed depressed, not just the fact that it was
depressed at some time since the last sample. The latch is what we call
"edge" logic. It tells you whether a transition occurred at all since you
cleared it.
Knowing how long a button stayed down is called "level" logic. Measuring
things with a real time loop is limited by the resolution you get with your
sampling rate. You're probably not going to get more than fifty samples per
second, and maybe a lot less if you start adding a lot of code besides those
snippets I wrote. That would give you a resolution of one-fiftieth of a
second. Not great, but fine for many jobs. If you need more than that, you
start adding external logic to capture the pulse energy. Then you digitize
that. For example, the button being depressed can charge a capacitor. You
come along and discharge it, measuring the time that takes with RCTIME. That
isn't a design, just an example<g>. But I think latched edge detection is
all you really need if I remember those rules you posted.
Good luck, Fred.
Gary