Pinball solenoids come with designations like 23-800. The first number, 23 in this case, represents the American Wire Gauge (AWG) used. The second number, and the more important number, is the number of windings which is related to its power rating. A solenoid with less windings, say 400, is more power and is used for such applications as actuating the flippers. These solenoids get very hot very quickly, which increases the resistance of the solenoid thereby decreasing the current and therefore the power. To avoid overheating, these high powered solenoids will have two coils. One for the main actuation of the solenoid, and another to maintain the position. The second solenoid will have a smaller wire gauge and more windings. In example, my flipper 'coils' are 15-411, 15 AWG and 411 windings. They are quite strong and found in some of the latter Williams pinball machines such as the popular Adams Family machine.
You can find a lot of good additional information, such as the required voltages (which I wish I had found earlier) for the solenoids from different eras of pinball machines, here at PinballMedic.net.
I happened to buy a bunch of 23-800 solenoids because I was not exactly sure what I was going to use them all for. If I start running my 32 volts through them and not turn them off, they'll likely get hot, melt something, and most probably catch on fire. They only have 4 Ohm resistance when cool, and when run on 32V they draw 8 amps of current or 256 W. That's not good. So if I want control the power, I need to control the voltage. This way I'll be able to use the 'wrong' type of solenoid for various other tasks.
A good start to the comprehensive control of the voltage for the solenoids would likely be turning them on and off. What I needed was a solenoid driver board. This is a circuit board that takes the 5V logic from my Arduino microcontroller and turns off and on the power to the solenoids using a metal oxide semi-conductor field effect transistor (MOSFET). This is now the most common type of transistor out there. Bi-polar transistors used to be common but MOSFETS switch faster and require lower gate voltages, ie. the voltage to turn it on.
The switching speed is important because to control the power I used what is called pulse wave modulation or PWM. A PWM signal is typically a square wave signal that jumps between 0V and say 5V in the case of logic circuits. Depending on the time between these pulses of 5V you can get an average, lower voltage. This is only possible because often whatever component you are driving, in this case a solenoid, reacts to the signal a lot slower. Because the solenoid reacts so slowly to the signal, it only sees an average voltage. The 'average' voltage can be controlled by changing the duty cycle. If the PWM signal is at 60% duty cycle, what it is powering will see 60% of the voltage if it cannot react fast enough.
This rapidly changing signal can also be smoothed out using 'filters' so the solenoid does see the average voltage instead of relying on the lagg of the solenoid to average it for you. Simple filters consist of a resistor is series and a capacitor. In the case of the pinball solenoids, a series resister is a bad idea as it would fry due to the high current. I can however, use a large capacitor to smooth out the voltage. An excellent PWM tutorial is available here. It is also where I nicked this very fancy PWM animated .gif from.
I built a basic solenoid driver board using the following components:
- IRF530 Power MOSFET *Note: No longer available
The power MOSFET controls the power to the solenoids. The AND gate combines the PWM signal and a I/O signal from the microcontroller. The combined signal is sent to the optocoupler which switches a higher voltage to the MOSFET's gate to turn on the MOSFET. The higher voltage is required to fully turn on the MOSFET otherwise it would not run at it's max current rating or switch at the required rate for the PWM. Alternatives for the optocouplers are smaller transistors / non-inverting buffers.
Silly me using 3 AND
gates when I only have 8 outputs. I was thinking it was a good idea
to use a separate one for the flipper controls, but it doesn’t
matter! Oh well, had to resolder the board but I at least now have
DIP sockets for the chips
It was not working
right anyways. As soon as I turned on all the solenoid circuits it
would not work. I hooked up LEDs to the circuits to see what was
happening. Now I had some odd occurances happening. I would place my hand closer to the MC
and they would turn on instead of being off or half lit. The LEDs
would actually glow brighter as my hand got closer. I could touch an
optocoupler and it would turn on one light or more. It was like
having a capacitive sensor but not really.
After I had resoldered
the board, it still did it and with different AND gates. I checked
all my outputs on my MC, made sure none of the pins were floating but
I was getting some feedback into the MC from the PWM. Very not good.
I even took it to one of my coworkers who’s an electrical engineer
and he couldn’t figure it out. Well, that same friend happened to have given me a
bunch of electronic parts he was not going to use because he’s all
about surface mounted components now and too good for DIP chips
anymore! I took a couple of the AND gates, assuming they weren’t
the cheap ones I purchased, and it works like a charm! Guess it goes to
show you, you get what you pay for. For those of you who want to
know, the AND gates I had were from Motorola and Texas Instruments.
I did have another problem, as at this time I was rather unaware of floating pins. If an input to an intergrated circuit (IC), such as an AND gate, is not tied to ground or to a voltage it will 'float'. Floating means that it might randomly change its logic level for fun. So you could end up with components turning on when you do not want them to. Whenever I turned on my microcontroller all the mosfets would activate even though I did not apply any voltage to them. This was easily solved by tying the input pins of the AND gates to ground with a 10 kOhm resistor. This resistor is called a pull-down resistor because it makes sure that the AND gate inputs are LOW when the microcontroller is turned on.
As a rule of thumb, all unused inputs for every single IC should be tied to a pull up or pull down resistor. This ensures no floating pins.
As a rule of thumb, all unused inputs for every single IC should be tied to a pull up or pull down resistor. This ensures no floating pins.
To give you a better
idea of what is happening I took some photos of my oscilliscope while
checking the circuits. Yes, I have one. I only have one because I
managed to get it for $25 bucks from a local highschool who were
getting rid of electrical equipment for some reason.
This photo shows the
output of the optocoupler. You can see it laggs behind the real
signal which is a square wave. This means that the optocoupler is actually rather slow. The PWM signal is generated from the microcontroller and is a rather lower frequency.
The output of the MOSFETs.
The above photo is the output of the MOSFETs. It is a nice square wave but this is more by happenstance. The MOSFETS turn off at a low voltage so even though the optocoupler output is slow to come back to ground, the MOSFET does not shut off until the voltage is low. Because the MOSFETs can switch faster, it results in this nice square wave though the signal stays HIGH for twice as long as the original signal. This narrows the range of duty cycles for which this setup will work. Hardly, ideal but at least it works.
great job! thanks for sharing
ReplyDeleteWhat kind of diode did you associate with the MOSFET?
I never thought anyone looked at this. I have not posted in a few years as I changed careers, moved etc. Pretty much you can use any rectifying diode to deal with the flyback across the mosfet, such as the 1N4148. The IRF510 did not have one integrated, but the P40NF10 I ended up using later on does. You should also have one across the solenoid to prevent voltage spikes due to the solenoid de-energizing.
DeleteI did make a mistake and changed my design to analog timing using caps and schmitt-trigger as I wanted to offload the work from my microcontroller as much as possible. However, it has more than enough processing power to deal the switching times. Also, I needed to use higher precision potentiometers to set the timing (20 to 40 ms). Anyways, thanks for posting. Maybe I'll update this thing.
answer in your other post 1N4148
ReplyDeletehttps://mikesprojecttracker.blogspot.fr/2012/04/pwm-voltage-control.html
:)