An FPGA for LEGO MindStorms Roboter
|
This page is about interfacing the sensors and motors of the
LEGO Mindstorms
series with an FPGA. The FPGA is the substitute for the LEGO RCX.
I will use JOP - the Java Optimized Processor - as soft-core inside the FPGA
to program the robots with a real-time enabled version of Java.
Or see it the other way round: A LEGO robot is the test case for the real-time
properties of JOP.
However, other processors, such as NIOS, are also fine.
This project is about interfacing: A Simple Line FollowerThe first simple roboter is running - a line follower. An exercise that kids solve in an hour. I needed a little bit longer because I had to solder some components, drill holes, write VHDL code and a few lines of Java ;-) A small movie: linefollow.mov Interfacing the SensorsFigure 1 shows how the RCX interfaces with the LEGO sensor.
We can see the 3ms periode where the sensor is powered for about 2.8ms.
The power is switched off for about 200us and a 0-0.4mA current sink
provides the output signal. The voltage is generated by a pull up resistor
to 5V.
T1 and T2 are switched by the FPGA output SP1 to power the sensor with the
unregulated voltage (V+). When switched off, the current sink will generate
a voltage on the 10k pull up (R9 to the regulated 5V). R10, R11, C3 and IC1
build the integrator and comparator for the sigma-delta ADC in the FPGA.
SDO1 is driven by the FPGA and SDI1 is the input. VCC is 3.3V, the IO-voltage
typically for most FPGAs.
The 9-bits ADC could generate values from 0 to
511. However, the values of R9, R10 and R11 limit the range: 130 (on a short
curcuit) to 447 (leaving the input open). for (;;) { // 0V ... 130 (short) // 5V ... 447 (open) int v = Native.rd(Const.IO_ADC1)-130; v *= 81; // v = v/3.17 v >>>= 8; if (v<0) v=0; if (v>100) v=100; Dbg.intVal(v); RtThread.sleepMs(500); } Motor DriverFirst we will take a look how the RCX drives the motor. Figure 3 shows a free running motor with power level 1. The startup can be seen in Figure 4 and a blocked motor is shown in Figure 5. All oscilloscope figures show both motor outputs with respect to battery ground.
The RCX uses simple PWM with a period of 8ms (= 125Hz) and 8 steps of 1ms.
As we can see from the voltage levels during the off part of the PWM both
output drivers are disabled. However, when the RCX shuts the motor off both
drivers are active low to break the motore.
When comparing Figures 4, 7 and 10 we see the difference in the acceleration.
The final velocity is allmost the same for all power levels for a free
running motor.
The voltage drop on the output transtors can be seen with the blocked motor:
Less than 1V on the high-side transistor and about
0.5V on the low-side transistor.
The L293 is an old and therefore common part.
The input levels of the L293D are 3.3V compatible and it has integrated
clamp diodes, thus making the interface from the FPGA to the motor trivial.
The main disadvantage of this part are the bipolar push-pull outputs having
a large voltage drop compared to a FET output stage.
The ADC is our workhorse sigma-delta ADC. The main difference to the former
ADC is the the higher ratio of the two resistors. With the ratio of 10 the
input range is between -14.85V and 18.15V (-1.65V*10 + 1.65V and 1.65V*10 + 1.65V).
There is no VHDL file for this PWM as it was simpler to generate it in Java
and JOPs scheduling is fast enough for this timing ;-) The PWM frequency of the RCX is quite low. We will change this, but add a longer off-time from time to time for the back-EMF measurement. Figure 16 shows one example. This example is still done in Java. A VHDL version generating this PWM and triggering the sigma-delta ADC will follow. -- stay tuned -- Now it's time to play some LEGO! I should build my first simple robot and let JOP control it before I move on with the back-EMF stuff ;-) ReferencesThere are a lot of good websites available about the internals of the LEGO MindStorms, substitutes for the RCX operating system (even a small JVM is available) and how to build your own sensors.Here are only a few links, that where helpfull to build the FPGA interface. Larry Barello has a good introduction how LEGO sensors work. A lot of information can be found at Michael Gasperis sensor page. Acroname has a good explanation how back-EMF measurement. Systronix builds a substitute for the RCX, called JCX. It consists of peripheral prints for the aJile Java processor powered JStamp. In my opinion they are using too many hardware components. However, they are providing the schematics of their board, a nice gesture. ConclusionAs I'm currently building the system it's too early to draw conclusion ;-)ContactIf you have comments or suggestions please drop me a note: martin@jopdesign.comIf there is enough interest in a PCB that contains the FPGA interface I will probably route one. | |
| |
Copyright © 2000-2007, Martin Schoeberl
|