Jump to content
Welcome to Backyard Astronomy Space - please register to gain access to all of our features. Click here for more details. ×
SmallWorldsForum Microscopy and macro photography - a companion forum to BYA ×

Moon Dial Clock showing realistic moon phase - 3D printed


Gina

Recommended Posts

The upgraded clock uses the following circuit components:-

            DS3231 Real Time Clock module with very accurate timekeeping
            ESP32 SBC replacing the Arduino Nano
            TMC2100 stepper motor driver replacing the A4988 for quiet operation
            NEMA16 stepper motor with 1.8°/step stride angle
            MOSFETs and resistors to drive RGB LED lighting strip for dial

Link to comment
Share on other sites

More details of the upgrade.

The original version of the clock used a pair of spur gears between the stepper motor and the seconds shaft but these proved noisy in spite of efforts to quieten them such as flexible filament, so these are being replaced with timing pulleys and belt behind the plywood panel.  These will provide a 3:1 speed reduction enabling faster and lighter motor drive for reduced noise.

The stepper driver will be run in 16x micro-stepping to provide the quietest operation of the motor.  There is a special quiet running mode of the TMC2100 using this.  This means that 200x16 micro steps are required for each revolution of the stepper motor ie. 3200.  With the 3:1 reduction the 60s of the seconds hand and shaft becomes 20s per rev at the motor.  Thus 3200 pulses must be sent to the driver module every 20s which is 160 pulses per second.

  • Like 2
Link to comment
Share on other sites

Now comes the tricky bit!  The DS3231 Real Time Clock module is capable of producing various frequency square waves which may be used to generate interrupts in the micro-processor.  These are 1Hz, 1024Hz, 2048Hz and 8192Hz.  Not 160 or any multiple of 10 (or 5) only powers of 2 so my idea is to produce a burst of 5 pulses at a suitable rate.  In this case 5 pulses every 32nd of a second.  32 groups of 5 pulses gives 160 pulses per second average, which is what's required.

The RTC can be set to provide a 1024Hz square wave and this can produce an interrupt on the rising edge giving 1024 interrupts a second.  A count of 32 will produce timing of 32 per second. (1024=32x32.)  This gives a period of 1/32s = 31.25ms.  If we use a short pulse of say 10µs and a space of 30ms we will be inside the 31.25ms  with a little to spare to allow for variations in the micro-processor clock.

Link to comment
Share on other sites

Some links to information about the parts of the clock :-
          DS3231 - https://datasheets.maximintegrated.com/en/ds/DS3231.pdf
          DS3231 with ESP32 - https://circuitdigest.com/microcontroller-projects/esp32-real-time-clock-using-ds3231-module
          ESP32 getting started - https://randomnerdtutorials.com/getting-started-with-esp32/
          ESP32 Interrupts - https://lastminuteengineers.com/handling-esp32-gpio-interrupts-tutorial/
          TMC2100 - https://reprap.org/wiki/TMC2100

  • Like 1
Link to comment
Share on other sites

Found a TMC2208 stepper driver in going through my components, which should be an alternative to the TMC2100, though the micro-stepping controls are different.

1778633188_Screenshotfrom2020-11-1521-13-51.png.b60088faa8e12d58cb0a2c0691084e66.png

 

Link to comment
Share on other sites

For fast setting of the clock I plan to run it fast forwards or fast backwards at 64x normal speed.  This will make use of 2x micro-stepping instead of 16x using the MS2 control pin of the TMC2208 and reducing the division in code from the 1024Hz Square Wave from 32x to 4x.

Link to comment
Share on other sites

This is an initial connection diagram.  I haven't included the MOSFETs to drive the dial LED lights yet.  I think the clock could be run from a 9v supply.  That should be enough to provide power to the stepper motor and yet not too much for the ESP32 which is stated to need between 5v and 12v though 12v is the absolute limit and less is better.

BlockDiagram.png.986d6428813203545e6145acaf65e039.png

 

Link to comment
Share on other sites

Looking at the dial lighting, the there sets of coloured LEDs are controlled by the three PWM output pins.  These go from 0-255 for off to full power.
        analogWrite(redPin,64);
        analogWrite(greenPin,32);
        analogWrite(bluePin,8);

So we have RED at a quarter, GREEN at an eighth and BLUE a mere 32nd of full brightness.  I think the BLUE is insignificant.  With a lower supply voltage the LEDs will not be as bright.

Link to comment
Share on other sites

Done a little bit on the clock. Further stripping down as the mechanics need sorting out as well as the motor drive.  In fact this is the most importand aspect of the job.  Without the hardware sorted out the rest is nothing.

Problem - the seconds shaft appears to be welded to the bearings and the gear. I considering a change of plan.  As I said above, I was going to replace the gear drive from the motor with timing belt and pulleys behind the panel but to do that I would need to print a new gear and employ a new 5mm shaft and bearings. Also, design and print a new motor bracket. Less work would be to replace the stepper motor with a smaller one (I have NEMA14 and NEMA11 motors) still mount it on the panel and change the motor gear for a much smaller pinion.  I think this will still be a lot quieter and involves less work.  I see no point in doing more than necessary.

Link to comment
Share on other sites

The original motor gears were 25t and 30t so if I used a 10t motor pinion it would give 3:1 reduction - same as the timing belt system.  A 5t pinion might be possible but I think that's going too far.

Link to comment
Share on other sites

Designed and printed a 10 tooth motor pinion, mounted a NEMA14 stepper motor and attached the pinion.  Then reassembled the rest of the gears in the clock.  These photos show adding the rest of the gears and the motor mounting.

Gears07.thumb.JPG.17c85eaa94f8b5ef696843cbe8b3b9c8.JPGGears08.thumb.JPG.6d4497e161a2dc9ef5859190934ed9f7.JPGGears09.thumb.JPG.c859953d1fa2be031b281bb926022014.JPGGears10.thumb.JPG.bd81be14554967ba714955dd03efbbfc.JPG

 NEMA17 Mounting 01

Link to comment
Share on other sites

That should be the mechanical parts sorted out - tomorrow I hope to construct the electronics, sort out the code and maybe get the clock working again.

Link to comment
Share on other sites

Updated circuit diagram.  Edit - ESP32 Gnd and Vin are reversed! Plus I've seen other errors.

BlockDiagram2.png.87adaf7010132a25216e44fcfc7e860d.png

 

Edited by Gina
Mistakes in diagram.
Link to comment
Share on other sites

Nearly finished building the circuit board.  Photos show :-
    1. Strip sockets for components and wire links
    2. Solder-side strip breaks
    3. Board populated.

CircuitBoard01.thumb.JPG.2d87d6831d54c0fdca6f9aca5f9e1264.JPGCircuitBoard02.thumb.JPG.c6f13c56ae60dc507ead21961fe59f6c.JPGCircuitBoard03.thumb.JPG.91c838002e04e9724331335bf27d3a7c.JPG
Link to comment
Share on other sites

There's a bit to finish off on the circuit board and then I can start producing code for testing.

The code will consist of several sections :-
   1. Step the clock motor forwards
   2. Set up the RTC and run the clock forwards at normal rate
   3. Run the clock forwards or backwards at high speed
   4. MQTT network messaging system for controlling the motor speeds
   5. Get precise time from the internet to use for setting the time
   6. Anything I've forgotten.

Link to comment
Share on other sites

As a first test we just want to run the motor in 16x microstepping mode at an approximate rate to run the clock at standard speed.

Now some calculations :-
   1. The gear ratio is 3:1 (10t pinion and 30t gear on seconds shaft) so the motor wants to rotate one revolution in 20s. 
   2. Number of microsteps per rev is 16x200 = 3200
   3. 3200 steps in 20 secs is 160 steps per second
   4. We want to send pulses to step the motor at 160 per sec which is a period of 1/160 = 6.25ms
   5. Code wants to be a loop of 6.25ms in which a very short pulse is sent to the stepper driver
   6. 6.25ms = 6250µs

Edited by Gina
Corrected error in text
Link to comment
Share on other sites

Now to the code :-

To send a single step to the motor we set STEP high, wait 10µs and set STEP low. Viz.

67979983_Screenshotfrom2020-11-2318-18-35.png.c0671194839ced35040428b64be3d1ba.png

To send a 10µs pulse every 6250µs the code is simply :-

666032713_Screenshotfrom2020-11-2318-33-52.png.5069e1ce261a5a966523cde08b340e3d.png

 Including setting the GPIO pins on the ESP32 the complete code is :-

1165560092_Screenshotfrom2020-11-2318-38-51.png.d6a3800bc034e02170eccbe362cb9a31.png

 

Link to comment
Share on other sites

First of all the motor didn't run but found the problem by buzzing through with DMM - found the windings went to the wrong pins.  I thought the motor cables would be standard as used in 3D printers to go with the RAMPS boards. ie. windings connected AABB but no they are connected ABAB!! So I've swapped the middle two pins over.

CircuitBoard04.thumb.JPG.1c2a1ae170e25a86ef98580874ab9f1b.JPG

 The clock is running fine and is silent.  I had to put my ear right on the motor to hear it.  This is a great improvement on the earlier version.

A short video :- http://ginad.uk/MoonClock/MVI_0107.MOV

Link to comment
Share on other sites

I was going to set up the RTC next but easier ATM is to check running it at high speed

  3. Run the clock forwards or backwards at high speed

All I need to do to run fast forward is to change the timing and change microstepping to 2x.  The microstepping change will give x8 and the other x8 will be by changing the timing.  So MS2 will want to be 0 and the timing changed from 6250 to 8x that is 781.25µs - 781 is close enough for testing and subtracting 10µs for the pulse width leaves 771µs.  The resulting code is :-

569498615_Screenshotfrom2020-11-2320-34-06.thumb.png.7b31430e932e6c0a1d80b53b21bc6f73.png

 

Link to comment
Share on other sites

The next test will be
    2. Set up the RTC and run the clock forwards at normal rate

This involves setting the RTC to produce a 1024Hz square wave and adding code to use interrupts to run off the square wave.

Link to comment
Share on other sites

On to the code then :-

Firstly to use the Real Time Clock module we include these libraries.  One specially for the RTC, Time functions, and Wire is the way the ESP32 talks to the RTC.

1336784760_Screenshotfrom2020-11-2409-22-13.thumb.png.8138ca8c7927ece03b4ea7afb02cf7c0.png

Then set the square wave output to 1024Hz.

609207661_Screenshotfrom2020-11-2409-23-50.png.5028b55c8a8d4e093216317b342caa3d.png

 

 

Link to comment
Share on other sites

The next stage is to attach an Interrupt Sub Routine to respond to the rising edge of the square wave, count 32 interrupts and then produce groups of 5 pulses to send to the stepper driver.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Welcome to Backyard Astronomy Space - please register to gain access to all of our features

    Once registered you will be able to contribute to this site by submitting your own content or replying to existing content. You will also be able to customise your profile, receive reputation points for submitting content, whilst also communicating with other members via your own private personal messaging inbox. 

     

    This message will be removed once you have signed in.

  • Tell a friend

    Love The Backyard Astronomy Space? Tell a friend!
  • Topics

×
×
  • Create New...