Feedback from the car

Now I have a reasonable RF link, I’ve been trying to get the car to drive around the track.

I have a slightly odd setup for controlling the power to the track.  Because I made this up before my Arduino arrived, I’ve got a Xilinx FPGA on a Basys-2 board setup to control the track.  This board is quite handy because it has 8 on-off switches and 8 LEDs (and a variety of other things) on it.

Up until now, I’ve controlled the voltage with the switches.  The design loaded on the FPGA is very straightforward, I’ve got an 12-bit counter counting up at the clock frequency (50MHz), and when the top 8 bits are greater than the value set on the switches, power is applied to the track through a Darlington pair of transistors.

I added a simple serial channel from the Arduino to the FPGA so it could set the voltage.  This was a very straightforward design: 2 wires, a clock and a data line both driven from the Arduino.  Data is sent 1 byte at a time, simply by sending 1 pulse on the clock line, and then 1 bit of data each subsequent time the clock rises.  To make this slightly complicated, the Arduino outputs are at 5V, and the FPGA’s maximum allowed rating on an input pin is 4.4V.  So I’ve got a simple voltage divider to get the inputs down to 2.5V.

Initially, this didn’t quite work – it appears that at the 50MHz frequency of the FPGA the signal was bouncing – I fixed that by ignoring changes in the clock line until it was stable for 16 cycles (I suspect less would have worked, but it doesn’t need to be *that* fast).

I have the value sent from the Arduino displayed on the LEDs on the FPGA so I can see what is going on.  The top switch on the FPGA now selects whether the value from the Arduino or the value set on the rest of the switches controls the power to the track.

My first proof of concept was to simply increase power to the track until the accelerometer detected any movement, and back off until the movement went away, then increase again.  This successfully made the motor hum without the car moving (perceptably).

I now have it set up to increase the power while the accelerometer readings are close to their average values, drop the power if they start deviating a bit, and cut the power significantly if they go over a certain value.  This allows the car to go round the track in fits and starts, but without flying off.

Finally, mchr3k has taken my Manchester library changes and is now hosting the definitive version here.  I’m including that as a submodule in my Arduino repo.  I’ve also made a new repo for the FPGA design.

Comments are closed.