Noise from DC Motor Driven by STM32F4 - Page 1
Forum section: electronics / projects

author: BareMetalBard
author_rank: Newbie
timestamp: March 20, 2024, 12:32:36 am
content: Hey All,I'm building an IR remote controlled fan with an STM32F4 MCU. The MCU receives signals from the IR remote, and drives a DC motor with a PWM signal through a L293D push pull driver.However, when the motor is being driven (purple signal in screenshot) it causes spikes spikes on the input line to my MCU (yellow signal). Strangely, it seems as if the PWM signal ranges from -0.5-4.5V before the spike, and briefly ranges from 0-5V just after the spike.I have two power rails. The 5V power rail driven by a wall wart plugged into my breadboard via barrel connector. The 3V rail is powered by my MCU board via USB. They are connected to a common ground.Does anybody have any idea what could be causing this behavior? I've tried bypass capacitors of varying sizes in various locations in the circuit.Thank you!

author: Retirednerd2020
author_rank: Regular Contributor
timestamp: March 20, 2024, 03:54:57 am
content: A schematic will help diagnose. Here are some random ideas:Eliminate one of the power sources, power everything from one isolated source with regulation to your rails as needed. Eg a 5V PS with a 3.3V LDO.Physically separate the power circuits/motor from the digital circuits. Get the motor far away from the "antennas" you have all over the breadboard. Twisted pair to your motor. Route it away, not past the breadboard.Likely a bulk capacitor (Electrolytic or Tantalum) right at the pins of the motor driver power input will help. 10uF? 100uF? Don't know the device you are using.Use multiple ground wires between breadboard ground and controller ground. Make twisted pairs of each digital signal and a ground wire.Shorten any breadboard jumpers you can to reduce stray pickup.Don't know where the white/yellow goes on the upper left. What is that?If you don't have one, a bypass capacitor on the chip on the left hand side of the motor driver might be a good idea.Also, breadboard grounds where you have a jumper tying together one side to the other open you up to poor ground performance. Maybe concentrate all of your ground connections to one short section of the breadboard commons.

author: BareMetalBard
author_rank: Newbie
timestamp: March 20, 2024, 07:42:56 am
content: Thanks for the feedback.I don't have much experience making schematics, but hopefully what I drew up is sufficient. The TSOP IR receiver talks to PD6 on the STM32F407 MCU via a 3.3-5V level shifter (TXS108EPW). Then, it drives a L293D via PA1, PA3, and PA15. In turn, the L293D drives a DC motor.The 3V0 power rail comes off the dev board (STM32F4-DISC1), and the 5V power line is coming from my wall via a 5V adapter and a barrel jack.I tried twisting the motor cables and routing as far away as possible, I placing a 100uF bypass across the 5V supply to the motor driver, and I placed another ground on my board which I twisted with the input signal on PD6. No luck so far though, I still see the spikes/ringing. I'll keep working on implementing your other ideas and I'll see whether I can make it work.Thanks again for the help.

author: ace1903
author_rank: Regular Contributor
timestamp: March 20, 2024, 08:17:42 am
content: Almost all of TSOP IR receiver have output of open collector type.It is better to remove the level translator and add external pull up resistor to 3.3v

author: bingo600
author_rank: Super Contributor
timestamp: March 20, 2024, 09:23:41 am
content: I would also put 100nF across the IR Sensor supply pins ...Learnt the hard way ...

author: macboy
author_rank: Super Contributor
timestamp: March 20, 2024, 12:19:36 pm
content: IR receivers are very susceptible to any noise in the power supply. Try a 100 ohm resistor in series with the v+ followed by a 100nF ceramic bypass cap as close as possible to the receiver.I'd also suggest another small capacitor across the motor power pins (on the motor, not on the PCB). Driving a motor with PWM can produce a lot of inductive noise spikes and this would help.

author: Retirednerd2020
author_rank: Regular Contributor
timestamp: March 20, 2024, 04:45:52 pm
content: The schematic was great. Always good to start with a schematic, even a hand drawn one.Agree with other's input too. For bypass and noise capacitors (say 0.1uF), keep their leads as short as possible.Put a 0.1 uF in parallel with the electrolytic as well.

author: MathWizard
author_rank: Super Contributor
timestamp: March 20, 2024, 05:12:25 pm
content: What about a reverse polarity diode on the top of the motor? TI has them pictured outside the L293 chip, so I guess not included inside it, and I don't see it on your schematic.All the making and breaking of contact on typical motor brushes, means you get big voltage spikes as the magnetic fields react, and the currents change.

author: BareMetalBard
author_rank: Newbie
timestamp: March 21, 2024, 07:16:33 pm
content: Thanks all for the feedback. I made some significant updates.Looking closer at the IR receiver, it's actually a TSOP 1838, and it's mounted on a PCB where the signal output is routed through a status LED and a 1k resistor.I removed the level shifter entirely, and tied the TSOP 1838 to the 3V rail. I also put a 100nF tantalum capacitor across it.I added another 100nF bypass across the L293D motor driver.I adjusted the breadboard layout so that every common ground was tied to a single physical rail, as close as possible.With this configuration, the ripple actually looks quite different. There used to be very sharp spikes down to ~1V. Those spikes now don't dip nearly as far - they reach about 2V and then ring for a while (see attached image). Unfortunately, the spikes are just bad enough that it's still picked up as an edge by my input pin.I have a few more things to try: add a 100ohm resistor in series with receiver V+, and use a single power rail with a regulator. I bought a 3.3V LDO that's coming soon, so I'll try that out. I also bought some shorter M-F jumpers to shorten some of my cable runs.A few questions:Why 100nF specifically across the IR receiver? Can that be derived from the switching speed of the receiver?What does the 100ohm resistor in series with V+ do?Again, thanks for all the help so far!

author: ace1903
author_rank: Regular Contributor
timestamp: March 22, 2024, 06:33:50 am
content: Input of the micro is high impedance, D1 R1 in series can mess the voltage levels.Maybe enabling pull down resistor on the micro's input can improve the things but to me it looks like bad workaround.If you want visual indication of the received signal add some PNP transistor to drive D1 and R1 and connect output of the receiver directly to the micro.

author: Chalcogenide
author_rank: Regular Contributor
timestamp: March 22, 2024, 07:14:24 am
content: By the way, almost everybody ignores that most of the pins on STM32F4 MCUs are 5V tolerant. PD6 on the STM32F407 certainly is, so if you are using it as an input you can just feed it the 5 V signal from the IR receiver without the need of any level translation. See table 7 "Pin and ball definition" on the datasheet to see which I/Os are 5V tolerant ("FT"), which in reality are actually 7-ish volt tolerant (VDD +4 V).

author: Retirednerd2020
author_rank: Regular Contributor
timestamp: March 22, 2024, 05:16:41 pm
content: Also try to get your scope probes away from the motor. You have extended the ground leads which is bad news as they are already long and can pick up noise easily. If you count the length of the ground bus you plug in the scope ground to, plus the extension, you are talking about several inches. Sometimes the noise you see is not "real" or at least not real with regard to the circuit you are measuring. Get yourself some of the pin type ground leads as in the attachment. Just put a 25 mil pin where you need it and plug in. They may make a male version but I have not seen one. Very handy for this type of work.You probably have some noise in your circuit too but you need to eliminate the instrumentation noise pick-up as best you can so you can know what is real and what is an instrumentation issue.Also, find yourself some small gauge, solid insulated wire to make jumpers of just the right length on your breadboard. Get rid of the long jumper wires. Think "everything is an antenna".

author: BareMetalBard
author_rank: Newbie
timestamp: March 23, 2024, 04:50:40 am
content: I bought some 3.3 LDOs (MIC2940A), and I'm now using that to regulate the 5V rail coming out of my wall wart for my 3.3V bus, rather than using the 3V rail on my dev board. I couldn't find the part in KiCad, so I just wired up another LDO and renamed it.I also significantly shortened the jumpers from dev board to breadboard, and I replaced all the breadboard jumpers with wires I cut myself.Chalcogenide had some good advice that PD6 on my MCU was 5V tolerant, so I am connecting my TSOP sensor to the 5V rail now and just feeding that into PD6. I thought this might resolve the issue entirely since I thought VDDfor my board would still be 3V, and therefore VIHwould be 0.7*3.3 = 2.3V. When I checked my scope, my power rail was still rippling, but seemingly never below 3V. For some reason, my MCU was still detecting these ripples as edges. Unsure the reasoning behind that.Either way, with the power of all this advice combined, I am now able to drive the motor with up to 80% duty cycle PWM without the IR receiver getting tripped. That feels like a victory in and of itself XD. I've learned a lot so far, and I've especially learned that cheap DC motors and cheap IR receivers don't play nice haha.

author: pcprogrammer
author_rank: Super Contributor
timestamp: March 23, 2024, 08:04:21 am
content: Quote from: MathWizard on March 20, 2024, 05:12:25 pmA quick glance of thedatasheetof the L293 shows it using BJT's for the drivers, so no body diodes like the FET based drivers have. External diodes are needed to protect the driver.For bidirectional driving you need four diodes. Also a 100nF capacitor across the motor helps in noise reduction.When only unidirectional driving is needed a single n-channel MOSFET could be used. A single reverse protection diode is then needed across the motor. This saves on the number of pins needed to drive the motor.

author: BareMetalBard
author_rank: Newbie
timestamp: March 23, 2024, 08:53:22 am
content: The particular chip I have is from ST - I believe it's this one, which I think has the flyback diodes built in:https://www.st.com/en/motor-drivers/l293d.html.

author: pcprogrammer
author_rank: Super Contributor
timestamp: March 23, 2024, 09:28:33 am
content: Quote from: BareMetalBard on March 23, 2024, 08:53:22 amYes you are right. That version has them build in, so your save in that respect. I would still add a 100nF capacitor across the motor though.

author: MarkT
author_rank: Frequent Contributor
timestamp: March 23, 2024, 09:39:11 am
content: Quote from: pcprogrammer on March 23, 2024, 08:04:21 amIts the L293D, not L293, the D means its has internal diodes as shown in Figure 5 of the datasheet.More disturbingly is use of the L293D from a 5V supply, given it drops 2 or 3 volts internally you have a very inefficient system. A MOSFET-based H-bridge is suited to low voltage use - keep the L293D's and L298's for 24V or more...