It uses 3D printed parts (mostly painted),
an Arduino Nano (code written in C in Atmel Studio 6),
a L298N dual H bridge (no micro-stepping, but uses software controlled PWM soft-stepping, completely silent)
and a Nema17 stepper motor (coil resistance 32 Ohm).
Video:
https://www.youtube.com/watch?v=Cqu5ZlmXVh8 (https://www.youtube.com/watch?v=Cqu5ZlmXVh8)
3D files:
http://www.thingiverse.com/thing:450985 (http://www.thingiverse.com/thing:450985)
Code:
//*
* chainclock.c
*
* Created: 8/29/2014 11:06:29 PM
* Author: Rolf R Bakke
*/
#include <avr/io.h>
void delayMicroseconds( unsigned long delay) {
static unsigned long timeStart;
unsigned long timeCurrent;
if (delay == 0) {
TCCR1B = 0b00000011; //set TCNT1 to run at 250kHz.
TIMSK1 = 0b00000010; //turn on Timer/Counter1, Output Compare A Match Interrupt
timeStart = (unsigned long)TCNT1 << 2;
return;
}
do {
timeCurrent = (unsigned long)TCNT1 << 2;
} while (((timeCurrent - timeStart) & (unsigned long)0x0003ffff) < delay);
timeStart = timeCurrent;
return;
}
int main(void) {
DDRD = 0b11111111;
PORTD =0b00001001;
TCCR0A = 0b10100001;
TCCR0B = 0b00000001;
delayMicroseconds(0);
while(1) {
for(uint8_t i=0xa0; i>=0x01; i--){ //ramp down coil A
OCR0A = i;
delayMicroseconds(10000);
}
PIND = 0b00000011; //flip coil A polarity
for(uint8_t i = 1; i <= 5; i++) delayMicroseconds(250000);
delayMicroseconds(50000);
for(uint8_t i=0x01; i<= 0xa0; i++){ //ramp up coil A
OCR0A = i;
delayMicroseconds(10000);
}
for(uint8_t i=0xa0; i>=0x01; i--){ //ramp down coil B
OCR0B = i;
delayMicroseconds(10000);
}
PIND = 0b00001100; //flip coil B polarity
for(uint8_t i = 1; i <= 5; i++) delayMicroseconds(250000);
delayMicroseconds(50000); //adjust this delay to correct the clock
for(uint8_t i=0x01; i<= 0xa0; i++){ //ramp up coil B
OCR0B = i;
delayMicroseconds(10000);
}
}
}