N-MOSFET, PWM and DPDT to control speed and direction of Motor

Hi,

I'm making a small robotic car and designed this circuit on a simulator [attached]. It also works in real life, I get direction and speed control. However I have read many times on this forum that just because a circuit works doesn't mean it's a good design. Also the PWM makes it "sing" which I found a bit worrying - maybe it's normal?

Is this design reasonable and safe, and how could I improve it?

The MOSFET is a logic level type and is activated when 5v is applied to the gate. When the logic PIN of arduino is 5v it goes one way and logic 0 causes the DPDT relay to switch over and the motor goes the other.

cheers

I can't help with the circuit but the singing is very likely because of the PWM frequency. By default it's about 1 KHz or 500 Hz (depends on the pin) which is obviously in the audible range. The cure is to push the frequency past 25 KHz (which will probably cause problems for any bats near your house).

Coding Badly - Thanks for clearing up the singing thing.

I'm using the arduino mega2560 I looked here Arduino Playground - TimerPWMCheatsheet for tips on altering frequency, but it looks advanced for an intermediate like me. Is there an easier way? I wonder if anyone wrote a library that does the register stuff in the background and I can just do something like

#include <lazyPWM.h>

setPWMfreq(int Hz);//

:slight_smile: although I guess I learn more playing directly with the timers.

I would put Q3 "under" the relay (between relay and ground).

The transistor driving the relay coil is wrong, its wired as "emitter follower", rather than
"common-emitter" configuration (which is always used for switching). Google/wikipedia those
terms for more info.

If the motor is large you need a snubber circuit across its terminals to avoid arcing
the relay contacts when they switch (unless you stop the motor before reversing
drive).

trendski:
Is there an easier way? ... :slight_smile: although I guess I learn more playing directly with the timers.

It isn't that difficult (one line of code). Yes.

Which pin will you be using for PWM? / Which Arduino pin will be connected to CN1 in your diagram?

Coding Badly- I'll probably use pin 10 on the mega2560.

also thanks MarkT and afremont for the tips about the switching tranny and snubber. At the mo, I'm only using a couple of amps @12vdc, but I want have these scalable so in future I can use larger currents so snubbers will be needed then.

I used this code from the playground and it works fine = Lot Less noisy PWM

 TCCR2B = TCCR2B & 0b11111000 | 0x01;
//sets Arduino Mega's pin 10 and 9 to frequency 31250.

cheers

trendski:
cheers

Back at ya!

Update.

I settled for this DPDT relay design http://www.audiowind.com/pdf/D-128.pdf and a X4 config of my mosfet circuit on perf-board see attached pics. Also with the higher freq PWM.

Does this circuit works finally? I want to do the same thing for an RC toy