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?