Jump to content

Banner.jpg.b89429c566825f6ab32bcafbada449c9.jpg

DIY Moon Phase Dial


Gina

Recommended Posts

After sleepping on it, one thing I ought to check is the time taken to complete the test run as I shall rely on this to calculate the time offset required to allow for the clock setting time.  I expect this to be slightly longer than 20,000 x delayTime due to processing time.

Result :- 40636 for delay time of 2ms and 20,000 steps, so 636ms added to the 40,000.  Test run five times and exactly the same result every time.

// Filename :- Moon_Clock_Test_for_NEMA16_stepper_02
// Arduino speed test sketch for NEMA16_stepper
//
int delayTime = 2;    //  Time between steps (ms)- 5ms gives 200 steps/s or 360° per sec = 1 revoultion per second
boolean done = false; 
unsigned long time;
//
int dirPin = 10;  // DIRECTION pin
int stepPin = 11;  // STEP pin
//
void setup() {
  Serial.begin (9600);     // Enable Serial Monitor via USB
  pinMode(dirPin, OUTPUT);
  pinMode(stepPin, OUTPUT);
  digitalWrite(dirPin, 0);
  }
//
void stepForward(void){
  digitalWrite(stepPin, 1);
  delayMicroseconds(10);     // Make STEP pulse at least 10μs long
  digitalWrite(stepPin, 0);
  delay(delayTime);          // delay between steps
}
//
void loop(){
  if (done) {return; }
  Serial.print(" Start Time: ");
  time = millis();
  //prints time since program started
  Serial.println(time);
  for (int i = 20000; i >= 0; i--) { stepForward(); }  // rotate motor shaft 100 turns
  Serial.print(" Finish Time: ");
  time = millis();
  //prints time since program started
  Serial.println(time);
  done = true;
}
// End

 

Link to comment
Share on other sites

  • Replies 1.1k
  • Created
  • Last Reply

Now for a more realistic test of setting the clock.  6 hours is 360m which is 360 revolutions of the seconds hand.  Each revolution of the seconds hand needs 6/5 of the motor which makes 432.  Multiplying by 200 steps/rev = 86400.  If we round this up to 100,000 for convenience, representing about 7 hours, it gives a time of 200,000ms @ 2ms / step = 200s or 3m 20s.

Link to comment
Share on other sites

Results :- 203217  203217  203217.

Proportion due to processing time = 1.016085.  For 40,000 steps proportion = 1.0159.  That's a pretty consistent 1.6% to be added for processing time.  For setting clock to 7 o'clock with a time of 3.33m this represents an additional time of 3.2s.  I don't think we need bother about that :)

Link to comment
Share on other sites

New motor gear and seconds wheel printed (to cater for the increased spacing).  25t and 30t at about mod 2.  I've also been working on the ali plate and spacers.

56e8a1d9dda5f_AliPlateGearTrain01.thumb.

Link to comment
Share on other sites

I'm not really keen on the aluminium plate but it will do for now to get the clock working and test the design.  I may replace it with a 3D printed structure later which will also provide a housing for the electronics.  I'm thinking of having the "works" attached to the case rather than the clock face.  This will have to wait until I have one of my larger 3D printer working well as it's too big for the little UP Plus 2.

I plan to add the stepper motor to the ali plate today.

Link to comment
Share on other sites

The code for calculating the number of steps required to set the clock from 12 o'clock to the correct time needs modifying to suit the new stepper motor.  This was the code for the little stepper, using 5s intervals and spurts of 8 half-steps.  Now we want 1s interval and steps.

  h = hour(); if (h >= 12) { h = h - 12; }  // convert 24hr clock to 12hr
  units = h * 720;
  units += minute() * 12;
  units += second() / 5;
  steps = units * 4;  //  was 16
  extra = steps / 600;
  steps = steps + extra;

Conversion to 12h clock remains the same but we now want the time advance in seconds.  h x 3600 + m x 60 + s then multiply by 4 for the number of steps.  Then the "extra" of one sixtieth of this if the fast speed is 60x normal speed, using a step time of 5ms or 150x with a step time of 2ms and divide by 150.  2ms stepping seems to be fine so the divisor for extra is 150.

  h = hour(); if (h >= 12) { h = h - 12; }  // convert 24hr clock to 12hr
  units = h * 3600;
  units += minute() * 60;
  units += second();
  steps = units * 4;
  extra = steps / 150;
  steps = steps + extra;

Of course, the "units" are now seconds so I might change the variable name but I have to be careful not to clash with other variables for seconds.

Link to comment
Share on other sites

Aluminium plate carved out to take NEMA16 motor and motor mounted.  Have to admit, I find metalwork rather tiring these days :(  Just as well most of what I used to do can now be done with a 3D printer :D

Link to comment
Share on other sites

Here's a photo of the ali plate with motor and gears mounted onto the clock face.  Next thing to try is running the clock fast forward.  I'll put the hands on first so that i can see what happens.  I have a feeling I may have to slow it down a bit :D

56e9814e7b6f2_AliPlateGearTrain02.thumb.

Link to comment
Share on other sites

It runs but doesn't half make a rattly clattery noise from the gears :D  Unfortunately, the hands were not out far enough and caught on the raised numbers so I need to increase the thickness of a spacer - no problem.   Back shortly...

Link to comment
Share on other sites

That's better :)  And I've reduced the rattling a bit by applying some white silicone grease to the teeth.  Had a fairly good run of about five minutes with 150,000 steps.  Now to test that it will stop in the right place at speed by advancing by a whole number of minutes.  Let's atart with one hour, which is what is wanted for "changing the clocks".  3600s in an hour so steps required is 4 x 3600 = 14400.

Result :- 3 seconds slow.  I'll try at 5ms.  Result :- about half a second slow.  I think that's probably good enough - the clock will only need setting at startup or for "changing the clocks".   Still make quite a racket though.  Mind you, it's got a great sounding box :D

Link to comment
Share on other sites

Phew!!! :D  And that's only testing!  Looking promising though :)

OK...  Next step is to combine the new motor drive code with the main code that sets the clock to 12 o'clock, then to the right time and finally running at the correct rate.

Link to comment
Share on other sites

Decided to get the new gears run in a bit more and the results have improved :)  Strangely, the gears make less noise when run fast so 2ms is quietest, 3ms is moderately noisy and 5ms is a lot noisier :eek:  The one hour advance is now losing just one second at 2ms step rate

Now trying an advance of 5 hours at 2ms per step.  Result :- 5s slow.  If, as things are ATM with setting to the minute, 5s is well adequate.  If I wanted accuracy to the second I would need to add a position sensor to the seconds.  This could be added behind the aluminium plate on the seconds shaft.  Normal clocks are not set to this accuracy - radio controlled clocks just set the minutes and hours with the seconds at random.

Of course, I could go one better than commercial clocks and have mine accurate to the second if I so desired.  Might upgrade to that later but for the moment I shall be satisfied with and accuracy of within 10 seconds.

Link to comment
Share on other sites

Now advancing 10 hours at 2ms per step.  Result :- 10s slow.  Acceptable.  I'll run it again to confirm.  Still 10s slow so no error this time.  Running for the third time...  Maybe the gears are getting "run in" :D  An extra second slow :)

Link to comment
Share on other sites

Repeatedly running the 10 hours advance with a 2ms step delay is resulting in the seconds hand stopping at the same place every time now and I reckon the gears are now "run in".  This speed is now showing no significant positioning error and I feel confident that I can use the 2ms step delay for setting the clock and for changing by the hour in spring and autumn with adequate accuracy :)

Link to comment
Share on other sites

Having finished "running in" and confirmed the fast setup mode the next thing is to make the clock run at the required speed for normal operation which is 4 steps per second.  To reduce accelleration and decelleration of the motor the steps should be sent at a regular rate of a step every 0.25s.  Both edges of the RTC square wave may be used to get a 0.5s period and a delay of 250ms used for the intermediate step.

Link to comment
Share on other sites

 Firstly then we set the main loop to call runClock on both rising and falling edges of the RTC square wave giving a 500ms period.

int val = digitalRead(2);  // read logic level of 1Hz square wave
if (val != lastSqWave) { lastSqWave = val; runClock(); } // Call runClock on both edges of RTC square wave

Now runClock has to send two equally spaced step calls each period of 500ms

void runClock() {  // subroutine called on both edges of the RTC square wave
// Send 2 steps to motor every half second
  stepForward(); //  1st step on clock edge
  delay(250);
  stepForward(); //  2nd step after delay of 250ms - next step will be on next clock edge at 500ms
}

This routine sends a pulse to the STEP input of the stepper driver

void stepForward(void){
  digitalWrite(stepPin, 1);
  delayMicroseconds(10);     // Make STEP pulse at least 10μs long
  digitalWrite(stepPin, 0);
}

For the setting up phase, the stepForward routine is called repeatedly with a 2ms delay between calls and therefore between steps.  This routine produces a number of steps with a delay between them

void fastForward(long steps) {  
  for (long i = steps; i >= 0; i--) { stepForward(); delay(2); }  // step then wait 2ms before next step
}

 

Link to comment
Share on other sites

To move the clock backwards the DIR input of the stepper driver is set to a logic 1 and pulses applied to the STEP input exactly as for forward motion.  Really the stepForward routine could do with renaming as it does both directions.

void fastBackward(long steps) {  
  digitalWrite(dirPin, 1);   // Set DIRECTION to backwards
  delayMicroseconds(10);     // Wait before sending STEP pulses
  for (long i = steps; i >= 0; i--) { stepForward(); delay(2); }  // step then wait 2ms before next step
  digitalWrite(dirPin, 0);   // Set DIRECTION back to forwards
}

 

Link to comment
Share on other sites

Blown my board up :(  Don't know how or why but I smelt burning that you get from frying resistor and the Arduino Nano is now dead as a dodo :(

Link to comment
Share on other sites

Annoying!!!  I was just about to check the full clock operation with the new motor.  Now to search for another Nano - should have one or two around...  I've checked the board for solder hairs and removed anything suspicious so keeping fingers crossed that a nwe Nano will work and that the rest is alright.

Link to comment
Share on other sites

Found a Nano kit, soldered the legs on, uploaded the sketch to it, plugged it into the socket and plugged the PSU into the mains.  All working fine but running the clock at 4 discrete steps per second it's very noisy and the seconds hand is almost shaking itself to death :eek:  I think I'll change the running mode to 16x microstepping giving 64 microsteps per second and more or less a sweep seconds hand.  Microstepping reduces the power so hopefully will make less noisy but if the buzz or 64Hz is too loud I might look into providing some springiness in the drive.

Link to comment
Share on other sites

I have experimented with changing the speed when setting the clock and by starting with a step delay of 2ms for the first 100 steps and then changing up to 1.2ms the clock spins very smoothly and more quietly than at 2ms.  Then I detect the hour hand at 12 o'clock (which occurs well before the minute hand get up to the top) and change to 5ms for sensing the minute hand at 12 o'clock.  The 5ms speed is very noisy so maybe it could do with microstepping to smooth it out a bit.

To achieve microstepping is simply a matter of connecting the three MS data inputs to an Arduino digital output (D12 is available and just needs connectinng).  Then the driver can be set to full steps or 16x microstepping by changing the D12 output.  Alternatively, I could use microstepping for all modes.  I would probably reduce the rattling.

Link to comment
Share on other sites

Changing to 16x microstepping means increasing the stepping rate by 16 times - no really?? - yep :D  That's 64 microsteps per second or 32 per half second and 15.625ms between microsteps - 15625μs.  Best to reduce this a bit to allow for processing time - I'll try 15600 - 25μs should be enough.  STEP pulses are about 10μs long - maybe 12 or 13 with processing time so still a good 10μs between pulses I think.  A for loop of 32 cycles will do the job.

void runClock() {  // subroutine called on both edges of the RTC square wave
// Send 32 μsteps to motor every half second
  for (int i = 32; i >= 0; i--) { stepForward(); delayMicroseconds(15600); }
}
Link to comment
Share on other sites

I've wired the three MS inputs to D12 so I can run either full step or 16x microstepping.  If it turns out that 16x is used all the time it's simply a matter of setting D12 to logic 1 in the setup.

To run the 2ms rate at 16x microstepping would mean 125μs - that's alright.  Likewise,  5ms would become 400μs and 1.2ms would be 75μs.  These all seem quite feasible.  That's if the motor has enough power to drive the load - I think it should have even though running at 16x microstepping reduces the power by 10x.

Link to comment
Share on other sites

Well, the microstepping seems alright except that there's a point on one of the motor to seconds gears that is catching, so that wants looking at.  Microstepping has certainly quietened it down.  If I can't find and cure the catching point on the gears I could change to 8x microstepping for more power.  I need to strip the clock down anyway as I want to alter the spacers again - the hour hand catches on the numerals.  In fact it caused it to break near the axle, so it will need gluing up.

Link to comment
Share on other sites

Fixed the gears - no binding now - nice and smooth :)  In normal running mode the noise is audible but not excessive.  I might be able to dampen it down a bit.  No problem with running at full speed either.  Little bit of rattling but much reduced by adding some white lithium grease.  Checking the timing by checking the seconds when the second hand is on the 12 o'clock mark shows no error over 5 minutes or so.  I'll leave it running overnight and see if the seconds still check out.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. By using this site, you agree to our Terms of Use.