Overactive interrupt triggering using internal pullups

Post here first, or if you can't find a relevant section!
racemaniac
Posts: 515
Joined: Sat Nov 07, 2015 9:09 am

Re: Overactive interrupt triggering using internal pullups

Post by racemaniac » Sun Dec 18, 2016 3:15 pm

Btw, just wondering how necessary it is to use interrupt on an encoder.
I started the same way on a cheap chinese rotary encoder i had, but when i noticed 1 step would trigger the interrupt over 50 times, i looked at the signal of my encoder with a logic analyzer, and there was about a 2ms gap between one line changing state, and then the other. So now i ended up just making a program that samples the pins every millisecond (and it does some debouncing by requiring the pin to have the new state on 2 consecutive reads), and it works very reliably, and it hardly taxes the processor at all, so unless your encoder can make lots of steps per second or is of far better quality than what i have, is using interrupts and all that effort in hardware debouncing really necessary?
(and in the end it's running on a timer that also generates interrupts, i confess :p)

User avatar
Pito
Posts: 1522
Joined: Sat Mar 26, 2016 3:26 pm
Location: Rapa Nui

Re: Overactive interrupt triggering using internal pullups

Post by Pito » Sun Dec 18, 2016 4:57 pm

Long time back I used to use the pic16 (DDS vfo) with the encoders in a similar way - ~4kHz interrupt, in the interrupt the encoder routine reading the enc values, inclusive acceleration, incrementing/decrementing a global var and an flag the enc was active).

Btw, 100nF @3.3V, shorted down via 0.1ohm (esr+cont res) creates a 20ns long pulse of 30A current.. (mcu clock is 14ns).
Switch current 100nF.JPG
Switch current 100nF.JPG (53.74 KiB) Viewed 356 times
The average energy dissipated during the 20ns is around 40 Watt..
Pukao Hats Cleaning Services Ltd.

User avatar
Pito
Posts: 1522
Joined: Sat Mar 26, 2016 3:26 pm
Location: Rapa Nui

Re: Overactive interrupt triggering using internal pullups

Post by Pito » Sun Dec 18, 2016 6:50 pm

Considering 2x 100mm long flying wires (2x 100nH) the situation would be (assuming 1ns edges of the driving pulse):
Switch current 100nF 200nH 0_1ohm.JPG
Switch current 100nF 200nH 0_1ohm.JPG (81.29 KiB) Viewed 352 times
Pukao Hats Cleaning Services Ltd.

User avatar
RogerClark
Posts: 6894
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Overactive interrupt triggering using internal pullups

Post by RogerClark » Sun Dec 18, 2016 8:31 pm

The lines to the rotary encoder are actually quite short, and relatively thick wire.
Picture 21.jpg
Picture 21.jpg (110.52 KiB) Viewed 344 times
Encoder is in top right of picture. Push button connections are on the right, the encoder outputs are on the left with centre ground.
Caps are soldered to the back of the encoder. The cap in the middle is the one for the push button part, the two outer caps are for the A and B outputs from the encoder.

However I agree that it must be making a considerable spike that is feeding back into the power rails, by modulating the GND.

The bigger problem is my FET output, that drives a solenoid, as that is causing triggering on the rotary input as well.
I doubt that the pickup is RF with such sort wires which are not near the rotary encoder.

More likely, because the whole unit is being fed from an external PSU about 2m, that the supply voltage is dropping when the solenoid is turned on, (or possibly when the supply bounces back when the FET turns off)
I have a flyback snubbing diode inside the box, which is in parallel with the solenoid output, so I don't think its a flyback issue.

I think the internal pullup's are just too weak in this high noise environment.

(BUt I agree I should have a resistor in series with the encoder as well, rather than the 100nF being shorted by the encoder.

User avatar
mrburnette
Posts: 1803
Joined: Mon Apr 27, 2015 12:50 pm
Location: Greater Atlanta
Contact:

Re: Overactive interrupt triggering using internal pullups

Post by mrburnette » Mon Dec 19, 2016 1:26 am

I think the internal pullup's are just too weak in this high noise environment.
The rule-of-thumb for pull-up/pull-down is 10K. I doubt this would eliminate your issue.
- Poor input DC source over long length,
- Plastic enclosure
- FET + solenoid inductive load

I would minimize the voltage stability by use of a 1A DC-DC
Caps should be low ESR caps, tantalum preferred
Use ferrite filters between Maple and FET

You can probably live with the plastic box but do use ground strapping between common ground and the DC-DC The reference.

Ray

User avatar
ahull
Posts: 1597
Joined: Mon Apr 27, 2015 11:04 pm
Location: Sunny Scotland
Contact:

Re: Overactive interrupt triggering using internal pullups

Post by ahull » Mon Dec 19, 2016 1:43 am

How much current does the solenoid draw? What FET are you using? High or low side switching? What diode did you use? Is the diode fried?
- Andy Hull -

User avatar
RogerClark
Posts: 6894
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Overactive interrupt triggering using internal pullups

Post by RogerClark » Mon Dec 19, 2016 2:34 am

Hi Andy,

Solenoid this this one

http://www.ebay.com.au/itm/WS-2X-5-6lbs ... 2245433151

Its supposed to be 12V but normally run it from 6V as it produces enough magnetism at 6V, however sometimes I need to use 9V.

FET is 2N7000 which is rated at 200mA continuous and 500mA when pulsed. And I'm only turning the FET on for 5mS and then off for 350mS.

The solenoid has a DC resistance of 50 Ohms, so at 9V the max current drawn should be inside the spec for the FET

Flyback diode is a 1n4148 - I could be blown, but I don't have the unit exhibiting the problem (long story)

I have a partially built backup unit (the one I took a photo of) so I will need to add the solenoid and FET etc and attach my scope and see what's going on !

But as the problem of miss triggering seems to be caused purely by pressing the push button on the rotary encoder and not purely by the FET and the solenoid, I think the main cause is just that the internal pullup's are "weak" as described in STM's on docs.

I won't use the internal pullups again for any real world products which involve interrupt inputs, as it looks like the changes of miss triggering due to supply noise is too high.

stevestrong
Posts: 1604
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

Re: Overactive interrupt triggering using internal pullups

Post by stevestrong » Mon Dec 19, 2016 9:37 am

RogerClark wrote:BUt I agree I should have a resistor in series with the encoder as well, rather than the 100nF being shorted by the encoder.
Indeed, I think this is important. One resistor at supplying the encoder would maybe suffice.

roffey
Posts: 10
Joined: Tue Sep 27, 2016 8:02 am

Re: Overactive interrupt triggering using internal pullups

Post by roffey » Fri Dec 23, 2016 11:07 am

I don't know if this will be helpful or not, but I was having issues with using multiple ints when dealing with 6 button switches plus a couple of bcd switches. I have never really been a fan of edge triggered ints in possibly noisy environments. Can be a pain.
I ended up running all the 'commons' through the base of an npn, and using just one line as the int. The base and collector lines were decoupled and I only had to deal with that one edge input.
Ok, it meant a scan at the int time to see what was active, but it certainly allowed me to tailor the circuit to my needs.

User avatar
RogerClark
Posts: 6894
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Overactive interrupt triggering using internal pullups

Post by RogerClark » Fri Dec 23, 2016 7:23 pm

I think the important lesson for me, is that the internal pullup is very weak.
Possibly as high as 50k, and is probably only useful on inputs between devices on the same PCB.

I should have not tried to use the internal pullup for any external connections, as the lightlyhood of false triggering is too hig.

Post Reply