I am currently building a controller for a slot car track.

These work by placing a car on a track on two rails that supply the DC motor of the car with current.

The track has an input of 20 V and has a 3 pin output for the controller. The original controller simply has a rheostat in it that regulated the voltage in the motor.

I want to build a controller that uses a MOSFET and PWM from an Atmega 328.

Here is the problem I am facing:

The polarity of the power supply to the track can change, because different track configurations mean that the car can travel in different directions.

To prevent any damage to the MOSFET I added a rectifier before the MOSFET.

The issue I am facing now is that I need to include a flyback diode across the motor but since the direction and polarity of the motor is possibly different, I don't know how to orient the flyback diode.

The additional challenge is I can only build something connected to the 3 right pins indicated on the picture.

How can I add a flyback diode to this motor which turns in either direction?

enter image description here

  • \$\begingroup\$ Use the circuit diagram tool and draw a schematic \$\endgroup\$
    – Voltage Spike
    Feb 9, 2021 at 14:36

2 Answers 2


Putting a MOSFET inside a bridge rectifier is a good way of ensuring that the MOSFET always receives the correct polarity but there are two issues to consider: -

  • You'll need to optically interface with the MOSFET to control it because you have "lost" any reference point to actual ground.
  • There will be losses in that there are two diode drops in the current path.

To protect the MOSFET you can add a zener diode in parallel with it inside the bridge rectifier. It needs to be rated at a voltage greater than the incoming power supply i.e. 24 volts.

Or, get hold of a MOSFET based solid state relay - these will be optically isolated internally and should do the job for moderate frequencies of PWM (maybe up to 1 kHz): -

enter image description here

Turn on and turn off time are around 1 ms for the device above but there will be quicker devices.

But, you'll still need flyback protection and this can be formed by two series back-to-back zener diodes of the appropriate voltage and current rating.


Well, it would be way easier to put the mosfet before the inversion switch. In this way snubber diodes could be put on the inversion contacts. If you want to do it in this way the "bidirectional power switch" is quite a big issue, as already said in the comments.

Since current is quite modest (I hope) in slot cars, a good solution could be to use two back-to-back P-channel mosfets. They are way less performant for technological and physical reason but no problem for some amps of current. It's also better since you only have one diode loss (a body diode) instead of two.

Since they are p-channel you don't need to translate the gate voltage with an optocoupler, you just need to pull it down from the power supply (with an n-channel or a bjt, your choice).

If you look in TI appnote SLVA948, you'll see some ideas. Obviously they want to sell their product but in figure 12 you could see a basic circuit to work with.

  • \$\begingroup\$ You don't have one diode loss for two MOSFETs wired as an SSR. \$\endgroup\$
    – Andy aka
    Feb 8, 2021 at 18:00
  • \$\begingroup\$ Yes you're right my fault. They are both in full enhancement \$\endgroup\$ Feb 8, 2021 at 18:18
  • 1
    \$\begingroup\$ Yes but, I don’t think it will turn on the MOSFETs very well when trying to connect the load to the most negative rail when the load is fed from the most positive rail. That’s why a photovoltaic opto isolator is used in SSRs. \$\endgroup\$
    – Andy aka
    Feb 8, 2021 at 19:18
  • \$\begingroup\$ Eliminate the requirement for a fly back diode, use a MOSFET that has the appropriate avalanche rating. This also helps simplify the circuit. The polarity of the track will change but the polarity of the power source will not. \$\endgroup\$
    – Gil
    Feb 8, 2021 at 21:04
  • \$\begingroup\$ he said that the source switches polarity depending on the piece of track. That, or I got the spec wrong. Relying on avalanche rating is a bad thing IMHO, especially on PWM application where it's really repetitive. A good RC snubber would do the job here but it's tricky to design. \$\endgroup\$ Feb 8, 2021 at 21:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.