Author Topic: DIY wall chain clock  (Read 6549 times)

0 Members and 2 Guests are viewing this topic.

Offline Kaptein QKTopic starter

  • Regular Contributor
  • *
  • Posts: 82
DIY wall chain clock
« on: September 03, 2014, 10:45:55 pm »
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:


3D files:
http://www.thingiverse.com/thing:450985

Code:
Code: [Select]
//*
 * 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);
}
}
}



 

Offline miguelvp

  • Super Contributor
  • ***
  • Posts: 5550
  • Country: us
Re: DIY wall chain clock
« Reply #1 on: September 03, 2014, 11:30:01 pm »
Nice, and to set the time you just need to pick up the chain and place it in the right time :)
 

Offline Dave

  • Super Contributor
  • ***
  • Posts: 1356
  • Country: si
  • I like to measure things.
Re: DIY wall chain clock
« Reply #2 on: September 04, 2014, 02:53:55 am »
Lovely project. :-+

Seeing that your circuit is powered by a wall wart (is it AC?), you could use the line frequency as a super accurate time reference (many clocks do that). No need to play with delays and hope that you get it right. ;)
<fellbuendel> it's arduino, you're not supposed to know anything about what you're doing
<fellbuendel> if you knew, you wouldn't be using it
 

Offline Kaptein QKTopic starter

  • Regular Contributor
  • *
  • Posts: 82
Re: DIY wall chain clock
« Reply #3 on: September 04, 2014, 08:59:58 pm »
Thanks :)

It is a DC adapter.
The delay routine uses a hardware timer, and current delay is started from where the previous ended.
Thus code run-time does not affect the delay time.
All delays in the loops adds up to the required 4.5 seconds per step, and I have not seen any inaccuracy yet.
We will see how good it is over long time :)
 

Offline JohnWard

  • Contributor
  • Posts: 12
  • Country: gb
    • Youtube jjward
Re: DIY wall chain clock
« Reply #4 on: September 04, 2014, 10:39:33 pm »
could use the line frequency as a super accurate time reference (many clocks do that).
AC line frequency is typically rather inaccurate, and will vary depending on the total load on the system.

UK line frequency in real time: http://www2.nationalgrid.com/uk/industry-information/electricity-transmission-operational-data/


 

Offline SArepairman

  • Frequent Contributor
  • **
  • Posts: 885
  • Country: 00
  • wannabee bit hunter
Re: DIY wall chain clock
« Reply #5 on: September 04, 2014, 11:50:47 pm »
i thought they deliberately slow/speed it up sometime to sync up line clocks.
 

Offline Dave

  • Super Contributor
  • ***
  • Posts: 1356
  • Country: si
  • I like to measure things.
Re: DIY wall chain clock
« Reply #6 on: September 05, 2014, 04:02:29 am »


AC line frequency is typically rather inaccurate, and will vary depending on the total load on the system.
The instantaneous frequency is all over the place. The long-term accuracy, however, is very good.

i thought they deliberately slow/speed it up sometime to sync up line clocks.
That is exactly what they do.
<fellbuendel> it's arduino, you're not supposed to know anything about what you're doing
<fellbuendel> if you knew, you wouldn't be using it
 

Offline VK5RC

  • Supporter
  • ****
  • Posts: 2672
  • Country: au
Re: DIY wall chain clock
« Reply #7 on: September 05, 2014, 08:34:14 am »
THE time nut Tom V B has measured the accuracy of mains http://leapsecond.com/pages/mains/.
Great clock.
Whoah! Watch where that landed we might need it later.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf