LudoMTR (Part 4)

Part 12345

Finally, this the whole picture of the sketch. No library required.


	Copyright (C) 2012 Didier Longueville

	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program.  If not, see <>.


#define maskD 0xFC /* Port D digital pins 2 to 7 */
#define maskB 0x3F /* Port B  digital pins 8 to 13 */

#define CUR_REVERSE -1 /* Current flows from port D to port B */
#define CUR_NONE 0
#define CUR_FORWARD 1 /* Current flows from port B to port D */

long lastCycleTime = micros();
long cycleInterval = 50000; 
char currentDirection = CUR_FORWARD; /* Default current direction */

void setup()
  /* Set ports directions */
  DDRD |= (maskD);
  DDRB |= (maskB);
  /* For diag purpose */

void loop()
	cycleInterval = map(analogRead(0),0, 1023, 200, 50) * 1000;
	/* Set next cycle time */
	long nextCycleTime = (lastCycleTime + cycleInterval);
	/* Wait next pulse */
	long now;
		now = micros();
	while(now < nextCycleTime);
	/* Set current flow */
	/* Flip current direction for next pulse */
	currentDirection *= -1; 
	/* Record last pulse time */
	lastCycleTime = now;
	/* Set pulse stop time */
	long pulseStopTime = (lastCycleTime + long(cycleInterval * 0.6));
	/* Wait until pulse duration has elapsed */
		now = micros();
	while(now < pulseStopTime);
	/* Cancel current */


void setCurrent(char value)
/* Set current flow between PORTB and PORTD pins */
  switch(value) {
		PORTD |= (maskD);		
	case CUR_NONE:
		PORTB &= ~(maskB);	
		PORTD &= ~(maskD);	
		PORTB |= (maskB);			

Set the potentiometer to half way, watch the blinking control led and gently spin the rotor shaft. Synchronizing the rotor and the alternative magnetic field is pure chance. You may have to retry multiple times.


Q – The control led does not blonk
A – Check the wiring (short circuits)

Q – The control led blinks and the rotor oscillates but will not turn
A – Check the magnet position, retry synchronizing the rotor

Q – I manage to start the rotor but if fails accelerating when I turn the pot
A – The pot should be move (very) slowly in order to give the rotor a chance to keep synchronized with alternative magnetic field.

Q – It is difficult for me to achieve low rotor speeds
A – Check rotor balance. Adding a mass on one shaft end may help achieving a smoother operation

Q – Yesterday LudoMTR was working like a charm and it fails to start today
A – Electric contacts must be in perfect condition. Clean then.

Q – Which speeds can I achieve with LudoMTR?
A – I depends very much on the design of the hardware part. Reasonably, you should achieve 500 to 1000 RPM.

Q – How can I improve the performances of my LudoMTR?
A – Maintain clean contacts, adjust the rotor position so that the gap between the magnet and the moving coil is small as possible. You may use contact spray which contain conductive lubricant. Graphite powder (from pen) does not work so well.

Next post on same subject

Leave a Reply

You must be logged in to post a comment.