waitpeq with multiple pins
Sariel
Posts: 182
I have looked around the old posts for a way to do this, and It seems not possible. has anyone figured out a way to use waitpeq with 2 inputs. Furthermore, can one use inputs stored as a variable do this? I was thinking of doing an XOR on the two, then making that the subject of waitpeq. I have tried this, but it seems to not do it's job:
Obviously, there is a lot more going on with my IO's, and I would want this line to make sure that the pins drop low, then continue on... I know I may be a bit confused, but at the end of this all, I would like to use this as a way to debounce 2 switches at once. Timing is a bit odd in my application, and using the standard waitcnt method of debouncing is not working right for me.
CON '' Clock settings _CLKMODE = XTAL1 +PLL16X _XINFREQ = 5_000_000 LeftSW = 23 ' actuator connections RightSW = 18 VAR long XORstuff PUB Main XORstuff := LeftSW ^ RightSW waitpeq(|< XORStuff, |< XORStuff, 0) ' <rest of program here>
Obviously, there is a lot more going on with my IO's, and I would want this line to make sure that the pins drop low, then continue on... I know I may be a bit confused, but at the end of this all, I would like to use this as a way to debounce 2 switches at once. Timing is a bit odd in my application, and using the standard waitcnt method of debouncing is not working right for me.
Comments
I wrote this bit of code as a quick example.... will post the real code in a sec. have to go to the other computer (and I see where waitpne is more appropriate for this)
JonnyMac: I am a bit confused by your example. How can that monitor 2 pins at once?
Champ Tracker v304 - Archive [Date 2012.01.19 Time 13.21].zip
So, you can wait for all 32 pins if you want ...
Yeah... MagIO2. that looks about right, and I think I understand what is going on with it. But alas, it is still not behaving. I think the machine I am interfacing to has a really screwy sense of timing, and my device is still missing some cycles. Now would be a good time to have an o'scope and be able to time it out better. I thought waiting for pin states would work better than an arbitrary pause, but this idea is falling apart too.
Sorry I was a little sparse -- thankfully, others gave you what you needed. That said... the Propeller manual is your friend (and available as a PDF from the IDE). If you read about WAITPEQ and WAITPNE you will find that you can monitor any number of IO pins with either.
www.hannoware.com
The way to combat this is to wait for your first transition, pause for an amount of time large enough to let the mechanical transition happen, then wait for your next state change. This is called "debouncing" and it's a very common thing to have to do in code that deals with mechanical switches.
(Disclaimer - I haven't looked at your code, so I'm kinda guessing here)
Yeah I thought of that right at the end of shift last night, and tried to put in a pause of a few ms before the waitpeq instruction, but it was doing the same thing. As for the o'scope, I would use it to see what kind of time frame I have to catch this sensor for the left and right actuator hitting, and try to time my spin accordingly.
little more background on my device...
We have been using a prop and the display to show the operator a list of colors to be terminated on this machine:
http://www.ebay.com/itm/AMP-SCSI-Champomator-2-5-terminator-crimp-machine-/300472508897It
It has 2 pneumatic solenoids that are toggled by leaf switches. When the machine senses a wire on the left and right side (if both are to be populated) the solinoids move crimp punches to push the wire into place. those crimp punches have 12v sensors on them (full schematic in the source) that detect for it's computer that it termed sucessfully. I am interfacing to those sensors so my device knows when to advance to the next color set. Operators used to have a clip board that told them the wire number/color to use next, but that was quite time consuming. I had one working well, but it was for a single product and I had to personally change the source on the prop in order to have a new product run. It is saving so much time that I am adding in an SD card so they can load different color lists from a txt file. They look on the screen and term. much faster than scanning an excel document for every wire pair.
Another feature is that they wanted to be able to go back a step in case they grabbed the wrong pair, the machine screwed up, or whatever. I am finding that adding the few lines in to scan the up and down buttons to go forward or back is putting a bit of a delay in there, and it is now missing cycles. I am not anywhere close to being able to do this in PASM, or I would just go that route.
I think for now I am going to experiment a bit more with the delay before the waitpeq.
Oh yeah. I have been drooling over that for some time now.... I think I have the wife convinced to unleash the purse a little to get me that software for home use. Unfortunately, the boss isn't convinced yet.
1.) ina[1] references pins just like doing a "MiscVariable[1] catches the 2nd var in a group, just with bits instead of bytes, words or longs.
2.) waitpne and waitpeq are good. In the right context. This obviously was not the right context.
The architecture is making more and more sense every day.
Thank you for all of your help guys. Again, I learn so much every time I visit these forums, and even more when I talk to the Masters.
Lawson
I didn't think of it that way, but yeah, I guess it is a type of state machine. But that term has either confused me, or I am just wrong. Couldn't you classify anything as a state machine? By the link you gave, it is stated that...
It would be my view that logic gates are state machines, the propeller.... everything. That article goes on to say that even AI and Biology (I am sitting down. that is my state. but then my chair starts on fire, and I jump up, leaving me in a different state. Does that mean that I am a state machine?) to some degree can be identified as a state machine. Am I totally wrong with this, but isn't that the same thing as saying "A lemon and a tire are the same thing because they are both made of matter"?
..... not really a propeller discussion, but interesting none-the-less.
-- http://obex.parallax.com/objects/489/
Everything electronic certainly uses state machines internally. I think that much of the work surrounding state machines was done so that designing chips with thousands of gates takes less than a lifetime and performs as expected.
I guess, the finite state machine is a very general concept. It's a poor model for systems with a large/infinite number of states. I.e. a state machine for PID control would be hell to layout, much easier to just define the transfer function of the controller and directly use that. On the other hand, a digital combination lock would be easily described as a finite state machine.
The other good thing with state machines is that they don't halt execution. This property makes it easy to run several inside the same scan loop. (as long as there is time and no accidental variable name overlap) If I ever need to do more than 8 things at once on a Prop, I'll start making state machines first.
Lawson