Jump to content

Banner.jpg.b83b14cd4142fe10848741bb2a14c66b.jpg

DIY Moon Phase Dial


Gina

Recommended Posts

LOGGING :- Clock 4:01  Real Time 3:57:32pm.  Clock fast by 3m 28s.

That's the last manually logged time error!!!  <Exits stage left muttering>...

Link to comment
Share on other sites

  • Replies 1.1k
  • Created
  • Last Reply
On 03/03/2016 at 17:25, Gina said:

// void timerIsr() { if (!timeIsSet) { return; } // Ignore the interrupt and return while setting the clock gbCount ++; // Increment gearbox count if (gbCount >= 63) { gbCount = 0; moveForward(2); } else if ((gbCount % 5) != 0) { moveForward(1); } // normal step // Turn motor current off digitalWrite(motorPin4, 0); digitalWrite(motorPin1, 0); digitalWrite(motorPin2, 0); digitalWrite(motorPin3, 0); delayMicroseconds(delayTime); // Allow time for motor to step } //

I think I have got it!

Delaymilliseconds won't work relaibly inside an ISR!

You need to set a flag in teh ISR than call a stepper move(s) from the main loop.

Apologies if I have misunderstood your code

Link to comment
Share on other sites

16 minutes ago, Stub Mandrel said:

I think I have got it!

Delaymilliseconds won't work relaibly inside an ISR!

You need to set a flag in teh ISR than call a stepper move(s) from the main loop.

Apologies if I have misunderstood your code

Um... I'm using delayMicroseconds which the guru says does work as it doesn't use interrupts.

Link to comment
Share on other sites

Anyway, stuff interrupts I'm using polling! 

Just hope I get on better with that 'coz I'm not having the best of days (though I did print a new bracket for the 400mm imaging rig which is fine :) )  Popped out to the local farm shop for milk and veggies but they had closed about 10 minutes earlier :( So I went on to the next village thinking the shop would be open.  It said "Open" so I parked but the door was locked and I found they closed at 2pm  :frown:

Link to comment
Share on other sites

I've modified the sketch to use polling - both for the 1Hz square wave timing signal from the RTC and for the Hall sensor that detects when the minute hand is at 12 o'clock.  An if statement detects the change of state then another checks for true before calling the appropriate subroutine.

The runClock() subroutine replaces the ISR and displayTime() does just that.  Now we have automatic logging and will be able to see how good the timing is by displaying the time when the Hall sensor detects the minute hand just before the 12 o'clock position.  This position is about 12s before the centre of the mark so I expect the time to read hh:59:48 or thereabouts.

The clock has been set a few minutes after 7pm and was right (within a few seconds) at 7:05pm.  Automatin logging will begin at 8pm and every hour thereafter.  Or it should do :D

// Filename :- Moon_Clock_with_RTC_17 2016-03-05 1830
// Arduino test sketch for moon clock with RTC
// Software timing from RTC on pin 2 using polling
// Everything to do with the seconds motor has been removed
// moveBackward has been removed
//
#include <DS3232RTC.h>    //http://github.com/JChristensen/DS3232RTC
#include <Time.h>         //http://www.arduino.cc/playground/Code/Time  
#include <Wire.h>         //http://arduino.cc/en/Reference/Wire (included with Arduino IDE)
//
int timeError = 16;  //  Amount of time setting error to be corrected
boolean timeIsSet = false;
//declare variables for the motor pins
int motorPin1 = 3;  // Blue   - 28BYJ48 pin 1
int motorPin2 = 4;  // Pink   - 28BYJ48 pin 2
int motorPin3 = 5;  // Yellow - 28BYJ48 pin 3
int motorPin4 = 6;  // Orange - 28BYJ48 pin 4
int lookup[8] = {B01000, B01100, B00100, B00110, B00010, B00011, B00001, B01001};  // phase patters for stepper motor
int delayTime = 1000;  //  Time between steps (μs) for fast motor speed
int gbCount = 0;    // Counts seconds for gearbox correction
long steps, h, units, extra ; // time set variables;
int lastSqWave = 0, lastHallMinute = 1 ; //  Save logic states of square wave and Hall sensor for minute hand
//
void setup() {
  Serial.begin (9600);     // Enable Serial Monitor via USB
  pinMode(motorPin1, OUTPUT);
  pinMode(motorPin2, OUTPUT);
  pinMode(motorPin3, OUTPUT);
  pinMode(motorPin4, OUTPUT);
  pinMode(2,INPUT_PULLUP);   //  One sec timing pin
  setSyncProvider(RTC.get);  // the function to get the time from the RTC
  if(timeStatus() != timeSet) 
      Serial.println(" Unable to sync with the RTC");
  else
      Serial.println(" RTC has set the system time");
  RTC.squareWave(SQWAVE_1_HZ);    // 1 Hz square wave            
}
//
void moveForward(long steps) // Used to move the hands forward as fast as possible for setting clock
{
  for (long s = 0; s < steps; s++) {
    for(int i = 7; i >= 0; i--)
    {
      digitalWrite(motorPin1, bitRead(lookup[i], 3));
      digitalWrite(motorPin2, bitRead(lookup[i], 2));
      digitalWrite(motorPin3, bitRead(lookup[i], 1));
      digitalWrite(motorPin4, bitRead(lookup[i], 0));
      delayMicroseconds(delayTime);
    }
  }
}
void stepForward(void)  // Normal clock advance of 8 half-steps per call
{
  for(int i = 7; i >= 0; i--)
  {
    digitalWrite(motorPin1, bitRead(lookup[i], 3));
    digitalWrite(motorPin2, bitRead(lookup[i], 2));
    digitalWrite(motorPin3, bitRead(lookup[i], 1));
    digitalWrite(motorPin4, bitRead(lookup[i], 0));
    delayMicroseconds(10000);
  }
}
//
void runClock() {  // subroutine called on every rising edge of the RTC squawre wave
  gbCount ++; // Increment gearbox count
  if (gbCount >= 253) { gbCount = 0; }              // skip call to stepForward
    else if ((gbCount % 5) != 0) { stepForward(); } // normal call to stepForward but skip 1 in 5
 }
//
void displayTime(void)  // Digital time display on Serial Monitor
{
    // digital clock display of the time
    Serial.print(hour());
    printDigits(minute());
    printDigits(second());
    Serial.print(' ');
    Serial.println(); 
}

void printDigits(int digits) {
  // utility function for digital clock display: prints preceding colon and leading 0
  Serial.print(':');
  if(digits < 10)
    Serial.print('0');
    Serial.print(digits); }
//
void loop(){
  if (timeIsSet) { 
    int val = digitalRead(2);  // read logic level of 1Hz square wave
    if (val != lastSqWave) { lastSqWave = val; if (val) {runClock();} }
    val = (analogRead(A7) < 500);  // Read logic level of Hall sensor for minute hand
    if (val != lastHallMinute) { lastHallMinute = val; if (val) { displayTime();} }
    } 
//  
  if (timeIsSet) { return; } //  break out once time is set
  Serial.println(" Setting hands to 12 o'clock");
  while ((analogRead(A6) > 500) || (analogRead(A7) > 500)) { moveForward(1); } // move fast forward until 12 o'clock sensed
  moveForward(timeError);   // correct error
  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;
  Serial.print(" Moving hands to ");
  Serial.print(h); Serial.print(":");
  Serial.print(minute()); Serial.print(" using ");
  Serial.print(steps);
  Serial.println(" steps");
  moveForward(steps);
  timeIsSet = true;
}
// End

 

Link to comment
Share on other sites

The stepper bench test stopped with the pointer about 5° short of the target.  If the number of revolutions was correct the error works out as 1 in 7200 or half a second in an hour.  I'll change the sketch and reduce the number of revolutions to check.

Time logged on the clock for the 9pm event was 20:59:41.

Link to comment
Share on other sites

20 revolutions counted and stopped about 1° short confirming the 100 revs being 5° short.  So the gearbox on its own is slightly out but not like it was in the clock.

Link to comment
Share on other sites

Stepper bench test stopped in the right place after 100 revolutions when run at five times the speed - delay of 2ms per half-step.  Maybe sometime these results will make sense :D

Link to comment
Share on other sites

This table copied from the log and with the time difference in seconds per hour added.  This shows quite a lot of difference but not as bad as when I was manually logging and the timing used interrupts.

 20:59:41
 21:59:31 10
 22:59:10 19
 23:59:07  3
 0:58:52  15
 1:58:42  10
 2:58:39   3
 3:58:22  17
 4:58:20   2
 5:58:02  18
 6:57:45  17
 7:57:41   4
 8:57:30   9

Average over 12 hours is 2m 11s, which is 10.6s per hour. 131s in 43200s is 0.003 or about 1 in 330.  If this correction were added the error would be less than 10s which would be acceptable for the hours and minutes with the residual error corrected every hour from the RTC.  What to do about the seconds hand has yet to be decided...

Link to comment
Share on other sites

Current correction (apart from the 1 in 5) is 1 in 253 = 0.00395 and we want another 0.003 giving about 0.007 and 1 in 144.  So replacing the 253 with 144 should provide the correction required.  Now why the timing in the clock differs so much from another stepper motor on bench test is a puzzle.  If the amount of error is constant it would not be a problem as I can correct for it but I have no guarantee that it will be, which is worrying.  I don't like unsolved puzzles :(

Link to comment
Share on other sites

Start of a new log of RTC reading when hour hand Hall device triggered around 18s before the mark.  Timing rate adjusted but no reset to RTC on the hour yet - this is just logging with adjusted error correction.  I might leave this running to provide an idea of longer term errors.  Currently logging on my main desktop PC but I might transfer to a laptop so that clock testing is independent of main PC.

56dc1cbc81874_LoggingTimeErrors04.JPG.66

Link to comment
Share on other sites

Five hours or so logging and I can't see any noticable improvement - I seem to be still chasing shadows :(

 11:59:42  Reference
 12:59:27  15
 13:59:15  12
 14:59:12   3
 15:58:57  15

Is it time to completely rethink this project and use a different drive method.  Maybe some extra gears and a pendulum?? :icon_rolleyes:  More practically might be a a different motor drive.  I shall still be making my long case clock though - with weight and pendulum.  Perhaps I should shelve this clock and work on the big one :D

Anyway, this moon phase clock is running in parallel with production of parts for my 400mm imaging rig.  Currently printing brackets for the guider. While still waiting for the new USB hub.

Link to comment
Share on other sites

Here's an update on the log results.

 11:59:42  Reference
 12:59:27  15
 13:59:15  12
 14:59:12   3
 15:58:57  15
 16:58:52   5
 17:58:34  18
 18:58:13  21

Link to comment
Share on other sites

FWIW another log update...

    TIME    Seconds gained in the last hour
 11:59:42  Reference
 12:59:27  15
 13:59:15  12
 14:59:12   3
 15:58:57  15
 16:58:52   5
 17:58:34  18
 18:58:13  21
 19:58:10   3
 20:57:59  11
 21:57:44  15
 22:57:37  13
 23:57:16  21
  0:57:11    5
  1:57:00   11
  2:56:46   14
  3:56:44    2
  4:56:30   14
  5:56:10   20
  6:56:01    9
  7:55:43   18
  8:55:41    2

Link to comment
Share on other sites

I've been looking at other stepper motors but apart from odd ones with little data, the next cheapest are NEMA 17s as used for 3D printers but these are rather big and I'll need to see if I can fit it within the present case.  They can be used with the standard 3D printer driver module so there's no problem there.  Stride angle is 1.8° so 200 steps per revolution.  A 3:10 gear ratio would give one step per minute.  A suitable ratio for construction would be 9:60 giving 2 steps per minute but with microstepping an almost smooth motion is possible.  16x gives 32 microsteps per minute and just over 2s per microstep.

Link to comment
Share on other sites

You can get smaller format motors - NEMA 11 or 14, and they all can come with an optional planetary gearbox if you want with various ratios from 5:1 up to 100:1. I'm using a 5:1 ratio NEMA 17 on my focuser but have some others ordered (on a slow boat from China ;-) ) to play with. I've ordered 19:1 and 27:1 to increase torque and steps/rev at half-stepping.

ChrisH

Link to comment
Share on other sites

Thanks Chris :)  Yes, I know these smaller motors are available (somewhere) and the UP printers use NEMA 14 motors.  OTOH there are NEMA 17s that are small enough to fit my clock at 34mm deep but a smaller 12v motor would make more sense if not too expensive.

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.