Tue 27 Dec 2011
Ok, I have to admit, I may be an evil genius – or just plain sadistic; I’m not sure which.
On my Christmas vacation I decided to work on a project that I have had in the queue for about 2+ years. When I had my last model railroad, I had a carnival on one side of the layout. The main attraction of the carnival, besides the massive Ferris Wheel, was a ride called “Top Spin“. It was a complicated ride to build and the build-out was even more complicated due to one of the main parts being broken when I received the kit. Of course I didn’t know the part was broken until I was 50% complete with the kit – too far to send it back.
After fixing the broken part and finishing the kit, I added it to the layout and tested it out. I didn’t work very well and seemed to only partially work right. More fiddling and more fixing lead to a kit that mostly worked. Here’s a picture of the ride shortly after placing it on the layout:
I’ve never been completely happy with the results and have always wanted to dig into why the kit didn’t seem to work quite right. Well, after 2+ years of waiting, today was they day. Well, it actually started yesterday, but I finished today. I took a deep dive into the mechanics of the Top Spin and built a new controller to completely figure out what the problems were. Well, not really. The new controller seemed to work much better than the stock controller, so I can only speculate on the problems.
I used a SN754410 half H driver coupled to an Arduino to control the motors on the Top Spin. After figuring out how to set up the pulse width modulation (PWM) capabilities of the Arduino, I set out to control the Top Spin.
My initial attempts actually went very well, but the motors moved fairly slowly – much more slow than what I remembered. I’m pretty sure the motors are 5V DC, and I was using the 5V from the Arduino, but things didn’t move as quickly as I remembered with the stock controller. A little investigation lead to the 1.1V-1.5V drop across the H-bridge circuitry. That means the highest voltage that can be applied to the motors tops out at about 3.5-4 volts rather than 5. Hmpfh.
A little digging into my spare parts led to a variable voltage regulator and a 12V DC power supply. I quickly whipped up a variable voltage regulator using a surface mount version of a LM317. The new power supplied fixed the speed problem and yielded a full 5 volts across the motor. With that problem solved I set out to fully build out the code to drive the animations.
I needed to control 2 motors, read 2 reed switches, and output to two status LEDs. The LEDs are optional, but helps debugging. To adequately control the animations I will need to read the status of the reed switches while keeping the motors going. That requires continuously reading the inputs while changing the outputs. Seems like I’ll need to read the inputs in the “background” using interrupts while driving the motors in the main loop.
Pulsing the motors is easy with the built-in capabilities of the Atmel part used in the Arduino; however, it wasn’t entirely clear which timers where used to control the PWM and which were available to use for other purposes. A little spelunking into the ATMEGA328P data sheet identified Timer 2 as an appropriate timer for interrupts.
To simplify my code, I used a timer library called FlexiTimer2 from the Arduino website. I’ve used it in the past and it has worked well. Loading the code into my project was easy and the timer worked the first time, so I was off to the races. I started with a simple sequence of spinning around with the main arm and then rotating the chair where the people will sit. After some time playing around I quickly realized I need to ensure the animations start from the same place every time or the timing will be off – the arm and chair will end up in different place each time.
Using the reed switches and some fine tuning, I was able to return the chair to the “home” position reliably every time. From there I continued to randomly build animation sequences without a lot of regard to timing or position of the chair. Without a lot of thought, I ended up with a pretty scary ride. A lot of upside down, backward spinning. After watching it run a few times, I have to say, if I was on that ride, I’d be scared sh*tless. I am an evil genius
Here’s a short video of the setup and the ride.
You’ll notice the Arduino on the far right and the breadboard with the motor controller and voltage regulator next to it. The ride was connected to the controller with spring clips and jumpers I had laying around.
I noticed after some playing around the voltage regulator seems to drop out if I run both motors at the same time. I’m guessing it’s because the SMD part does not have any sort of heat sink. Hopefully that will be fixed when the whole thing is soldered together.
You can also see in the video where the arms hit the sides and cause the gears to grind a bit. That’s what all the tape is for – to try and hold the sides completely vertical. I know once it’s cemented into place it will work fine (experience speaking), but on my desk it’s a little more difficult to pull off.
So after 16 or so hours fiddling around, I have to say I’m quite pleased with the outcome and the ease of getting everything to behave like I wanted. I guess the next step is to whip up some schematics and a PCB to act as a shield for the Arduino.
It will be a quite some time until I can get the next MRR up and running, but I now know I have a solid HW and SW platform to build from in the future.