Switches and SX
Brian Carpenter
Posts: 728
So I have 16 switches that i want to monitor with the SX48.· The switches are magnetic reed switches.· when a magnet rotates and passes near the switch it closes the switch (to ground).· I want to have 16 different Variables, one for each switch.··Each Variable will be set at 15 for instance at the beginning of the program. Each time the switch is closed (to ground) I want the associated variable to decrement by one, then send the new variable value to the PINK module where it can be seen via a web page.· My questions are
1.· Do i create a loop that just checks that status of each pin that switches are connected to?· If a change is seen, Decriment.
2. With other things that need to happen in the chip also do i just nest this loop into the rest of the program?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
It's Only A Stupid Question If You Have Not Googled It First!!
1.· Do i create a loop that just checks that status of each pin that switches are connected to?· If a change is seen, Decriment.
2. With other things that need to happen in the chip also do i just nest this loop into the rest of the program?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
It's Only A Stupid Question If You Have Not Googled It First!!
Comments
a) What is the expected time interval (frequency)·of the switches being turned on?
b) How long do you expect the switches to be in either state (ie, how long is the high period, how long is the low period)?
c) What else is being done while monitoring the switches, just sending info to the Pink module?
Nate
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
It's Only A Stupid Question If You Have Not Googled It First!!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
It's Only A Stupid Question If You Have Not Googled It First!!
With a 1/2 second "changed state" of your input (eternity to a micro controller), you can do this pretty much any way you want.· You can place a loop somewhere in your main code, as long as you are sure that the inputs are tested at intervals less than 1/2 second.
A more elegant, but more complicated-to-program solution, would be to wire the input switches as a matrix (google "keypad matrix") attached to rb (interrupt capable port).· When the interrupt is triggered, you would need to decode the port interrupt register status to determine which input was triggered.· This way you would only spend the resources looking at the input switches when there was a input event.· (But if you are using the interrupt for other timing-dependant routines, this may not be possible).
Nate
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
It's Only A Stupid Question If You Have Not Googled It First!!
Just another way to go about your idea...
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Meh. Nothing here, move along.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
It's Only A Stupid Question If You Have Not Googled It First!!
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
It's Only A Stupid Question If You Have Not Googled It First!!
So the vision is to use an older style vending machine and add electronics to it.· This machine uses a coin opperated rotary mechanism that you put your required coins into and turn the dial.· i will be installing magnetic reed switches in this mechanism with a neodym magnet attached to the rotaing part.· as the coins are validated and the mech is allowed to turn, the magnet will pass the reed switch and close the contact.· My thought is to have a variable for each switch (ie.. sw0-sw15) The variable called sw0 will be set to ,say 15 (the ammount of goods in that row) It the SX48 sees that the reed switch has made a connection then it will decrement the value to 14 and so on.· Eventually, i would like for the SX to update these variables to the PINK module and i will be able to log in and see current inventory.· Another good thought is to have the Pink send me an email if quantities drop below 3.· This may not seem like any huge project to some, but for me i work crazy long hours and am trying to learn SX/B and develop this in my wee remaining hours.· Any suggestions would be appreciated.· thanks
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
It's Only A Stupid Question If You Have Not Googled It First!!
The keypad matrix that I was thinking about was one that used an·encoder (or perhaps 2 of the '74148) to turn your switch input into a binary representation.·
Since the actual switch time that you are sensing is so long (1/2 sec. or so) it would be fine to use the canned SX/B keypad matrix and just make sure that you run the "check input status" routine at a frequency of greater than 2 Hz.
Nate
I think your SW6 should connect to RC.5 instead of RC.4 ?
Because the picture shows SW6 & SW7 both connected from RC.2 to RC.4
Other than that, looks like your on the right track.
I would not worry about using interrupts for a signal that lasts 500 milliseconds.
Have you thought about what should happen if two people try to vend different items at the same time ? I guess it could happen...
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Cheap 4-digit LED display with driver IC·www.hc4led.com
Low power SD Data Logger www.sddatalogger.com
"I reject your reality, and substitute my own." Mythbusters
·
P.S. I am looking for a sort of latching effect. ie. switch closes for a few miroseconds, but i need the bit in the byte to stay 1 until other code processes the data and sets the bit low again.... even though the pin might have already gone low. Does this make sense?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
It's Only A Stupid Question If You Have Not Googled It First!!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
It's Only A Stupid Question If You Have Not Googled It First!!
Setup one set (either the columns or the rows) to "drive", and the other set to "sense".
Enable pull-ups on the sense pins.
Loop through each of the drive pins making them LOW (others should be INPUTS).
As you make each drive pin low, check if any of the sense pins are low. If it is, the switch must be closed.
If you just want to know if ANY switch is closed, just make ALL the drive pins LOW. Then if ANY of the sense pins go low, you know a switch is closed. Then use the routine above to figure out which switch is close.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Cheap 4-digit LED display with driver IC·www.hc4led.com
Low power SD Data Logger www.sddatalogger.com
"I reject your reality, and substitute my own." Mythbusters
·