Close

Motor control: faster and faster

A project log for Building the Thor robot

Building a 6-axis robot based on the Thor robot. When size DOES matter!

Olaf BaeyensOlaf Baeyens 05/14/2017 at 20:480 Comments

Testing for faster speed.

I am using a timer interval to trigger the motor motion.

By having a loop of "NOP" I managed to get a predictable step pulse of 2.24 - 2.32µS

void MotorExecutionBlock::StepDelay() {
	// Code blow should be about 2 µS on a 84 Mhz Arduino Due
	for (auto i = 0; i < 40; ++i) {
		asm("nop \n");
	}
}

void MotorExecutionBlock::SendMotorStepCommand(byte step_command) {
        REG_PIOC_SODR = PIO_PC3;		    // X_AXIS_STEP set to high
        REG_PIOB_SODR = PIO_PB26;		    // Y_AXIS_STEP set to high
        REG_PIOD_SODR = PIO_PD0;		    // Z_AXIS_STEP set to high
        REG_PIOC_SODR = PIO_PC16;		    // E0_AXIS_STEP set to high
        REG_PIOC_SODR = PIO_PC19;		    // E1_AXIS_STEP set to high
        REG_PIOA_SODR = PIO_PA19;		    // E2_AXIS_STEP set to high
        REG_PIOC_SODR = PIO_PC7;		    // E3_AXIS_STEP set to high

	// Delay 2 micro seconds
	StepDelay();

	REG_PIOC_CODR = PIO_PC3;		    // X_AXIS_STEP set to Low
	REG_PIOB_CODR = PIO_PB26;		    // Y_AXIS_STEP set to Low	
	REG_PIOD_CODR = PIO_PD0;		    // Z_AXIS_STEP set to low
	REG_PIOC_CODR = PIO_PC16;		    // E0_AXIS_STEP set to low
	REG_PIOC_CODR = PIO_PC19;		    // E1_AXIS_STEP set to low
	REG_PIOA_CODR = PIO_PA19;		    // E2_AXIS_STEP set to low
	REG_PIOC_CODR = PIO_PC7;		    // E3_AXIS_STEP set to low
}
Which gives these fine tuned motor control

I now speed up the clock pulses (driven by an interrupt) and get a speed of 32 Khz

The bonus is that I have at this speed only used 7.6% of the CPU processing cycles,, I still have 92.4% of available time to do something useful with the processor.

Controlling 7 stepper motors at 32 Khz and have 92% CPU processing power to spare. Think we are on to something. :-)

I also have been running at this speed for 5 minutes and no smoke to see.

Discussions