PDA

View Full Version : magnet control through PIC



SterlingY
- 17th March 2007, 23:02
Okay, so I'm not sure where to put this thread.

I need to control multiple electromagnets from a PIC18F4550. The strength of the magnets needs to be varied over time, and each magnet individually controlled. To make this more difficult, I need to control more magnets than the PIC has outputs.

Thoughts?

-Sterling

Russ Kincaid
- 18th March 2007, 04:38
Implement a 4 bit binary counter and use '154 one of 16 decoder. With a 2 port PIC you could control 128 magnets easily.

Russ

SterlingY
- 18th March 2007, 06:13
I understand the 1 of 16 decoder, but I'm lost, those decoders have 4 inputs. Two '154 ICs would require 8 pins from the PIC I'm guessing the 4bit counter resolves this, but I'm not clear how.

Can you be a bit more specific to my untrained brain?

Thanks,

Sterling

SterlingY
- 18th March 2007, 08:02
What about using a 1-wire network to address each magnet seperately? Maybe that's much more costly. I have no experience with 1 wire networks.

mackrackit
- 18th March 2007, 13:38
Depending on the wattage of the magnets, there are several ways to control them. Use PWM or maybe even FREQOUT. Connect the mag circuit to you chip with an opto-isolator or drive the mags with a MOSFET or IGBT. There are pros and cons to each though.

How many more mags than pins? How many mags need to be on at a time? Look at some of the recent post about LEDs, add driver hardware and...

BobK
- 18th March 2007, 15:34
Hi SterlingY,

Don't know your level of expertise, but if it would help, there's a book out for Basic Stamps (these are PIC's) called "The Microcontroller Application Cookbook" that has a chapter on expanding I/O using only a few port pins and it has some code examples. Volume 2 also has some interesting I/O examples. These books are available from www.parallax.com and www.nutsvolts.com and probably from Amazon.com.

HTH,

BobK

SterlingY
- 18th March 2007, 18:25
Thanks for the book info. I'll check them out. Can't hurt to have them around.

As for how many mags to control at once, all of them. I would assume that I have 2 PORTS available for their control.

-Sterling

Russ Kincaid
- 18th March 2007, 20:24
That reminds me of the cemetery joke: How many people are dead in that cemetery? Answer: all of them!

My idea of using the '154 was that 8 of them could be connected with their inputs in parallel. The enable port on the '154 would be connected to 8 pins on the PIC to select the group of 16 magnets. that leaves 4 pins on the PIC for other control.

Russ

SterlingY
- 19th March 2007, 01:06
Forgive me for asking this stupid question, but wouldn't that mean that each '154 would be the same as the others: if output 3 is HIGH on one then it is HIGH on the others?

Another question, which is a better interface I2C or Serial Data? Microchip make a 16 channel port extender in both formats.

-Sterling

Russ Kincaid
- 20th March 2007, 23:15
wouldn't that mean that each '154 would be the same as the others: if output 3 is HIGH on one then it is HIGH on the others?

Only the enabled IC has an output.

skimask
- 21st March 2007, 00:07
Forgive me for asking this stupid question, but wouldn't that mean that each '154 would be the same as the others: if output 3 is HIGH on one then it is HIGH on the others?

Another question, which is a better interface I2C or Serial Data? Microchip make a 16 channel port extender in both formats.

-Sterling

I2C....because PBP has built in I2C handling capabilities (sure, it's got serial and SPI also, but I find I2C a bit 'cleaner' if that makes any sense).

On the '154...
The '154 has 4 inputs to control the 16 outputs, it's also got an enable line which turns the chip on or off.
You take a 5th bit from the PIC and drive that enable line with it. If you're driving 2 '154's, you have to invert that 5th bit going to one of the '154's, that way when one is on, the other is off.
If you want to drive a whole load of '154's, you can take 17 '154's, connect 16 of them in parallel (with say D0-D3) except for the enable line, take the 17th '154, connect it to another 4 bits from the PIC (say D4-D7), and use each of the 17th '154's outputs to drive the other 16 '154's enable line. And you'll end up with 256 individually controllable outputs. (or you could do the same thing with a '138, but with 8 '154's instead of 16 of them, or just not use all of the outputs of that extra '154 connected to D4-D7).

Another thing, with the '154, all you'll get is ON and OFF, nothing in between. You mentioned that you want to vary the strength over time. The '154 won't do it because you can't run multiple channel pulse-width modulation through it. You could easily set up an 8 channel software driven pulse-width modulation program and drive a bank of MOSFETs with the PIC and control the magnets that way. I've done exactly this with an 18F8722 and bank of 22 RGB LEDs (66 individual LEDs total). Replace those LEDs with n-channel MOSFETs or a bunch of ULN2803A's and you've got instant magnet control (well, as long as your power supply can handle it and doesn't cause the PIC to reset!).

Let us know if I dumbed this down too far for you, or maybe not enough, or whatever. We'll get you straightened out... :)

SterlingY
- 21st March 2007, 00:35
OKAY!!!!

This is starting to makes sense. It sounds so cool, I want to build the multiport system just to build it for something, anything.

Of course to make my problem more difficult, I am now in the process of builing my own electromagnets. That's a whole other field to learn. My problem is making them strong enough without starting a fire.

-Sterling

skimask
- 21st March 2007, 02:26
OKAY!!!!

This is starting to makes sense. It sounds so cool, I want to build the multiport system just to build it for something, anything.

Of course to make my problem more difficult, I am now in the process of builing my own electromagnets. That's a whole other field to learn. My problem is making them strong enough without starting a fire.

-Sterling

Well, if you're talking about electromagnets that are going to be drawing a fair amount of current (over a total of an amp or so), then you're going to want to skip the '2003 in the first place and just go straight with MOSFETs or whatever else you choose.

In the meanwhile, while you get your magnets built up and working well, I'd suggest setting up a bank of LEDs set up and trying those out while you sort out your software. The light from the LEDs (in relation to the PWM input to them) won't be a linear curve, and neither will your electromagnets response to that same input...but at least with the LEDs you can learn how to change your program easily to change that curve without pumping a bunch of current and potentially burning something out...then you can easily swap out those LEDs for a MOSFET and the magnets...PRESTO! instant done...almost anyways :)

SterlingY
- 23rd March 2007, 17:25
Thanks for all of the info so far.

Can someone suggest a logic-level MOSFET that they might use for this type of project?

Thanks,

Sterling

skimask
- 23rd March 2007, 17:50
Thanks for all of the info so far.

Can someone suggest a logic-level MOSFET that they might use for this type of project?

Thanks,

Sterling

Unless somebody else beats me to it, I'll get you a good number when I get home after work. I use a few of them, 1 logic level, a couple not so logic level (but work at 5v anyways), and a couple that need a lot of V to turn them on.

Take the advice of the post below. I forgot you were working with electro-magnet type things.

Acetronics2
- 23rd March 2007, 17:59
Hi,

Why not look at the automotives protected IGBTs ???

IRGS 14C40 ( I R ) or ISL9V5036 ( Fairchild ) ... MGP 15N40 ( Motorola ... ON Semi. )

No switching issues then !!!

Alain

SterlingY
- 23rd March 2007, 18:10
Not sure about the 14C40, but the ISL9V5036, costs almost $4, so 56 of them would be too costly. The Motorola is $2.50, still too much. I'm trying to make this thing for $50-$70.

It may not be possible.

-Sterling

peterdeco1
- 23rd March 2007, 18:15
The best MOSFET I've used and use exclusively is an N-channel IRLZ44N. It has .02 ohm ON resistance with a logic level gate drive. It's rated (I think) 44 AMPS in a TO-220 package. We use a pair of them as a replacement for a solid state relay and run them at 1 AMP continuously. They stay cool up to a couple of AMPs without a heatsink, and are bi-directional. If you reverse the load voltage from source to drain they still conduct. If you want, I'll throw a few in an envelope & mail them to you. We have a lot of them.

SterlingY
- 23rd March 2007, 18:37
Peterdeco1,

That's a very nice offer, but I can just order a few if I go that route. They are certainly cheaper than the other MOSFETS suggested.

Honetsly, I am beginning to think that MOSFETS may not be the way to go.

It may be determined by the magnets themselves. I've built a few, and now I've got some feelers out there to see what the pros think. I have seen small magnets driven by 6V that can hold 100lbs!!! I only need 1-2lbs. What I am getting at is that I should probably learn what my magnets will require and let that determine what the drivers need to be.

In the mean time, I'm still interested in playing with a multiport analog system and MOSFETS.

-Sterling

mackrackit
- 23rd March 2007, 20:10
Another thing to look at is the switching speed. IGBTs normally will switch faster.

I use the FGA40N60UFDTU for motor control DC at 180 volts. These are out of you price range but... http://www.fairchildsemi.com/ds/FG%2FFGA40N60UFD.pdf

Also, the higher the voltage the less amps. (stating the obvious) So try to make a coil that will handle say 48 volts and then you might get by with a MOSFET if the switching speed is not to high.

Either way, do not forget a fly-back diode.

skimask
- 23rd March 2007, 21:36
Peterdeco1,

That's a very nice offer, but I can just order a few if I go that route. They are certainly cheaper than the other MOSFETS suggested.

Honetsly, I am beginning to think that MOSFETS may not be the way to go.

It may be determined by the magnets themselves. I've built a few, and now I've got some feelers out there to see what the pros think. I have seen small magnets driven by 6V that can hold 100lbs!!! I only need 1-2lbs. What I am getting at is that I should probably learn what my magnets will require and let that determine what the drivers need to be.

In the mean time, I'm still interested in playing with a multiport analog system and MOSFETS.

-Sterling

Heck, try it out with the MOSFETs and the LEDs like I suggested above...get the firmware working right...swap in the magnets and the flyback diodes, and try it out.
As long as you've got the firmware working, if you accidentally smoke the PIC of a couple of MOSFETs, no biggie, at least the firmware is tested and works. Just have to work out the kinks at the business end...
and of course...I've just overstated the blatantly obvious...

SterlingY
- 24th March 2007, 05:15
Skimask,

You said you built a similar thing with LEDs. Would you happen to have the schematic?

-Sterling

skimask
- 24th March 2007, 14:38
Skimask,

You said you built a similar thing with LEDs. Would you happen to have the schematic?

-Sterling

Nope, built it off the top of my head with the datasheets, didn't really have time to draw it all out. But it really shouldn't be that hard in the first place.

Have you 'finalized' the end result yet? or do you just want to try it out with a bank of LEDs first or what?

'cause I'm thinking that you just get a PIC up and running, oscillator, a few buttons, maybe an LCD for diagnostics, and your bank of LEDs. Get them blinking the way you want, make the LCD work, make the buttons respond...then we can get working on applying some PWM to the LEDs. Since you'll have more than a couple of outputs to control, software PWM, timer interrupts, and a few other things will have to be used. Then after that's done, modify the outputs to run electromagnets instead of the LEDs by replacing the LEDs with the MOSFET/flyback/magnet combo.