I have found this code that I am going to ready through in detail https://github.com/KensCode/TrainMotor but I am a little concerned about the PWM frequency requirements:
I have not read about this high frequency requirement anywhere else that references using a H Bridge to control model train motors.Although PWM acts like DC, it is essentially a form of AC and can heat objects via arcing if a short circuit occurs (e.g., if a train derails or shorts a turnout by running into it the wrong way, or even while placing a train on the tracks). This can be intense enough to melt plastic models or even weld wheels to track. With a smaller power supply, the risk is lesser but not absent. With a 2 Amp or larger supply the risk of fire or damage to the model or to a person attempting to remove it is higher. Always turn the power off before touching a train. Don't leave a motor shield powered up unattended. Small children should not use motor shields unsupervised.
Has anyone here successfully built a train controller who may be able to point me in the right direction ?