*OBEX* Quadrature Decoder help (SingleQuadDecoder)
TC
Posts: 1,019
Hello all
For my reflow oven I have decided to use an encoder to select through the menus, and to change things. I an using Luke Haywas's Quadrature Decoder object. I like the object because I only need to worry about one encoder (since that is all I am using). But the only problem I am having with it is, it adds/subtracts 4 for each detent of my encoder. I would like to have it add/subtract 1 per detent. I have tried (and works);
That works, But I have to do that for each menu, and I have to add that in every "repeat" that uses the encoder.
I am wondering, does someone have a better, more efficient option?
Thanks
TC
*** ALSO *** I know I should be using "longs" for my variables, but I don't need a larger value than a "byte" (range 0 to 9). And the QuadDecoder object works with "bytes"
For my reflow oven I have decided to use an encoder to select through the menus, and to change things. I an using Luke Haywas's Quadrature Decoder object. I like the object because I only need to worry about one encoder (since that is all I am using). But the only problem I am having with it is, it adds/subtracts 4 for each detent of my encoder. I would like to have it add/subtract 1 per detent. I have tried (and works);
VAR byte EncoderVariable ' Where QuadDecoder stores value byte EncoderDivided ' Converted encoder value PUB EncoderConvert EncoderDivided := EncoderVariable / 4 #>0 <#9
That works, But I have to do that for each menu, and I have to add that in every "repeat" that uses the encoder.
I am wondering, does someone have a better, more efficient option?
Thanks
TC
*** ALSO *** I know I should be using "longs" for my variables, but I don't need a larger value than a "byte" (range 0 to 9). And the QuadDecoder object works with "bytes"
Comments
Notes:
-- expects A and B pins to be contiguous
-- works with longs so that you can have negative values
-- .start() method has a true/false detent setting, as well as range and preset values
It sound like the object you're using is not setup to accommodate detented encoders (which have delta of four per detent). The object I've attached allows you to specify what type you have and handles the math in and out. If you look at my object, when you specify detented, values are multiplied by four on the way in, then [sign] divided by four on the way out; it's transparent to the user.
Funny story: I got a call from a Nuts & Volts reader who used this object with an LCD to create a growing lights timer. As he worked in the entertainment industry, I jokingly asked what he was growing. His response, "Uh........... tomatoes!" to which I replied, "Are those medical tomatoes!" which caused him to burst out laughing. In his project used just one encoder object and when moving to another selection he would simply restart the object using the preset parameter with the value (with upper and lower limits) he was now going to adjust. As it takes less than a millisecond to (re)start a cog, this worked really well.
By the way... use longs unless you're doing something that specifically requires bytes (e.g., serial buffer). The long is the native data type; other types require more work under-the-hood.
I haven't looked at the object Jon posted, but I bet my objects are pretty similar since they're based on his SpinZone articles.
I was very surprised to find Kye's encoder object in the OBEX is flawed. It's possible to increment the encoder value by just wiggling an encoder. It shouldn't be possible to trick an quadrature encoder into "thinking" it's rotating when it's not.
I mention being surprised since Kye's objects are generally very well done.
Thank you so much, that works great. I like that I can set the value without stopping and restarting the object. Not all of my menus have 9 selections. I am using this so the menu selections can rotate.
And thank you for the info about using longs, I had no idea there is more work to use anything else. I will continue to use longs. unless I have to.
@Duane Degn
Thank you for the link, I am going to study the posts more closely to see if I can get any great ideas. And I like Kye's encoder object. I am planing on using it later on when I make an auto angle set for my table saw and my 3D printer. They will be using optical encoders that do not have detents, and every change of the encoder must be accounted for.
That's probably an application where Kye's object could get you into trouble. There's a link to discussion about the glitch in the thread I linked to above.
That object has been around a while and deserves an update. When that happens I will add a roll-over/roll-under feature. I will also allow the pins more freedom (so that one is not force to use contiguous pins in a particular order).
That would be a great idea. If I may make a suggestion, for my menus (only example) I have different menu selections. Some have 5 selections, some have 3, and changing values I am changing one digit at a time, so that would be 0 to 9. Maybe a way to change the hi and lo on the fly?
Also, if I could find a knob for this encoder that I like PEL12T-2.pdf, I would be using it. A RGB encoder would add some cool factor to my reflow oven. Again just an idea for you, maybe a way to do a PWM to control the RGB led's, from the encoder object.
No, I'm not going to go that far -- just restart the object with the value from the variable you want to update and its limits. As it takes less than 1ms to re-start the cog, this is the best approach for HMIs.
Not going to do that, either -- pwm should be handled separately.
Or YOU could write and post that object!