The exercise of trying to use PWM to control motor speed is a subsection of a larger project that was also used to demonstrate some prototype techniques in the Project 14 Circuit Prototype Techniques challenge. I've continued to work on the project. The Project 14 opportunity motivates me to take up the task and do some documenting along the way.
The goal of the larger project is to develop a train animation sequencer. Train#1 (TR1) leaves the station and travels a loop of track to return to the station to stop. Train#2 (TR2) then leaves the station, travels the same loop and returns to stop at the station. Once Train#2 returns Train#1 runs the pattern again. This sequence continues indefinitely. The final design has both an east and west set of trains shown in the drawing.
The animation sequence has been broken down into a series of stages for each of the train pair. The stages are Train Stopped, Train Departing, Train in Transit, Train Arriving to end with Train Stopped. All the stages will need to be able to control the speed of the train by either accelerating it, decelerating it or stopping it. This is where PWM techniques should come in handy
The sequencing project layout uses a series of IR sensors, track switches and motor controllers all managed by Arduino code to make the whole animation possible. This submission looks at applying PWM to move a locomotive.
Bill of Materials:
Geekcreit® L298N Arduino module Dual H Bridge Stepper Motor Driver Board
Geekcreit® MEGA 2560 R3 ATmega2560 MEGA2560 Development Board
Andrea Lombardo/L298N Arduino Library
Test locomotive(s)
The Arduino using the L298N software library, will produce PWM to the L298N driver module. The driver module using a train power supply will feed PWM signal to the locomotive.
I'm told, the Model Railroaders club has a device to establish the speed of the locomotive to scale. How fast a locomotive moves through the sidings versus in the loops is critical for realism. I hope to use the device to determine code values so the speeds can be accurate for the stages.