Author Topic: Switching an electromagnet using PWM  (Read 7207 times)

0 Members and 1 Guest are viewing this topic.

Offline DaaniiTopic starter

  • Robot Overlord
  • ****
  • Posts: 138
  • Helpful? 3
Switching an electromagnet using PWM
« on: August 29, 2011, 03:17:38 PM »
I want to control a trailer electric drum brake using an Arduino PWM output pin. (Don't worry -- this will not be used on the public roads.) The trailer brake has a 12 Volt electromagnet that draws up to 5 Amps.

I built a test circuit that takes a PWM signal from the Arduino through a 220 Ohm resistor to the base of a TIP120 transistor, with a 10k resistor to ground. Then I have the load (I don't have a brake yet, so I'm using a lamp as a load now) hooked up between the 12 Volt supply and the collector, with the emitter connected to ground.

The circuit works fine to power the lamp. When I get the brake, I'll make sure there is a diode across the terminals of the electromagnet.

Anything I have missed here to have this circuit drive the brake? 

Offline Soeren

  • Supreme Robot
  • *****
  • Posts: 4,672
  • Helpful? 227
  • Mind Reading: 0.0
Re: Switching an electromagnet using PWM
« Reply #1 on: August 29, 2011, 10:36:03 PM »
Hi,

The circuit works fine to power the lamp. When I get the brake, I'll make sure there is a diode across the terminals of the electromagnet.
What voltage do you get over the lamp (assuming a 'scope measure here)?


Anything I have missed here to have this circuit drive the brake? 
A generous heat sink!
At 5A you'll be driving it at its abs. max. rating (which is never a good idea) and Darlingtons have a high c-e saturation drop => heat

For PWM, I would make the pull down resistor smaller... Much smallerm as you want the TIP120 to close as fast as possible (I'm not sure how well the Arduino pulls to ground, might not be needed).

You'd be better off with the MOSFET you mentioned and the two BjT's for a driver (tell me if you want a schematic), as it have a much lower drop (much less heat) and is much faster, which is good, as the losses/heat is negatively impacted by slow switching. Finally, it can handle the current without bordering its limits.

Regards,
Søren

A rather fast and fairly heavy robot with quite large wheels needs what? A lot of power?
Please remember...
Engineering is based on numbers - not adjectives

Offline DaaniiTopic starter

  • Robot Overlord
  • ****
  • Posts: 138
  • Helpful? 3
Re: Switching an electromagnet using PWM
« Reply #2 on: August 30, 2011, 11:57:38 AM »
What voltage do you get over the lamp (assuming a 'scope measure here)?

I don't have an oscilloscope, but my voltmeter shows 0 Volts across the lamp terminals when the Arduino output pin is at 0 Volts. My voltmeter shows 10.28 Volts when the Arduino output pin is at 5 Volts. (My voltmeter also shows my power supply  putting out 11.47 Volts instead of 12 Volts.)

You'd be better off with the MOSFET you mentioned and the two BjT's for a driver.

That makes sense. I'll replace the Darlington transistor with a MOSFET. If not too much trouble, having a schematic would be nice, just so I don't misunderstand anything.


Offline Soeren

  • Supreme Robot
  • *****
  • Posts: 4,672
  • Helpful? 227
  • Mind Reading: 0.0
Re: Switching an electromagnet using PWM
« Reply #3 on: August 30, 2011, 12:47:35 PM »
Hi,

I don't have an oscilloscope,
Oh, I thought this was a "school" project  :)


but my voltmeter shows 0 Volts across the lamp terminals when the Arduino output pin is at 0 Volts. My voltmeter shows 10.28 Volts when the Arduino output pin is at 5 Volts. (My voltmeter also shows my power supply  putting out 11.47 Volts instead of 12 Volts.)
That sounds about right and that's 1.2V (6W at 5A) of lost power.


That makes sense. I'll replace the Darlington transistor with a MOSFET. If not too much trouble, having a schematic would be nice, just so I don't misunderstand anything.
I'll draw you one... In between the flick that's on the boob tube in about 12 minutes.

Edit: Here's a schemmy...

Consider C1 only for experiments and with a higher value R5, to deliver enough charge voltage to the gate for a swift turn on, while keeping the average current lower.
« Last Edit: August 30, 2011, 02:29:53 PM by Soeren »
Regards,
Søren

A rather fast and fairly heavy robot with quite large wheels needs what? A lot of power?
Please remember...
Engineering is based on numbers - not adjectives

Offline karlis

  • Full Member
  • ***
  • Posts: 79
  • Helpful? 0
Re: Switching an electromagnet using PWM
« Reply #4 on: August 30, 2011, 03:32:06 PM »
i would go for a relay, that is driven by tip120 you are using, so you would not fry anything, regular car relays can hold up to 40A

Offline Soeren

  • Supreme Robot
  • *****
  • Posts: 4,672
  • Helpful? 227
  • Mind Reading: 0.0
Re: Switching an electromagnet using PWM
« Reply #5 on: August 30, 2011, 04:14:12 PM »
i would go for a relay, that is driven by tip120 you are using, so you would not fry anything, [...]
Interesting!
Please share how you get relays to do PWM at anything above ~5..10Hz.

Why do you think the circuit I posted will fry anything?
Regards,
Søren

A rather fast and fairly heavy robot with quite large wheels needs what? A lot of power?
Please remember...
Engineering is based on numbers - not adjectives

Offline DaaniiTopic starter

  • Robot Overlord
  • ****
  • Posts: 138
  • Helpful? 3
Re: Switching an electromagnet using PWM
« Reply #6 on: August 30, 2011, 08:24:27 PM »
Soeren, thanks very much for the schematic. For the Schottky diode, will a 1N5817 work? I'm not too worried about the speed of the gate, since the PWM frequency of the Arduino pin is only 500 Hertz.

Oh, I thought this was a "school" project  :)

Actually, all this is for an electric car project. With some other family members, I am building a new type of electric car. It's more to try out some concepts than to build a car to actually drive on the roads.

Your help on a variety of topics for this project over the past year or two has been very valuable. The only thing that is still a problem is steering. Everything else is close to being ready.

Offline Soeren

  • Supreme Robot
  • *****
  • Posts: 4,672
  • Helpful? 227
  • Mind Reading: 0.0
Re: Switching an electromagnet using PWM
« Reply #7 on: August 30, 2011, 09:19:09 PM »
Hi,

For the Schottky diode, will a 1N5817 work?
1N5817 is a 20V device, so I wouldn't. 1N5818 is 30V and I'd go for at least the 40V handling of the 1N5819. There's probably not any real price difference and just a single breakdown due to a too weak diode might cost you way more, in terms of labor and a new diode..


I'm not too worried about the speed of the gate, since the PWM frequency of the Arduino pin is only 500 Hertz.
It's not the frequency of the signal I'm worried about, it's the rise and fall times of same.


Actually, all this is for an electric car project. With some other family members, I am building a new type of electric car. It's more to try out some concepts than to build a car to actually drive on the roads.
The more (tried&tested) electric cars on the road the better, so every project that bears that way is good - now that the flying cars never arrived  ;D


Your help on a variety of topics for this project over the past year or two has been very valuable. The only thing that is still a problem is steering. Everything else is close to being ready.
Great, remember me if you build something like the Tesla Roadster or the Koenigsegg Quant   :D

What's the steering issue(s)?
Regards,
Søren

A rather fast and fairly heavy robot with quite large wheels needs what? A lot of power?
Please remember...
Engineering is based on numbers - not adjectives

Offline DaaniiTopic starter

  • Robot Overlord
  • ****
  • Posts: 138
  • Helpful? 3
Re: Switching an electromagnet using PWM
« Reply #8 on: August 31, 2011, 12:16:28 AM »
What's the steering issue(s)?

I haven't found a good way to steer the wheels. The plan is to steer each wheel individually by sending it an 8-bit number (0 to 255). We need an electromechanical device to turn the wheel.

At first I thought of using a linear actuator. But they are too slow and weak.

Someone suggested (it may have been you) to use the existing steering gearbox, and just replace the steering wheel with an electric motor. We would then get another steering gearbox for the wheel on the other side.

You thought a windshield wiper motor might work as the electric motor. So I've been trying that out, and have tried to write a PID program to control the motor. But I'm not sure the motor has enough torque.

Another problem has been the mechanical linkage between the motor and gearbox. Finally, it's hard to find a place to put a potentiometer to give feedback on the steering angle.

None of those are huge problems. But there are a lot of problems, all of which need to be solved. So the steering still needs a lot of work. We may even have to come up with a whole new idea on how to do it.

Otherwise, the car is coming along nicely. It's no Tesla Roadster, or Koenigsegg Quant. (Those are really nice cars.) But our car is a whole new architecture for an electric car that may lead to much better cars in the future, as well as change the carmaking industry.

Offline Soeren

  • Supreme Robot
  • *****
  • Posts: 4,672
  • Helpful? 227
  • Mind Reading: 0.0
Re: Switching an electromagnet using PWM
« Reply #9 on: August 31, 2011, 01:12:35 AM »
Hi,

I haven't found a good way to steer the wheels. The plan is to steer each wheel individually by sending it an 8-bit number (0 to 255). We need an electromechanical device to turn the wheel.
Unless it's for being able to turn the wheels 90° for a smooth parking, I wouldn't touch it. There's a well proven steering geometry that's hard to beat - if weight has a say in it, carbon fiber rods may be the ticket.


At first I thought of using a linear actuator. But they are too slow and weak.
They come in lots of different speeds and strength, ut wouldn't be my first candidate either.


Someone suggested (it may have been you) to use the existing steering gearbox, and just replace the steering wheel with an electric motor. We would then get another steering gearbox for the wheel on the other side.
I really think you can get in a lot of trouble by steering each side separately - what if one wheel stics? I'd prefer they followed along, rather than taking different routes in that situation - less emergency handling to know/learn.


You thought a windshield wiper motor might work as the electric motor. So I've been trying that out, and have tried to write a PID program to control the motor. But I'm not sure the motor has enough torque.
With a conventional Ackermann geometry, it should have as much (or little) torque as a skinny 16 year old girl   ;D


Another problem has been the mechanical linkage between the motor and gearbox. Finally, it's hard to find a place to put a potentiometer to give feedback on the steering angle.
Potentiometer *aargh* How short do you want it to last?  ;D
You really should use an encoder, either optical, or better, a hall based encoder, as the latter are as good as impervious to dirt and grime.

What resolution do you need?


None of those are huge problems. But there are a lot of problems, all of which need to be solved. So the steering still needs a lot of work. We may even have to come up with a whole new idea on how to do it.
I may be repeating myself, but if you stick to the good old steering arms to yank with the connecting rod, you only have one motor to worry about and a gearhead with a rack and pinion should take care of the interface.

A well written and very illustrative page on Ackermann can be found here (never mind it's written for R/C, the principle remains the same.


Otherwise, the car is coming along nicely. It's no Tesla Roadster, or Koenigsegg Quant. (Those are really nice cars.) But our car is a whole new architecture for an electric car that may lead to much better cars in the future, as well as change the carmaking industry.
I'll drink to that  ;D  (As long as it doesn't come out looking like a Skoda  :D)
Regards,
Søren

A rather fast and fairly heavy robot with quite large wheels needs what? A lot of power?
Please remember...
Engineering is based on numbers - not adjectives

Offline DaaniiTopic starter

  • Robot Overlord
  • ****
  • Posts: 138
  • Helpful? 3
Re: Switching an electromagnet using PWM
« Reply #10 on: August 31, 2011, 12:53:01 PM »
Soeren,

Thanks as always for your helpful response.

If I were trying to build a normal electric car, I would take your suggestion and just put a motor on the existing gearing and turn both wheels with one motor. But the whole point of our car is to do things a little differently.

For one thing, we want to implement things like the steering geometry in software rather than hardware. As you may know, modern cars do not use pure Ackermann steering. In fact, race cars use reverse Ackermann steering, and turn the outside wheel more than the inside wheel. By being able to change the steering geometry on the fly, we can get better performance at no added cost.

And we want to have each wheel steered independently. In fact, we want to have all four wheels steered, braked and driven independently. We will then have a true four-wheel drive car, with each wheel being an interchangeable module.

But as you point out, that will be hard to do. So I am trying to figure out whether to abandon the ideal solution and take a more practical approach. Your comments help.

Frankly, I have not spent much time on the steering lately, so I cannot explain the issues we face any better. As you point out, a potentiometer may not last long. But that is not really a problem with us. I doubt that our car will ever be driven on the public roads. It's more to demonstrate concepts than to be a working car.

And I want an absolute reference rather than a relative one. That's why the rotary encoders and Hall sensors I found did not seem like they would work well. Ideally, I would like to put the position sensor right on the steering knuckle and get a resolution of half a degree.

This car has been an interesting project, and as I said, your help on some of these questions has been very good to have. Thank you.

Offline Soeren

  • Supreme Robot
  • *****
  • Posts: 4,672
  • Helpful? 227
  • Mind Reading: 0.0
Re: Switching an electromagnet using PWM
« Reply #11 on: September 01, 2011, 06:41:49 AM »
Hi,

But the whole point of our car is to do things a little differently.
Ah OK, I think we're on the same page now (at least I'm getting there inch by inch ;))


By being able to change the steering geometry on the fly, we can get better performance at no added cost.
I see.


we want to have all four wheels steered, braked and driven independently. We will then have a true four-wheel drive car, with each wheel being an interchangeable module.
I've had similar thoughts for 'bot wheels, but with the motors built into each. Something like an outrunner BLDC with a tyre, perhaps with a "layer" of gearing in between, but my present lack of an easy accessible mech space makes it hard to build motors :(
This method might be good for a car as well and would make the wheels interchangeable modules at the minimum size.


But as you point out, that will be hard to do. So I am trying to figure out whether to abandon the ideal solution and take a more practical approach. Your comments help.
Hey, don't let me scare you off trying new and exciting roads!!


And I want an absolute reference rather than a relative one. That's why the rotary encoders and Hall sensors I found did not seem like they would work well. Ideally, I would like to put the position sensor right on the steering knuckle and get a resolution of half a degree.
You can get absolute Hall encoders - somewhat expensive compared to other ways, but not prohibitively so (around $30..50 a chip and sold in 3..5 piece sample packs IIRC a little steep).

I recently made a new disc for my steering, it's not 360° since I don't need that and by limiting it, I can still get 1° resolution in 8 bits wide). I also modified the Gray code a bit (actually 4 bits ;D) to make for easier detection of forbidden codes, even if I am never gonna get to the extremes (except if I drive over a mine perhaps).
(Anyone with too much time on their hand could try to find where I modified the code  :D)

This is just a raster image of it, I made it as a µm-precision vector image and all the "segment dividers are just for easier checking and gone in the finished disc.
It would be easy to make it ½° resolution for a full 360° by using:
  log(360/0.5) / (log(2) =  9.49  => 10 bits
But the diameter of the disc, assuming 1mm detection zones will be around 260mm (10"), so I'd prefer the Hall chips for size as well (My own disc is gonna be 166mm (a little over 6.5") but is very cheap to make - just wondering if I should get it laser cut in stainless foil or run out on film for max. precision, but for starters, it's gonna be LASER printed and put on a polycarbonate disc.


This car has been an interesting project, and as I said, your help on some of these questions has been very good to have. Thank you.
You're very welcome!
Cars are plain fun working on and this way I don't even get dirty hands  ;D
Regards,
Søren

A rather fast and fairly heavy robot with quite large wheels needs what? A lot of power?
Please remember...
Engineering is based on numbers - not adjectives

Offline DaaniiTopic starter

  • Robot Overlord
  • ****
  • Posts: 138
  • Helpful? 3
Re: Switching an electromagnet using PWM
« Reply #12 on: March 23, 2012, 12:23:47 PM »
Here's a schemmy...

Consider C1 only for experiments and with a higher value R5, to deliver enough charge voltage to the gate for a swift turn on, while keeping the average current lower.

Soeren, last year you drew the above schematic for me. (Thank you for that.) I'm just now getting back to the project. You have a MOSFET labeled as Q3. I'm not sure what type of MOSFET would work here. Back then I was thinking of using an STP40NF10L. Would that work?

Offline Soeren

  • Supreme Robot
  • *****
  • Posts: 4,672
  • Helpful? 227
  • Mind Reading: 0.0
Re: Switching an electromagnet using PWM
« Reply #13 on: March 23, 2012, 05:21:48 PM »
Hi,

[...] I'm not sure what type of MOSFET would work here. Back then I was thinking of using an STP40NF10L. Would that work?
Yes that would work fine - and so will any that can handle the current, so if you have some already, or cannot get the STP40NF10L, go for the one with the lowest RDS-ON
Regards,
Søren

A rather fast and fairly heavy robot with quite large wheels needs what? A lot of power?
Please remember...
Engineering is based on numbers - not adjectives

Offline DaaniiTopic starter

  • Robot Overlord
  • ****
  • Posts: 138
  • Helpful? 3
Re: Switching an electromagnet using PWM
« Reply #14 on: March 23, 2012, 06:47:25 PM »
Great, thanks.

 


Get Your Ad Here