Go Down

Topic: N-MOSFET, PWM and DPDT to control speed and direction of Motor (Read 1 time) previous topic - next topic

trendski

May 22, 2013, 10:39 am Last Edit: May 22, 2013, 10:41 am by trendski Reason: 1
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
Craig Turner, blog: http://gampageek.blogspot.co.uk/ It helps with my learning if I write things down, esp. for others to follow (constructive comments welcomed to improve)

Coding Badly


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).

trendski

Coding Badly - Thanks for clearing up the singing thing.

I'm using the arduino mega2560 I looked here http://playground.arduino.cc/Main/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

Code: [Select]

#include <lazyPWM.h>

setPWMfreq(int Hz);//


:) although I guess I learn more playing directly with the timers.
Craig Turner, blog: http://gampageek.blogspot.co.uk/ It helps with my learning if I write things down, esp. for others to follow (constructive comments welcomed to improve)

afremont

I would put Q3 "under" the relay (between relay and ground).
Experience, it's what you get when you were expecting something else.

MarkT

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).
[ I won't respond to messages, use the forum please ]

Coding Badly

Is there an easier way? ... :) 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?

trendski

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.
Craig Turner, blog: http://gampageek.blogspot.co.uk/ It helps with my learning if I write things down, esp. for others to follow (constructive comments welcomed to improve)

trendski



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


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


cheers
Craig Turner, blog: http://gampageek.blogspot.co.uk/ It helps with my learning if I write things down, esp. for others to follow (constructive comments welcomed to improve)


trendski

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.

Craig Turner, blog: http://gampageek.blogspot.co.uk/ It helps with my learning if I write things down, esp. for others to follow (constructive comments welcomed to improve)

Go Up