Pages: [1]   Go Down
Author Topic: N-MOSFET, PWM and DPDT to control speed and direction of Motor  (Read 982 times)
0 Members and 1 Guest are viewing this topic.
Durham UK
Offline Offline
Full Member
***
Karma: 1
Posts: 169
aka Craig Turner
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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


* DPDTandPWM_MOSFET.jpg (95.12 KB, 998x811 - viewed 51 times.)
« Last Edit: May 22, 2013, 03:41:41 am by trendski » Logged

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)

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 212
Posts: 13072
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


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

Durham UK
Offline Offline
Full Member
***
Karma: 1
Posts: 169
aka Craig Turner
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#include <lazyPWM.h>

setPWMfreq(int Hz);//

smiley although I guess I learn more playing directly with the timers.
Logged

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)

texas
Offline Offline
God Member
*****
Karma: 27
Posts: 862
old, but not dead
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Experience, it's what you get when you were expecting something else.

0
Online Online
Shannon Member
****
Karma: 220
Posts: 12690
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

[ I won't respond to messages, use the forum please ]

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 212
Posts: 13072
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Is there an easier way? ... smiley 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?
Logged

Durham UK
Offline Offline
Full Member
***
Karma: 1
Posts: 169
aka Craig Turner
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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)

Durham UK
Offline Offline
Full Member
***
Karma: 1
Posts: 169
aka Craig Turner
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset



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


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

cheers
Logged

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)

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 212
Posts: 13072
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

cheers

Back at ya!
Logged

Durham UK
Offline Offline
Full Member
***
Karma: 1
Posts: 169
aka Craig Turner
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.



* mosfetDriverX4forum.jpg (483.02 KB, 600x607 - viewed 36 times.)
Logged

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)

Pages: [1]   Go Up
Jump to: