Shop OBEX P1 Docs P2 Docs Learn Events
*OBEX* Quadrature Decoder help (SingleQuadDecoder) — Parallax Forums

*OBEX* Quadrature Decoder help (SingleQuadDecoder)

TCTC Posts: 1,019
edited 2014-03-16 11:53 in Propeller 1
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);
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

  • JonnyMacJonnyMac Posts: 9,107
    edited 2014-03-16 08:00
    I've attached an old encoder object that I wrote -- it may do the trick for you.

    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.
  • JonnyMacJonnyMac Posts: 9,107
    edited 2014-03-16 08:18
    For grins I downloaded the other object. Per what you're seeing, it's not setup to deal with detented encoders. Also, it uses wrlong to modify the encoder value so it is in fact setup for longs, not bytes. Another thing, it assumes that the value will not be modified by the application outside the encoder. My object allows this with the set method. The encoder cog actually reads the present value in the hub before adding or subtracting based on encoder movement.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2014-03-16 08:32
    I have a couple encoder object posted in this thread.

    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.
  • TCTC Posts: 1,019
    edited 2014-03-16 09:24
    @JonnyMac

    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.
        index := Encoder2.read
    
        if index == -1
          index := 4
          Encoder2.set(4)
    
        if index == 5
          index := 0
          Encoder2.set(0)
    

    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.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2014-03-16 09:43
    TC wrote: »
    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.
  • TCTC Posts: 1,019
    edited 2014-03-16 09:47
    I have not read about it yet. But I will, just have not made it to that point yet.
  • JonnyMacJonnyMac Posts: 9,107
    edited 2014-03-16 09:54
    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.


    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).
  • TCTC Posts: 1,019
    edited 2014-03-16 11:04
    JonnyMac wrote: »
    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.
  • JonnyMacJonnyMac Posts: 9,107
    edited 2014-03-16 11:39
    Maybe a way to change the hi and lo on the fly?


    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.

    maybe a way to do a PWM to control the RGB led's, from the encoder object.


    Not going to do that, either -- pwm should be handled separately.

    Or YOU could write and post that object! :)
  • TCTC Posts: 1,019
    edited 2014-03-16 11:53
    I might just do that. But at a later date. Have way to much on my plate.
Sign In or Register to comment.