Author Topic: Using Arduino To Drive A Quartz Clock / Lavet Stepping Motor  (Read 105 times)

MJLorton

  • Administrator
  • Hero Member
  • *****
  • Posts: 817
Using Arduino To Drive A Quartz Clock / Lavet Stepping Motor
« on: February 01, 2021, 12:25:32 PM »
Sketch for clock pulse:

// Quartz Clock / Lavet Stepping motor Pulse Generator - Martin Lorton (mjlorton.com) Jan 2021
// Read more on how the Lavet Stepping motor works here: https://en.wikipedia.org/wiki/Lavet-type_stepping_motor
// Learn more about this code and how to drive a Quartz Clock /
// Lavet Stepping motor here: https://youtu.be/NLwb-lgjv9M (https://youtube.com/mjlorton)

unsigned long StartIntervalMillis = 0;
unsigned long CurrentIntervalMillis = 0;
const long PulseInterval = 45; //Sets pulse width in milliseconds

int PulsePos = 40; //Pin used for positive pulse (Arduino DUE, change for other boards)
int PulseNeg = 41; //Pin used for negative pulse (Arduino DUE, change for other boards)
int state = 0;
int PulsePin = PulsePos;
int NewPulse = 1;


void setup()
{
  pinMode(PulsePos, OUTPUT);
  pinMode(PulseNeg, OUTPUT);

  digitalWrite(PulseNeg, LOW);
  digitalWrite(PulsePos, LOW);

  Serial.begin(9600);
}

void doPulse()
{
  state = (digitalRead (PulsePin));
  if (state == 0 && NewPulse == 1)
  {
    StartIntervalMillis = millis(); // Timing for pulse width and 1 second interval resets here.
    digitalWrite(PulsePin, HIGH);
    NewPulse = 0;
  }
  CurrentIntervalMillis = millis () - StartIntervalMillis;
  if (state == 1 && CurrentIntervalMillis >= PulseInterval)
  {
    digitalWrite(PulsePin, LOW);
    if (PulsePin == PulsePos) // Change polarity of pulse. Note polarity won't affect the rotation direction
    {                         // of the Lavet motor / rotor. However, depending on the cogging point / position
      PulsePin = PulseNeg;    // of the rotor, the polarity of the first pulse may or may not rotate the rotor.
    }
    else
    {                          // If it is critical for your clock to start on the first pulse, you will need to
      PulsePin = PulsePos;     // send a "test" pulse before running the clock.
    }
  }
 
}

void loop()
{

  if (CurrentIntervalMillis > 1000)
  {
    NewPulse = 1;
  }
  doPulse();
}
Play, discover, learn and enjoy! (and don't be scared to make mistakes along the way!)

SeanB

  • Administrator
  • Hero Member
  • *****
  • Posts: 987
Re: Using Arduino To Drive A Quartz Clock / Lavet Stepping Motor
« Reply #1 on: February 02, 2021, 03:32:11 PM »
Video's here, part 1 and 2

https://www.youtube.com/watch?v=NLwb-lgjv9M

https://www.youtube.com/watch?v=G3RNolH6Qik


Original crystal clock IC was the CD4045, which is a 21 stage counter, and needed a crystal of a little over 2MHz to run as a clock, though it likely is not a common thing to find these days, though it is still being made by TI.

https://www.ti.com/lit/ds/symlink/cd4045b.pdf
« Last Edit: February 02, 2021, 04:05:21 PM by SeanB »