Author Topic: Normally Open Rotary Encoder? [SOLVED]  (Read 5908 times)

0 Members and 1 Guest are viewing this topic.

Offline jtsylveTopic starter

  • Contributor
  • Posts: 14
  • Country: us
Normally Open Rotary Encoder? [SOLVED]
« on: August 06, 2018, 12:46:55 am »
I'm working on a project that uses a rotary encoder with an ATTiny85.  I'm using the internal pull up resistors on the MCU to keep things simple.

My issue is that the rotary encoder I'm using seems to default to closed, so the pins are being pulled down to ground.  This leaves me with around a 280 µA current draw when everything is shut down.  I can reduce that to about 265 µA if I put a 1K resistor between the encoder and ground (see below).



If I leave the encoder's ground pin floating the MCU only pulls around 76 µA when sleeping.  Are there rotary encoders that are normally open?  I know that means my output waveforms would be inverted, but that's easily dealt with.  It would be nice to have the idle power savings.

« Last Edit: August 06, 2018, 09:30:47 pm by jtsylve »
 

Offline JS

  • Frequent Contributor
  • **
  • Posts: 947
  • Country: ar
Re: Normally Open Rotary Encoder?
« Reply #1 on: August 06, 2018, 01:33:49 am »
Do the pwm work with pin set as input? In arduino setting a pullup is the same as digitalWrite High to an input. You cpuld use a low value input and only have the timer on and the rotary encoder draining less current.

I've seen some pretty common encoders wich are normally open in the detents.

You could pottentially use an stepper motor as encoder, it doesn't need any pullup as it generates it's own voltage while apinning, the problem with it is the voltage depends on the speed so you need to do something about it and wouldn't work too slow. You could use a comparator to sense it with lower levels but at least you need to limit the voltage going to the micro in some way. So much for the simplicity of the internal pullups.

An easier half solution would be to leave only one pullup while sleeping, as it senses a movement the other comes on, you miss the first movement but the idle current will be about half.

JS

If I don't know how it works, I prefer not to turn it on.
 

Offline Peabody

  • Super Contributor
  • ***
  • Posts: 2041
  • Country: us
Re: Normally Open Rotary Encoder?
« Reply #2 on: August 06, 2018, 02:52:26 am »
The PEC11L and PEC11R  encoders are open at detents provided the pulses per revolution equal the detents per revolution.  In fact I think the great majority of encoders are open at detents.

Here are the Bourns mechanical encoders:

https://www.bourns.com/products/encoders/contacting-encoders

In the datasheets, look for a diagram called Quadrature Output Table.  It will show you where the detents are for pulse=detents encoders.

« Last Edit: August 06, 2018, 03:04:49 am by Peabody »
 
The following users thanked this post: jtsylve

Offline jtsylveTopic starter

  • Contributor
  • Posts: 14
  • Country: us
Re: Normally Open Rotary Encoder?
« Reply #3 on: August 06, 2018, 03:22:45 am »
The PEC11L and PEC11R  encoders are open at detents provided the pulses per revolution equal the detents per revolution.  In fact I think the great majority of encoders are open at detents.

Right, that's my problem.  Ideally I'd want the opposite, where most of the time the circuit is open, except for at the detents (pulses when the encoder is being turned).
« Last Edit: August 06, 2018, 03:25:57 am by jtsylve »
 

Offline KL27x

  • Super Contributor
  • ***
  • Posts: 4108
  • Country: us
Re: Normally Open Rotary Encoder?
« Reply #4 on: August 06, 2018, 04:50:52 am »
Can you set the pins as output low (or turn the pullups off) before going to sleep, and wake the micro some other way? I mean, if you already had to press a power button, anyway, that would be eezy peezy.
« Last Edit: August 06, 2018, 04:57:34 am by KL27x »
 

Offline jtsylveTopic starter

  • Contributor
  • Posts: 14
  • Country: us
Re: Normally Open Rotary Encoder?
« Reply #5 on: August 06, 2018, 05:12:52 am »
I think I'm looking at the problem the wrong way.  The internal pull-ups are only about 50K.  Since the input pins in the MCU are high impedance, I think I'll try a higher value external pull-up resistor (and lower value cap).  I'm hoping that should reduce the idle current while it's being constantly pulled down.  I'll try it in the morning.
 

Offline hamster_nz

  • Super Contributor
  • ***
  • Posts: 2803
  • Country: nz
Re: Normally Open Rotary Encoder?
« Reply #6 on: August 06, 2018, 05:24:59 am »
I think I'm looking at the problem the wrong way.  The internal pull-ups are only about 50K.  Since the input pins in the MCU are high impedance, I think I'll try a higher value external pull-up resistor (and lower value cap).  I'm hoping that should reduce the idle current while it's being constantly pulled down.  I'll try it in the morning.
That sounds like a much better idea!
Gaze not into the abyss, lest you become recognized as an abyss domain expert, and they expect you keep gazing into the damn thing.
 

Online MarkF

  • Super Contributor
  • ***
  • Posts: 2555
  • Country: us
Re: Normally Open Rotary Encoder?
« Reply #7 on: August 06, 2018, 05:31:17 am »
The PEC11L and PEC11R  encoders are open at detents provided the pulses per revolution equal the detents per revolution.  In fact I think the great majority of encoders are open at detents.

Right, that's my problem.  Ideally I'd want the opposite, where most of the time the circuit is open, except for at the detents (pulses when the encoder is being turned).

The PEC11 Encoders are normally-open contacts.  The contacts close when the shaft is rotated.
Here is the suggested circuit from the PEC11 datasheet.  It includes the pull-up resistors and a noise filter. 
I highly recommend it as it worked the best for me.  And do not use the ATTiny internal pull-ups.
 
The following users thanked this post: jtsylve

Offline jtsylveTopic starter

  • Contributor
  • Posts: 14
  • Country: us
Re: Normally Open Rotary Encoder?
« Reply #8 on: August 06, 2018, 06:11:27 am »
The PEC11 Encoders are normally-open contacts.  The contacts close when the shaft is rotated.

Ah!  My mistake.  I read the Quadrature Output Table wrong (something about off being up on the square wave didn't click despite the labels...).

I picked up these guys, which seem to be normally closed: https://www.mouser.com/datasheet/2/54/ec09-777790.pdf.  I'll order some others now that I know what I'm looking for.
 

Offline jtsylveTopic starter

  • Contributor
  • Posts: 14
  • Country: us
Re: Normally Open Rotary Encoder?
« Reply #9 on: August 06, 2018, 09:30:23 pm »
Thanks everyone for your help.  Here's my new circuit:



It now pulls only 15 µA when the encoder is closed and about 0.7 µA when open.  The signals are all nice and clean.  I could probably get that 15 µA down even further, but I don't have any higher value resistors and the caps are already pretty low value.  I figure it won't matter much when I get new encoders that are normally open, since then I'll only have to deal with 15 µA spikes instead.  It still pulls about 800 µA when the reset button is pushed, but that seems to be what's required to overcome the internal pull-up on the RESET pin.
 

Online MarkF

  • Super Contributor
  • ***
  • Posts: 2555
  • Country: us
Re: Normally Open Rotary Encoder? [SOLVED]
« Reply #10 on: August 06, 2018, 11:35:54 pm »
You are still missing the series resistors between the encoder and the capacitors.
The missing resistors and the capacitors form the RC Low Pass filter with a cutoff frequency of:

   FC = 1 / (2 * pi * R * C)
      = 1 / (2 * 3.14159 * 10000 * 10.e-9)
      = 1592 Hz

with the suggested values in the datasheet.
The shaded area on the circuit is the filter.

Also, the RESET line should have a pull-up to 5V just like encoder A and B pins.  Capacitor C4 is probably not needed.
If you are using the internal pull-up for the RESET line, then you do not need R3.
« Last Edit: August 07, 2018, 12:47:28 am by MarkF »
 

Offline jtsylveTopic starter

  • Contributor
  • Posts: 14
  • Country: us
Re: Normally Open Rotary Encoder? [SOLVED]
« Reply #11 on: August 07, 2018, 01:57:55 am »
I tried the suggested circuit from the data sheet and it drew over a microamp.  I'm pretty new at circuit design (I'm a Computer Scientist trying to learn more about hardware), so please be patient with me as I'm still learning.  Let me spell out my thought process and I'd be very interested in pointers to where my logic is wrong.  Also this has all been tested experimentally and it works.



Here the encoder contact is closed and current flows from 5V -> R1 -> A -> C -> GND.  R1 is needed to limit current.  5 V / 640000 ohm =
7.8125 microamps.  This is much better than the 500 microamps with the suggested 10K setup.  (There's also additional current flow from the ATTiny -> A -> C which is not pictured)

You are still missing the series resistors between the encoder and the capacitors.



Here the encoder contact is open and current flows from 5V -> R1 -> ATTiny.  R1 and C1 form a low pass filter.  Adding another series resistor would just change the frequency.  We've already got 1 / (2 * pi * (680000 ohm) * (680 picofarads)) = 344.193216 hertz, which should be sufficient to stop bounce.

Also, the RESET line should have a pull-up to 5V just like encoder A and B pins.  Capacitor C4 is probably not needed.
If you are using the internal pull-up for the RESET line, then you do not need R3.



I'm using the internal pull-up for the RESET line (as it can't be disabled AFAIK).  When the switch is closed current flows from the RESET pin -> R3 -> S1 -> S2 -> GND.  R3 is there to limit the current.  I'd rather a higher value, but experimentally this is what worked (higher values prevented the pin from pulling down).

C4 is intended to be another RC filter to prevent bounce.  Although now that I'm stepping through this I think it's misplaced.  With it how its drawn instead, it should form a low pass filter.
« Last Edit: August 07, 2018, 02:00:24 am by jtsylve »
 

Online MarkF

  • Super Contributor
  • ***
  • Posts: 2555
  • Country: us
Re: Normally Open Rotary Encoder? [SOLVED]
« Reply #12 on: August 07, 2018, 03:32:12 pm »
I can not find your reasons for wanting to use these insanely low current levels.  Just looking at the circuit sideways would be enough to inject noise and cause erroneous input. :scared:

The internal pull-up resistors in MCUs are considered "weak" pull-ups.  I would consider these values as the upper limit (i.e. lowest current) to design for.  And ONLY if the encoder is very close to the ATTiny.  The ATTiny's internal pull-up resistors are in the range of 20K to 50K for I/O pins.  I recommend you stay within 1K to 50K for 5VDC pull-ups. 

The larger your pull-up resistors are the larger the chance of spurious noise getting into your circuit.  Remember with normally-open contacts on the encoder, you should only see current draw when the shaft is turned or the button pushed.  The standby pull-up current with "no encoder activity" should be minimal.


Your design for the RESET switch is forming a voltage divider between R3 and the internal pull-up of about 40K. See attached. 

   VPIN = VCC * (R / (RPU + R))

When the switch is closed the voltage on the RESET pin will be about 1.5V with R3=20K.  Very close to the threshold voltage of 0.3*VCC for the "low" state.  I would not use R3.  If anything, add a pull-up resistor to increase the current.
« Last Edit: August 07, 2018, 03:45:47 pm by MarkF »
 
The following users thanked this post: jtsylve

Offline jtsylveTopic starter

  • Contributor
  • Posts: 14
  • Country: us
Re: Normally Open Rotary Encoder? [SOLVED]
« Reply #13 on: August 07, 2018, 06:42:34 pm »
I can not find your reasons for wanting to use these insanely low current levels.  Just looking at the circuit sideways would be enough to inject noise and cause erroneous input. :scared:

Well there's an example of my limited academic understanding of design.  I was over-optimizing for power because "why not?" and because I accidentally bought encoders that have normally-closed contacts.  I hadn't even considered the practical implications of noise on the system.  Thank you for that, and for taking the time to explain it to me.

When the switch is closed the voltage on the RESET pin will be about 1.5V with R3=20K.  Very close to the threshold voltage of 0.3*VCC for the "low" state.  I would not use R3.  If anything, add a pull-up resistor to increase the current.

That explains why increasing the value of R3 prevented the RESET from triggering!  That makes total sense.

Other than my issues with the RESET circuit and the values of the passive components I've chosen, was my analysis in my last post correct?  I still do not understand the need for the additional series resistor on the encoder that you and the data sheet suggested.  They don't seem to make sense to me when connected to a High-Z input.
 

Online MarkF

  • Super Contributor
  • ***
  • Posts: 2555
  • Country: us
Re: Normally Open Rotary Encoder? [SOLVED]
« Reply #14 on: August 07, 2018, 07:23:00 pm »
Other than my issues with the RESET circuit and the values of the passive components I've chosen, was my analysis in my last post correct?  I still do not understand the need for the additional series resistor on the encoder that you and the data sheet suggested.  They don't seem to make sense to me when connected to a High-Z input.

The capacitor in your circuit is discharged (i.e. shorted to ground) when the encoder pin is closed.  The capacitor is charged through the pull-up resistor when the pin opens.

The capacitor in the suggested datasheet circuit is discharged through the series resistor to ground when the encoder pin is closed.  The capacitor is charged through the pull-up resistor + the series resistor when the pin opens.  I will need to think about the frequency cutoff calculation.  I probably did that wrong now that I'm looking at it.
 
The following users thanked this post: jtsylve

Offline Peabody

  • Super Contributor
  • ***
  • Posts: 2041
  • Country: us
Re: Normally Open Rotary Encoder? [SOLVED]
« Reply #15 on: August 07, 2018, 10:33:52 pm »
jtsylve, except for one pullup resistor, somewhere, all of the rest of the circuit is an attempt to defeat switch bounce.  I think your circuit actually would work pretty well when the switch goes from open to closed, and as the rotating contact is dragged against the conducting surface connected to ground as the knob is turned.  Since the capacitor discharges immediately when the switch is closed, but only charges slowly if the contact is temporarily broken, you are less likely to have the line actually go high during bouncing.

But at the other transition things aren't so good.  When the switch goes from closed to open, even the slightest contact will result in an immediate low.  Bounce is less likely to occur in the first place at this transition because the rotating contact is being dragged onto a non-conducting surface, so it can bounce all it wants to physically without causing any electronic bounce.  But there can still be some flutter as the rotating contact leaves the conducting surface.

But typically designers try to choose similar delays at both transitions, which is why everyone wants you to include some series resistance when the rotary switch is closed.

Not to complicate your life, but I think increasingly the modern practice is not to include any hardware debouncing (no capacitors), but rather depend on software to defeat any bouncing that occurs.  This approach saves on the BOM and on board space, and the software routines have actually become quite good at dealing with bounce.  I don't think you've said how you're reading the encoder state, whether you are polling at regular intervals or letting the encoder lines generate interrupts, but both methods can work quite well with no hardware debouncing.  One approach to this is discussed in my Github repository on this subject.

https://github.com/gbhug5a/Rotary-Encoder-Servicing-Routines

As far as power consumption is concerned, if you are using the internal pullup resistors, remember that you can turn them on just before you read the pins, and turn them off immediately after, so you would use almost zero power. Of course that's for polling only.  For pin interrupts, they would have to be enabled all the time.  Either way, I think you really do need to get one of the open-at-all-detents encoders, like the PEC11's, and make sure
pulses equals detents.

 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf