Spurious pin-change interrupts with AVR DB - Page 1
Forum section: electronics / general

author: rubidium
author_rank: Regular Contributor
timestamp: May 07, 2024, 03:00:56 pm
content: I have a circuit, involving one of the AVR DB chips, in which I set up a pin-change interrupt for one of the GPIO pins. The pin is set up with an internal pull-up, and so I wish to service the interrupt on the falling edge when that pin is connected to ground. The MCU is powered by a 12V source via a 5V LDO regulator. Unfortunately, that same 12V source is experiencing back-EMF from a DC motor that is also powered by it. That is giving me interrupt triggers every time the motor is disconnected from the 12V.In the scope output below, the yellow trace is that of the 12V input to the regulator, and the green trace is that of the GPIO pin in question. The traces are triggered on the 12V input falling below 10V. What I'm suspecting is that the MCU is "riding out" the disturbance on the 5V Vcc line, but that one or more of the finer transient dips are being seen by the GPIO pin as state transitions and therefore triggering the interrupt. I believe it only takes about 3 clock cycles or so to jump to an interrupt handler.Now this test was performed without any free-wheeling diode to just make a point. Adding a diode at the board suppresses much of the back-EMF, but apparently the diode is not fast enough to eliminate all of the short-lived transients, and so I still get spurious interrupts - although less frequently. What improves things further is, of course, the better practice of placing the diode right at the motor terminals. However, in this particular application, access to the motor is an issue, and no one had the foresight to include a diode at the time of installation.Any insights or suggestions"Jim

author: pcprogrammer
author_rank: Super Contributor
timestamp: May 07, 2024, 03:07:48 pm
content: Add more decoupling capacitors near the MCU and/or use a stronger external pullup resistor with maybe a small capacitor to ground on the interrupt pin. This might filter the unwanted interrupts and still allow the regular ones.Otherwise filtering of the 5V supply with a ferrite bead and capacitors could be the solution.

author: eutectique
author_rank: Frequent Contributor
timestamp: May 07, 2024, 03:33:30 pm
content: GPIO voltage of 3.5V might indicate problems with 5V supply rail. How does it behave during transient?

author: rubidium
author_rank: Regular Contributor
timestamp: May 07, 2024, 04:15:20 pm
content: Another thought I had is to invert the interrupt logic. Eliminate the internal pull-up on the pin and have the interrupt serviced on the rising edge. Perhaps a 10K to ground endures that the pin remains at logic low when an external 5V is not applied to legitimately request the interrupt.I also take your point of having a ferrite bead at the output of the regulator. I have 22uF there now, but maybe more would help.

author: pcprogrammer
author_rank: Super Contributor
timestamp: May 07, 2024, 05:16:35 pm
content: Sometimes it is not more capacitance, but less that does the job. For a linear regulator the datasheet specifies what capacitance is needed near to the regulator to avoid it from oscillating. Same applies to a lot of IC's where for instance a 100nF capacitor needs to be placed near to the supply pin.I had problems with my MCU resetting due to voltage dropping to low when starting a brushed dc motor. Was using a buck converter to lower the voltage from 9 to 3.3 and the input voltage dropped to low also depleting the capacitors for the mcu. Solved it with a diode between the 9V and the buck converter and adding more capacitance for the mcu. That solved the turning on issue. To filter noise when stopping the motor I used ferrite beads and small capacitors plus series resistors and bigger capacitors to get a cleaner supply voltage.Take a look at the schematichere.Changing the polarity of the interrupt might also do the trick, but making sure the supply voltage is as clean as possible never hurts.

author: T3sl4co1l
author_rank: Super Contributor
timestamp: May 07, 2024, 10:44:31 pm
content: We need schematic and layout to know better, but fast bounce is typically not propagated along the PDN (power distribution network), differential mode, but common mode through wiring; including any boards that lack ground planes, to name one very basic error, but without layout provided, I cannot rule out the possibility.Calling it an unqualified error is a bit over-the-top, but is simpler and more colloquial than saying "highly likely to be problematic". Again, without information, only broad sweeping answers are possible.EMC is a complex and holistic topic. Rigorous, provable and comprehensive solutions are possible -- but the problem must be fully defined to every detail and nuance to be able to provide that certainty. In lieu of that, incomplete data lead to uncertain outcomes -- how much, depends on what data are missing, and as the picture gets less and less complete, the full range of possibilities, best case to worst case, quickly diverges; a likely path can still be explored through the problem space, but more and more assumptions must be made along the way: what components are used, how the layout and wiring is done, about what nodes are interfering and how, etc. If you're doing things in the usual way, but for some omissions (EMI filtering oversights, perhaps? unexpected behavior of components differing from a reference design?), this can still prove a useful answer, but clearly you are doing something different (real productsdon'taren't supposed to have EMI problems) and if simply anything could be different, you can see how much uncertainty that leaves.Note also, brushed motors arc internally, so create noise by themselves, without switching noise having to be generated by the circuit. Ceramic caps and ferrite beads on the terminals, and to the motor case or nearby chassis/enclosure (whatever might pass for relevant RF ground), are a typical addition. Needless to say, the switching source into the motor needs to be controlled, whether by local filtering, or switching slow enough. Note that filtering can be a small dampened LC filter to knock down the edges, or a full PWM filter (i.e. buck converter), depending on what you're doing with it (it might be better to use the full PWM filter if Fsw should be on the high side, motor control should be nimble, and the wires are long, preferring strong filtering).There's also the semi-non-solution solution: if the noise is synchronous with the circuit (i.e. switching noise ultimately triggered by a timer), you might even blank the interrupt entirely, near the edge. This will require a cascade of timers, but might be reasonable depending on available resources.Tim