Advice for monitoring state of 4 leds?
stampinator
Posts: 18
Hi everyone,
I have a circuit with 4 LEDs that have various modes of flashing that they do. I've got the basic stamp 1 wired up to monitor them, and am trying to come up with the best way to detect when they enter a specific mode.
The LEDs do the following:
* individually blink at a rate of ~125ms
* individually can become solid, once all 4 are solid, they all reset to blinking at ~125ms
* alternate on state amongst themselves: 1..., .2.., ..3., ...4, (repeat)
* blink slowly and increase in speed over a 5 second period (1000ms all the way down to 0ms)
* turn off for 3 seconds, and then resume whatever they were doing previously
What I am trying to do is detect when at least one LED has become solid, and then all 4 leds are blinking at ~125ms. And this is where I am a little unsure of how I should tackle this. In order to ensure I am seeing the correct state, I basically need to have the basic stamp look for a LOW over all 4 LEDs, and then look for a HIGH over all 4 leds in under a 125ms period, and I probably need to repeat this like 3 times to verify it's the 125ms state and not one of the other states.
Does anyone have any suggestions on how I should proceed with this?
Thanks.
I have a circuit with 4 LEDs that have various modes of flashing that they do. I've got the basic stamp 1 wired up to monitor them, and am trying to come up with the best way to detect when they enter a specific mode.
The LEDs do the following:
* individually blink at a rate of ~125ms
* individually can become solid, once all 4 are solid, they all reset to blinking at ~125ms
* alternate on state amongst themselves: 1..., .2.., ..3., ...4, (repeat)
* blink slowly and increase in speed over a 5 second period (1000ms all the way down to 0ms)
* turn off for 3 seconds, and then resume whatever they were doing previously
What I am trying to do is detect when at least one LED has become solid, and then all 4 leds are blinking at ~125ms. And this is where I am a little unsure of how I should tackle this. In order to ensure I am seeing the correct state, I basically need to have the basic stamp look for a LOW over all 4 LEDs, and then look for a HIGH over all 4 leds in under a 125ms period, and I probably need to repeat this like 3 times to verify it's the 125ms state and not one of the other states.
Does anyone have any suggestions on how I should proceed with this?
Thanks.
Comments
Since you are using a BS1 and its programming is limited, this will be challenging but not impossible. I wrote a small test program that catches when all 4 LEDs are steady and releases when they start blinking again, but it will take some changes to catch the first LED going steady.
They are on the playfield of a pinball machine.
> How do you want to indicate when the pattern you want to detect has occurred? What are you using this for?
Basically I will be energizing a solenoid when the pattern is detected...
After more thought, I think I just need to experiment with how many cycles fit into a 125ms period, and once I have that close then I can just use a counter to determine if I should be looking for a low vs. high, repeat that 2-3x and then theoretically would be good to go.
THEORETICALLY!!!!!!!!
and the text output for counter happens incredibly slowly.. slower than the rate the leds I want to track are flashing....... So this tells me that debugging to the console is not an accurate way to figure out my timing issues.. Looks like I am going to have to start blinking an LED of my own to figure this out.
Should have something for you soon...
IIRC, DEBUG slows down the BS2 significantly as well.
True, but not nearly as much as the BS1. The DEBUG in the BS1 sends the entire RAM memory to the PC at 4800 bps, which can really knock timing off. At least in the BS2 it only sends what you specify in the DEBUG statement when it is encountered at 9600 bps.
http://www.parallax.com/Portals/0/Downloads/docs/cols/nv/vol7/col/NV131.pdf
There are a few parameters you can set. From the top, DELAY specifies how long to wait between loops. Not knowing for sure how fast your inputs are flashing, this may be too high. Adjust up or down to suit. The next, LIMIT, is how many passes through the test the LED has to be ON before the alarm is set. If you lower DELAY you probably should raise LIMIT. You want DELAY low enough to catch the quickest flashes, and LIMIT to be high enough at that DELAY setting to ignore the longest flashes. ALARM is just the pin you want to make HIGH when the event occurs. There are some hard-coded values in the LOOKUP statement that assume the input pins are P0-P3. They are also assumed to go HIGH when the LED is ON. If you wired it up differently, let me know because changes will be necessary.
Disclaimer: Since I don't have a nifty pinball machine like you do, I couldn't fully test this. But I think it will work.
In the meantime, I was working on my own experimentation and am TOTALLY confused........ check out the attached program. I am simply repeatedly looking to see if I receive a low and a high multiple times within a period of time. I have a test LED rigged up to go off when the "fire_coil" method is called... So my plan was to test this out by tapping pin4 with 5v rapidly and see the led go off...
However, just by applying power, the led goes off.. And so I threw in some debug statements to tell what was going on, and it appears that the "increment_high" method is being called regardless of the fact that there is no 5v going to it!!!!!! WTF?!?!!
The debugger shows:
?!??!!??!?!!?!?
Why is this happening? Why in the world is high_count incrementing? Seems like total nonsense.
Do you have a pull down resistor on pin 4? I'm betting not.
In post #3 of my index (see signature) there's a link to a tutorial on how to use code tags. Code tags preserve indentation and make code easier to read.
I commented out two lines of code which I'm pretty sure aren't needed. Since if the pin isn't high, you can assume it's low and the program flow will continue on to "increment_low" without any intervention required.
You're just testing to see if pin 4 isn't continuously high or low right? You're checking to make sure not all 200 loops where all high or all low?
Does the BS1 really dump the entire RAM with each debug statement?
Edit: I just looked at Sapphire's code. It has an example of letting the code flow after an "if" statement who's condition isn't met.
The code is only directed to the "Off" section. The "On" section is reached by default.
(Sorry, these comments about programming style don't really help in your efforts to monitor LEDs.)
I don't... Do I need one?
I was simply trying to test that if a high AND a low on pin 4 is detected multiple times within 200 loops, then light up my test LED to prove that it's working... It makes absolutely no sense to me why high_count increments, regardless of the lines that you commented out. It should only be incremented if it actually sees a high, and there is no 5v being applied to the pin, so the fact that the output shows high_count going up, is total nonsense and makes me question how anything is going to work at all.
You'll see either "PIN4 = 1" or "PIN4 = 0" and that will let you know if PIN4 is working.
You could also test your output with this to drive PIN6 with whatever is on PIN4:
Yes.
By not letting your input pins float (not being pulled high or low). If look in the various Stamp manuals, they show how to wire a button. They'll always have the pin pulled high or low with a resistor so when the button isn't pressed the pin is in a well defined state. The button press will then switch the state of the pin. I think it would be a good idea to wire up a button to your input pin for testing.
Your basic stamp code is a little different than I've seen in the manual, so I am a wondering how some of this works.. Would you mind explaining some of your code to me?
How is this working exactly? what is PINS? a constant representing p0-p7 ? $F is 15, correct? I get that you are anding a bit representation, but I am a little confused-- and also there is no where in the program designating which pins are inputs and which are outputs-- which I thought you have to do?
is this doing:
bits = [1,2,4,8]
bit = bits[index]
as in, assign bit to one of the indices in the bits array through the index variable?
MAX means it will not increment count3 if it is higher than the limit variable? Does it goto Done regardless if count3 <=> limit ? Or is going to done only after limit has been reached?
thanks!
$F is 15 in hex notation. The & (AND) operator takes the value of PINS and returns only the lowest 4 bits. The upper 4 bits are zero. Turns out this operation isn't necessary, I had it in there in the first version which was doing a differrent kind of check that needed to ignore the high bits. With the current program it could be simplified as:
Yes, bit will be set to 1,2,4,8 for index of 0,1,2,3 respectively.
Yes, MAX limits the count to LIMIT. GOTO always goes to Done regardless of the count.
How big of a resistor do I need to qualify as a "pull down?"
Also, post a schematic of how you wired in the LEDs from the pinball machine. You may not need pulldown resistors depending on where you are getting the inputs from.
Here are the schematics...
The LEDs I am hooking into are 17-20. My plan was to just go from the BS1 pins directly to where the diodes are in the circuit.
Can you find a drawing like the first one for the lights? You'll need that to determine how they are driven, what the voltage is on the LEDs and where you are going to tap into the circut. And you need to find out if they are multiplexed as that could affect how they are monitored.
Oops.. sorry, yeah I attached the wrong one! Here is the one with the lamps...
So they read approx ~6.6v when they are on solid... And 1.9v when they are blinking--- Which is my volt meter getting an average of the rapid on/off I guess..
What does this mean? Well for one, directly connecting them to the BS1 won't work, because the stamp could read the input between strobes and think they are off when to your eye they are on steady! Also, 6.6v is too high for the stamp, and it's actually probably a bit higher than that due to the multiplexing. You will need to build an interface circuit that taps the 4 lights you want, buffers them, reduces the voltage, and extends the on-time to cover the strobe so the BS1 sees a clean on or off condition. This could be done with hardware (opto-isolators, inverters, resistors and capacitors). One thing your going to need to find out is the multiplex rate. Do you have an oscilloscope?
And yes, I'm familiar with Westwood. I grew up in Westchester.