After posting Hacking the LEGO Mindstorms NXT Standard Motor, I received several requests for more information regarding the wiring of the motor.
The NXT cable has six wires. Below I list a table with the wires and their colors:
The WHITE and BLACK wires (Motor 1 and Motor 2) deliver power to the motor.
If standard batteries are used, the potential difference will be 9 volts, otherwise the NiMH rechargeable batteries provide 7.2 volts. If the white wire is positive and black is negative, the motor will turn one way. If you reverse the polarity, the motor will turn the other way.
The RED wire is connected to the ground (GND). Note that in the sensors, RED and BLACK are connected to one another. This is not the case in the motors.
The GREEN wire is connected to the +4.3 NXT power supply.
The YELLOW and BLUE wires are connected to the quadrature encoder, also called an incremental rotary encoder.
As shown in the figure from Wikipedia above, (http://en.wikipedia.org/wiki/Quadrature_encoder) the wires return square wave pulses that are 90 degrees out of phase. If the rising pulse on TACH00 leads the rising pulse of TACH01 by 90 degrees, then the motor is going forward. If it instead lags by 90 degrees, the motor is rotating backwards. One complete square wave cycle corresponds to 2 degrees of rotation. In the diagram above, if TACH00 refers to A and TACH01 refers to B, we can see that the motor is going backwards as TACH00 is lagging TACH 01.
By measuring the frequency of the square wave oscillation, one can compute the rotational velocity. Since one cycle corresponds to 2 degrees of rotation, one cycle per second (1 Hz) corresponds to 2 degrees/sec. If you record a frequency of X Hz, then the rotation rate is 2X cycles/sec.
Note also that by tracking both square waves, you can identify quarter cycles, which gives you a resolution of 1/4 of 2 degrees, which is 0.5 degrees.
The motor speed is controlled by pulse-width modulation (pwm), which works by driving the motor with a variable duty cycle square wave. This effectively turns the motor on and off, fast. The longer it is on, the more torque it will generate and the faster it will go.
These details and more can be found in the excellent book: Extreme: NXT with a sneak peak here.
Additional details can be found in the excellent book Extreme NXT: Extending the LEGO MINDSTORMS NXT to the Next Level (Technology in Action) by Michael Gasperi, Philippe E. Hurbain, and Isabelle L. Hurbain.
Philo uploaded a comment, and reminded me that “Note that there are some internal photos of the NXT motor here: http://philohome.com/nxtmotor/nxtmotor.htm and schematics here: http://www.brickshelf.com/cgi-bin/gallery.cgi?i=1846577”
Thanks for the plug ;o)
Note that there are some internal photos of the NXT motor here: http://philohome.com/nxtmotor/nxtmotor.htm and schematics here: http://www.brickshelf.com/cgi-bin/gallery.cgi?i=1846577
there are 2 pwm signals for each output port. but which one is used to control the motor. black or white?
The WHITE and BLACK wires (Motor 1 and Motor 2) are used in conjunction to deliver power to the motor. If the white wire is positive and black is negative, the motor will turn one way. If you reverse the polarity, the motor will turn the other way. They both must be pulse width modulated (pwm) to achieve variable speed.
antonio moyano says:
Hello. I am a teacher of Spain and I need to move the motor with arduino degree to degree (steps of 1º). How can I do? thank you
Sorry for the horrible delay in my reply.
We have not solved this problem.
You would need to monitor the two encoder lines which would allow you to determine changes in angle of 0.5º.
Keep current going to the motor until you have rotated the desired amount.
We have not yet implemented the code to monitor the angle changes.
When we do, we will post the solution.
how can i control other motors using the NXT ? can I connect the wires to a toys car motor – for example ?
is there any constraint on the length of the RJ12 cable ??
I don’t know of any constraints.
I use 1 meter long cables for some of my applications and there have been no problems.
Hi. Thanks for the info, very helpful. I’d like to know how we can generate the two pwm signals (a link maybe) because i tried with a pic16f84a (output max) but the voltage it delivers is too low.
DIY Arduino Circuit | BrickEngineer: LEGO Design
Derek Powles says:
If the output shaft ‘rocks’ about a stationary position and the tacho signal is close to one square wave edge then false readings of shaft position results. This can be resolved by what used to be called a ‘state machine’.
TKJ Electronics » NXT Motor Shield
Use Lego for Making High Speed Photography Pictures