Clock driver for Sparkfun EasyDriver breakout

Clock driver for Sparkfun EasyDriver breakout

This is a project I’ve done on behalf of a person on an internet forum. The requested operation is simple: Use an EasyDriver stepper motor driver and a 1.8 deg/rotation stepper motor and make the motor turn one revolution per minute. This frees me up a bit not having to select and source products myself, nor having to implement the actual stepper driver myself.

Update: If you need your motor to turn one revolution per hour instead of one minute, download this slightly modified source code instead

The EasyDriver is REALLY simple in operation. Connect 7-30v DC to M+ (and ground to GND), connect a stepper motor to A and B and the motor automatically steps once for each LOW->HIGH transition on STEP. The direction is dependent on the state of DIR (+5v or ground). MS1 and MS2 together defines the step resolution. The driver chip is a Allegro A3967SLB, so the truth table for MS pins can be found in it’s datasheet, page 2.

The breakout board has pull-up resistors on both MS1 and MS2, which puts it in eight-step resolution as standard. To alter MS1 and MS2 you simply pull them to ground individually based on your desired resolution.

I decided to make a few improvements to the requested operation. Via a DIP-switch the user can select the resolution for the EasyDriver while simultaneously altering the steps/minute so it will always make one turn per minute even though the step resolution is changed. There is also an LED to indicate each step. I used a four-way DIP switch, the two remaining switches I used for step direction and to simply turn the steps on or off. The DIR signal is pulled up to +5v by a 10k resistor

My circuit is built on a strip board and is based on an AtTiny25. It’s system clock is driven by a low frequency 32.768kHz watch crystal. It’s important to program the correct fuse bits for low frequency crystal oscillators!

On to the code. I’m using Timer 0 with system clock as clock source in output compare mode. The registers defining when an output compare interrupt hits is altered based on MS1 and MS2 signals on the DIP-switch.

#define F_CPU 8000000UL

#define DIV64 	3
#define DIV8 	2
#define FULL 	!(PINB & (1<#define HALF 	!(PINB & (1<#define QUARTER (PINB & (1<#define EIGHT 	(PINB & (1<
//MS1 pin 7 PB2
//MS2 pin 6 PB1

void step (void)
	PORTB ^= (1<}

ISR(TIMER0_COMPA_vect) //Timer/Counter0 Overflow interrupt routine


int main (void)
	uint8_t previous = 1;
	uint8_t current = (PINB & 36);
	//Port configuration
	DDRB |= (1<	PORTB |= (1<
	//Timer initialization
	TCCR0A |= (1<	TCCR0B = DIV64;	//Timer/Counter0 prescaler
	TIMSK |= (1<	OCR0A = 76;
	/* OCR0A values
	300ms period (ordinary step) =76/div64
	150ms period (half step) 37/div64
	75ms period (quarter step) 18/div64
	37.5ms period (eight step) 76/div8
	sei(); //Enable interrupts globally

		current = (PINB & 3);

		if (current != previous)
			if 		(FULL) 		{ OCR0A=76; TCCR0B=DIV64; }
			else if (HALF) 		{ OCR0A=37; TCCR0B=DIV64; }
			else if (QUARTER) 	{ OCR0A=18; TCCR0B=DIV64; }
			else if (EIGHT) 	{ OCR0A=76; TCCR0B=DIV8;  }

			previous = current;

	return 0;

A final short demonstration, showing the LED indicating step pulses

This article has 4 comments

  1. […] I did a circuit on this subject for a customer – Clock driver for Sparkfun EasyDriver breakout function hidestatus(){ window.status='' return true } if (document.layers) […]

  2. where do I need to put the code please ?


Leave a Reply