Controlling Baudet clock timing problem

Hi all,

Can you please help me with the following problem that I cannot solve?

I have an old Baudet clock from the Seventies which is controlled by a central using to all connected clocks run at the same time. You could see them in train stations and banks.

I am using an Arduino Uno with a clock module because the internal microseconds get heavily affected by internal processes by the Arduino itself.

Everything runs perfect and the timing is correct.

The Baudet clock is connected by a 2-meter long cable to a relay board which is separated from the Arduino by optocouplers. So there is no electrical connection between the Arduino and the clock. Even the power supply is separated from each other.

When I connect the Baudet clock to the relay board and switch the power on, the Arduino's behaviour becomes erratic. As it runs smoothly before the connection it starts to behave as it becomes tired. The led's flashing on the relay board works sometimes and also the orange light on the Arduino itself start becoming unpredictable. In the end, nothing happens anymore.

I am thinking that the Arduino gets infected by noise generated by the Baudet clock. The Baudet clock is 24 V DC which is powered by another power supply. The Arduino is powered by its own USB power supply.

I do not understand why the Baudet clock is interfering with the Arduino or the timing module. There is really no physical connection between them.

Will placing an RC filter between the Baudet clock and the relay board help prevent noise from reaching the relay board?

Please, can you help me solve this problem? I will appreciate your help and efforts so much and thank you in advance.

Kind Regards,

Chris

Hi Chris,
I would think noise is the problem based on your description but to help we need specific details. Please read How to get the best out of this forum

In particular I would like to see photos of what you have and a schematic (hand drawn and photographed is fine, Fritzy diagram is not).

In general terms noise is picked up by loops of wire, first rule is to group wires together so that the net current in the resulting cable is zero, that is if one wire takes the current to the load and another bring it back then those 2 wires should be bound together physically in a cable so the net current is zero in the cable. Doing that reduces the tendency to pick up noise.

Code would also be useful at some stage.

Read the instructions I linked to before posting anything else.

Thanks,

Hi Perry,

Thank you so much for your reply and help which I do appreciate. I have no problems providing you with the code and the schematic of what I made so far.

Here is the code:

/*
   ##################################################################
   ## Application: Tardis 60 seconds cycle 24 volt pulse generator ##
   ## Version: 1.1.1                                               ##
   ## Creation date (1.0.0): 21 september 2019                     ##
   ## Modification date (1.1.0): 03 december 2020                  ##
   ## Modification date (1.1.1): 14 mei 2021                       ##
   ## Microcontroller: Arduino UNO r3                              ##
   ## Developed by AfriWerX                                        ##
   ## For Walter Seghers                                           ##
   ## Copyright: AfriWerX / Creative Botswana                      ##
   ##################################################################
 */
// Include necessary libraries
  #include <ThreeWire.h>
  #include <RtcDS1302.h>
  ThreeWire myWire(3, 4, 2); // DAT/IO, CLK/SCLK, RST/CE
  RtcDS1302<ThreeWire> Rtc(myWire);

// Initialising global variables.
  // Polarity switch clockline 1
  int Switch_R1 = 11;
  // Polarity switch clockline 2
  int Switch_R2 = 10;
  // Pulse switch clockline 2
  int Pulse_R3 = 9;
  // Pulse switch clockline 1
  int Pulse_R4 = 8;
  // Polarity tracking (1 = Negative / 2 = Positive)
  int Polarity = 1;
  
void setup() {
  // Initialise sketch
  // Set ports to "output" mode
  pinMode(Switch_R1, OUTPUT);
  pinMode(Switch_R2, OUTPUT);
  pinMode(Pulse_R3, OUTPUT);
  pinMode(Pulse_R4, OUTPUT);
  // Set relays 1 to 4 to high
  digitalWrite(Switch_R1, HIGH);
  digitalWrite(Switch_R2, HIGH);
  digitalWrite(Pulse_R3, HIGH);
  digitalWrite(Pulse_R4, HIGH);
  // Initialise RTC and communication
  Rtc.Begin();
  Serial.begin(9600); // Baudrate 9600
  // Set and write the manual <date> and <time> to the RTC
  RtcDateTime cdt = RtcDateTime("May 14 2021", "12:23:00");
  Rtc.SetDateTime(cdt);
}

void loop() {
  // Process loop
  // Getting date and time from the clock module.
  RtcDateTime pdt = Rtc.GetDateTime();
  if (pdt.Second() == 0)
    {
      // Change polarity
      Switch_Polarity();
      // Sent pulse of 2 seconds
      Pulse_On();
    }
  if (pdt.Second() ==2)
    {
      // Turn pulse off
      Pulse_Off();
    }
} // End loop

void printDateTime(const RtcDateTime& dt) {
  // ### This is test code, has to be removed when finished. ###
  // Day of the week
  Serial.print("Day of the week: ");
  if (dt.DayOfWeek() == 1) {
    Serial.print("Monday");
  }
  else if (dt.DayOfWeek() == 2) {
    Serial.print("Tuesday");
  }
  else if (dt.DayOfWeek() == 3) {
   Serial.print("Wednesday");
  }
  else if (dt.DayOfWeek() == 4) {
   Serial.print("Thursday");
  }
  else if (dt.DayOfWeek() == 5) {
   Serial.print("Friday");
  }
  else if (dt.DayOfWeek() == 6) {
   Serial.print("Saturday");
  }
  else if (dt.DayOfWeek() == 7) {
   Serial.print("Sunday");
  }
  // Current date
  Serial.print("Currect date: ");
  if (dt.Day() < 10) {
    Serial.print("0");
    Serial.print(dt.Day());
  }
  else {
    Serial.print(dt.Day());
  }
  // One Tab
  Serial.print("/");
  if (dt.Month() < 10) {
    Serial.print("0");
    Serial.print(dt.Month());
  }
  else {
    Serial.print(dt.Month());
  }
  // One Tab
  Serial.print("/");
  Serial.println(dt.Year());
  // Currect time
  Serial.print("Currect time: ");
  if (dt.Hour() < 10) {
    Serial.print("0");
    Serial.print(dt.Hour());
  }
  else {
    Serial.print(dt.Hour());
  }
  Serial.print(":");
  if (dt.Minute() < 10) {
    Serial.print("0");
    Serial.print(dt.Minute());
  }
  else {
    Serial.print(dt.Minute());
  }
  Serial.print(":");
  if (dt.Second() < 10) {
    Serial.print("0");
    Serial.print(dt.Second());
  }
  else {
    Serial.print(dt.Second());
  }
} // Function end

void Switch_Polarity() {
  /*
   * This function changes polarity.
   * If variable Polarity equals -1 (negative)
   * then the value becomes 1 (positive)
   * else the value will be set again to -1.
   * Thereafter, the relays are set.
   */
   if (Polarity == 1)
    {
      Polarity = 2;
      // Clockline 1 is set to positive
      digitalWrite(Switch_R1, HIGH);
      // Clockline 2 is set to negative
      digitalWrite(Switch_R2, HIGH);
    }
   else
    {
      Polarity = 1;
      // Clockline 1 is set to negative
      digitalWrite(Switch_R1, LOW);
      // Clockline 2 is set to positive
      digitalWrite(Switch_R2, LOW);
    }
}

void Pulse_On() {
  /* 
   *  This function sends the pulse to the clock.
  */
   digitalWrite(Pulse_R3, LOW);
   digitalWrite(Pulse_R4, LOW);
}

void Pulse_Off() {
  /* 
   *  This function sends the pulse to the clock.
  */
   digitalWrite(Pulse_R3, HIGH);
   digitalWrite(Pulse_R4, HIGH);
   // De-activate relays 1 and 2 to save energy
   digitalWrite(Switch_R1, HIGH);
   digitalWrite(Switch_R2, HIGH);
}

I left the test code in. When the clock is not connected all the lights on the relay board are in the correct sequence and duration. The problems really start when the clock is connected.

All cables are like you suggested nicely grouped. I use 4 relay boards that are soldered by the manufacturer on the same circuit board. They can handle 240V/3A and the relays are isolated from the Arduino by Optocouplers.

The Arduino Uno as the Clock module comes from AZDelivery in Germany.

I looked up the circuit I drew :


back in 2020. Here it is in png format:

Here is the connection circuit provided by the manufacturer of the clock module:

Regretfully, the latter comes from Fritzing but that is all I have. I also do not have any photographs of the real-world circuit. The Arduino, the clock module and the relay board are with plastic spacers connected on an aluminium plate.

If you need any more information, feel free to ask me.

I thank you in advance and appreciate your help so much.

Kind Regards,

Chris

Can you provide any actual schematics of how you have everything connected? Any links to the actual relay boards being used?

Why are you not using the hardware I2C pins on the UNO?

Has the code & clock ever functioned correctly? The code looks like it would be rapidly switching some of the relays on and off. Remember that loop runs many times per second, so the code within the if statements in loop will get executed multiple times during the specified second.

Hello David,

Thank you for your reply. At this moment is it not possible to make photographs of the actual situation because the board is in Belgium and I am in Botswana. I will go back to Europe on 21 February 2022 and then I can make photographs of the board exactly like it is.

The code which is controlling the clock was tested thoroughly and it worked nicely. Before version 1, when the internal microseconds were used, the clock worked without any problem. The problem was that those microseconds get affected by the internal housekeeping of the Arduino itself. But there was no interference from the clock itself. The circuit itself and the clock could stand near each other without any problems. However, it was impossible to get the clock keeping the right time because of that internal housekeeping.

The problems really started when I start using the clock module. When it works with the clock connected, the lights on the relay and the Arduino becomes very erratic and finally stop working. You can compare it as if everything becomes to heavy and the Arduino/relay board in the end.

Because the clock module finally controls when those relays are switching, I think the problem is there. However, my knowledge is too limited to be sure.

I appreciate your useful advice.

Kind Regards,

Chris

Hello Chris,
Thanks for the extra information.

Definitely need to see your project, which means photos, I understand if you are not able to send at the moment.

I don't understand what the polarity switching is about, please explain. I am (or used to be) familiar with those kinds of clocks both because they were common in UK telephone exchanges, where I used to work, and because a friend is a collector of them. I even once made a controller of the kind you are making, but maybe no use now as it was a long time ago, ran on a PIC with the code in assembly language.

I see nothing horribly wrong though. Photos please when possible.

Thanks.

I think your problem is caused by repeated switch the polarity output while second == 0.
Try this code, that will limit the functions to running once per second:

void loop() {
  // Process loop
  // Getting date and time from the clock module.
  static uint8_t previousSecond; //saves previous value for Second()
  RtcDateTime pdt = Rtc.GetDateTime();
  if (pdt.Second() != previousSecond) { //check to see if Second() has changed
    previousSecond = pdt.Second();
    if (pdt.Second() == 0)
    {
      // Change polarity
      Switch_Polarity();
      // Sent pulse of 2 seconds
      Pulse_On();
    }
    if (pdt.Second() == 2)
    {
      // Turn pulse off
      Pulse_Off();
    }
  }
} // End loop

Hi Perry and David,

Thank you both again for your input. Let me explain the working of a Baudet clock.

The clock I have works on 24V and on pulses of 2 seconds which are alternating. When you start you give a positive pulse during 2 seconds. Then after 60 seconds you give another pulse but negative this time, after another 60 seconds you give another 2 second pulse but again positive and so on. So every 60 seconds you give a pulse with a different polarity. When you give twice after each other a pulse with the same polarity, the clock will not work.

I will test the code once I am back in Europa and can test it with a physical Arduino.

I do appreciate your input which is very helpful.

Kind Regards,

Chris

Hi Chris,

That's different to the clocks I knew about. I guess the basic principal is the same though.

Looking forward to photos and more information.

Seems reasonable. One pulse has the current flowing in one direction, then the next pulse has the current flowing in the opposite direction. If the clock used a single electromagnetic coil, that would reverse the polarity of the magnetic field with each pulse. Another possibility would be diodes used in the clock to route the current to two separate coils.

You definitely would have a problem with simply checking for (pdt.Second() == 0), because that will be true for the entire second, during which loop run multiple times, switch the polarity each time.

Hi everyone,

I want to give an update about what I found out. The baudet clock still gives problems. And yes, it is correct that the simple checking for (pdt.Second() == 0) will cause a big problem leading to switching several times a second.

I also found out that the pulse time is not 2 seconds but 250 ms. I will give you here the updated code:

// Include necessary libraries
  #include <ThreeWire.h>
  #include <RtcDS1302.h>
  ThreeWire myWire(3, 4, 2); // DAT/IO, CLK/SCLK, RST/CE
  RtcDS1302<ThreeWire> Rtc(myWire);

// Initialising global variables.
  // Polarity switch clockline 1
  int Switch_R1 = 11;
  // Polarity switch clockline 2
  int Switch_R2 = 10;
  // Pulse switch clockline 2
  int Switch_R3 = 9;
  // Pulse switch clockline 1
  int Switch_R4 = 8;
  // Polarity tracking (1 = Negative / 2 = Positive)
  int Polarity = 1;
  
void setup() {
  // Initialise sketch
  // Set ports to "output" mode
  pinMode(Switch_R1, OUTPUT);
  pinMode(Switch_R2, OUTPUT);
  pinMode(Switch_R3, OUTPUT);
  pinMode(Switch_R4, OUTPUT);
  // Set relays 1 to 4 to low
  digitalWrite(Switch_R1, HIGH);
  digitalWrite(Switch_R2, HIGH);
  digitalWrite(Switch_R3, HIGH);
  digitalWrite(Switch_R4, HIGH);
  // Initialise RTC and communication
  Rtc.Begin();
  Serial.begin(9600); // Baudrate 9600
  // Set and write the manual <date> and <time> to the RTC
  RtcDateTime cdt = RtcDateTime("May 14 2021", "12:23:00");
  Rtc.SetDateTime(cdt);
}

void loop() {
  // Process loop
  // Get the time from the RTC
    RtcDateTime pdt = Rtc.GetDateTime();
  // When seconds = 1 sent the pulse
    if (pdt.Second() == 1)
      {
        // Sending the pulse to the clock
        Sent_Pulse();
    }
}

void Sent_Pulse() {
  /* 
   *  This function send the pulse to the clock.
  */      
      // Now, lets switch the polarity
      if (Polarity == 1)
      {
        Polarity = 2;
        // Clockline 1 is set to positive
        digitalWrite(Switch_R1, HIGH);
        // Clockline 2 is set to negative
        digitalWrite(Switch_R2, HIGH);
      }
      else
      {
        Polarity = 1;
        // Clockline 1 is set to negative
        digitalWrite(Switch_R1, LOW);
        // Clockline 2 is set to positive
        digitalWrite(Switch_R2, LOW);
      }
      // Now the polarity is set, give the 250 ms pulse
      digitalWrite(Switch_R3, LOW);
      digitalWrite(Switch_R4, LOW);
      delay(250);      
      // Stop the pulse
      digitalWrite(Switch_R3, HIGH);
      digitalWrite(Switch_R4, HIGH);
      // De-activate relays 1 and 2 to save energy
      digitalWrite(Switch_R1, HIGH);
      digitalWrite(Switch_R2, HIGH);
   // Delay for another 750 seconds,
   // to prevent Arduino from giving
   // several pulses in a second.
    delay(750);
}

For some reason "(pdt.Second() == 0)" gave problems and I changed it to "(pdt.Second() == 1)". It doesn't matter if the change takes place at 0 or 1 second as long. To solve the multi switching problem, after ending the pulse there is a "Delay(750)" instruction. This prevents the Arduino from switching more than once in a second.

When the clock is not connected, the Arduino behaves as expected. From the moment the clock is connected, it behaves erratically. I changed the Baudet clock with a 24V/25W lamp and the problems are gone. So we can conclude that the Baudet clock is the cause of the troubles.

I also inspect the wiring and they are all the same length. Also, those wires are located around the Arduino and the relay board. I have no idea why the Baudet clock influences the Arduino because everything is isolated from each other by opto-electronics.

However, I did the following test:
I switched on the Arduino without the lamp or clock connected. So it changed every 60 seconds without problems.
Then I manually switched the Baudet clock by changing the terminals myself every 10 seconds and kept repeating this.
After approximately 20 to 30 seconds, the switching of the Arduino became erratically again. Remember, there is no physical connection between Arduino and the clock.

So I assume that we can conclude that it is noise coming from the clock which disturbs the Arduino.

Therefore, I think that in this case, with this clock, using an Arduino is no option. Even when the distance between Arduino and the clock is more than 2 meters, it still disturbs.

Any ideas if this noise problem can be solved?

Thank you so much for your replies, which are appreciated.

Chris

Without reading the entire thread, do you have some suppression of the EMF from the solenoid each time it is pulsed and released?
If this was my project, I would add RF chokes in series with the wires going to the clock solenoid. Preferably chokes with a ferrite core and can handle the current going to the solenoid.

Hi Chris,
Thanks for the update. I'm away from home posting on a mobile phone, which is awkward. You have confirmed noise from the wiring is the problem, now how to solve it.

Loops of wire are perfect for transmitting and receiving noise, so what you need is to eliminate loops. That means running the wires to and from the clocks together so the current to and from the clocks is in adjacent wires.

Also read this; Flyback diodes and why you need them
The diode needs to be physically close to the switching device, not the clock. That should reduce the electrical noise from switching the clocks.

Hi all,

Thank you so much for replying.

In my latest test, there was no connection between the Arduino/relay board and the clock. Also, the power of the clock was separated from the Arduino. As long as I did not manually switch the clock (by just changing and touching the wires of the clock to the terminals of the power supply), everything worked find for hours and hours.

It is, when I (like described above), start to manually switch the clock after about 20 seconds the Arduino becomes erratically. Even when I should use solenoids, it would not make any difference because it is something transmitting from the clock, not travelling through the wires (which was also my first thought).

I cannot shield the clock but maybe I can shield the Arduino and its components from the noise.

Do you have any idea how I can shield the Arduino from that noise? Which housing do I have to use?

Thank you so much for your input.

Chris

In making my reply to you my phone is not connected to anything, I am holding it in one hand and typing with the other, no wires needed. Electromagnetic radiation is wonderful stuff...

I don't have any additional advice other than it's not shielding you need it's doing the things I suggested already to minimise the noise radiated by the clock circuit and the noise picked up by the control circuit.

True, I can place solenoids on both ends of the cable. But how do I shield the Arduino and circuitry from the magnetic noise of the clock which travels through the air? So I am gonna put as described solenoids on both ends of the cable.

I thought connecting the Arduino - RTC - Relay board - Step Down convertor was the challenge, however I was mistaken, the magnetic noise is a much bigger challenge.

Thank you so much for your reply.

Chris

I think you mean diodes (or I misunderstood you), put them only at the end where the switch is, not by the solenoid (clock driver magnet).

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.