I have successfully used L298N with arduino uno & R3 to control model railway trains (OO scale), both speed and direction, and with brushed and coreless motors (max 12v DC). Some of the locos have directional red and white LEDs. All was well until, on one particular relatively new loco all of the LEDs flicker (red and white together) no matter the direction. The motor has low value ceramic capacitors and chokes across the relevant motor tags. I have tried lowering the PWM frequency of PIN 3 (490 to 122.55). Any slower, the quality of the speed control is reduced. It reduced the flicker somewhat but not totally. I am limited with making changes to the internal PWM speeds because I use timers throughout, shift-out chips to control signals and master/ slave setups.
This is a long shot to see if anyone else uses arduinos to automate train layouts who might have a solution.
Can you apply 100% duty cycle to the loco (straight from power supply to wheels, or whatever passes power from the rails to the motors)? If you can not, do not proceed with my advice. If you can, does touching the power supply to the wheels still cause flicker? If no flicker, clean your wheels and/or rails.
It is DCC ready (Digital Command Control, but is set up for DC, power from rails go straight to a standard 5 pole motor. The LEDs at each end has usual resistors and additional diodes.
When standard power control is applied directly the LEDs work perfectly.
I volunteer at an Education Centre, building an automatic railroad, teaching all of the usual skills including coding.
The locomotive I am talking about was a ‘donation’. I have a similar one of my own, which is fine. I am not ruling out that the loco has been tampered with is some way. It will not be the first which has needed “surgery”!
The second post is much better but I cannot troubleshoot from a wiring diagram, an annotated schjematic showing all connections, power, ground and power sources would help a lot. Also note what the power supplies are capable of. The L2998N is an obsolete part that just burns energy. The output is ~ 3 volts less then the power supply because of the darlington drivers it uses. I suggest you get one that uses MOSFETs in the driver stage.
Are you planning to keep it non-DCC?
It might be worth finding a circuit to keep a stable supply to the LEDs
Older locos with filament lamps just took the lamp supply off the motor supply.
Had a meter on it?
What locomotive is it?
Yes, I have been considering the TB6612FNG. When the time permits I will write up some code and try it. As they use I2C it frees up 3 pins for something else.
I had considered DCC. The project is for a charity demonstration and costs are an issue. Even using a DCC shield, the locomotive chips would be costly. The loco is a DMU twin set which does have an old motor. My trouble-shooting has identified the motor as the culprit. The is a charity project and I have to work with donated items - not an easy task at times!
That's nice to hear.
I'm a big fan of the DMUs that used to operate out of Kings Cross to Cambridge and Bedford.
I grew up on the old LNER main line so lots to see. The Deltics were impressive and both neighbours worked on the railway. I even bagged a ride on one of the Class 4 diesel shunters.
There are a few things you can do to improve old motors. Some have felt washers on the motor shaft that need lubrication and the old iron magnets can be swapped for stronger neodymium types.
I have an old Triang dock shunter that looks as though it uses a DMU type chassis.
The filament headlamp runs off the motor supply so is shaky. I will change it to a warm white LED and maybe add a capacitor to smooth out the noise.
Not easy with a DMU, but with the dock shunter, I'm going to add some more pickups on a small trailing wagon.
PWM always gives you full voltage and coupled with an MCU, you can programme in things like soft starts.
Sounds like a good project.
Good luck with it.
My favoured railway is LNER. The layout I have automated is an end to end SR/WR layout (OO) made by John Wylie, accomplished model maker, worked on the original Thunderbirds set. I have a DMU, a H class loco with an auto coach, and class 4 with a two car with DVT. I have three arduinos controlling turnouts and signals. I have coded it with some random charged, to make it look like it is being operated. Like you say all motors are different. I have a potentiometer for each loco which ‘trims’ acceleration, braking and top speed.