Electronics > Beginners

Normally Open Rotary Encoder? [SOLVED]

<< < (3/4) > >>

MarkF:
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.

jtsylve:
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)


--- Quote from: MarkF on August 06, 2018, 11:35:54 pm ---You are still missing the series resistors between the encoder and the capacitors.

--- End quote ---



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.


--- Quote from: MarkF on August 06, 2018, 11:35:54 pm ---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.

--- End quote ---



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.

MarkF:
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.

jtsylve:

--- Quote from: MarkF 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:

--- End quote ---

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.


--- Quote from: MarkF on August 07, 2018, 03:32:12 pm ---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.

--- End quote ---

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.

MarkF:

--- Quote from: jtsylve on August 07, 2018, 06:42:34 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.

--- End quote ---

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.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

There was an error while thanking
Thanking...
Go to full version
Powered by SMFPacks Advanced Attachments Uploader Mod