Syncronization of two or more separate atmega32

Go To Last Post
20 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I want to design and implement 4 clock system for a swimming pool. I already made a single clock using atmega32's 16 bit timer and 7-segment for display, but my concern is when the 4 for clocks start counting there might be a slight difference in timing so that after say 10 hours of operation a time delay between each clock would occur as the frequency of each microcontroller might be slightly different from the other.
My idea was to create a master clock with the controller in it and just control the other three by the same controller by connecting all four clocks through cat6 network cables.
Is this a good idea? And if not what else can I do to sync the clocks together?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I think we need more information. What are the clocks used for? What else does the processor do apart from show time? How far apart are the clocks? Does it matter if all the clocks are wrong if they tell the same time? How do you set the time on a clock? Are you going to go round and set each clock individually or does one act as master and the others are slaves?

 

If I were doing this I would consider using a GPS receiver on each clock. May be cheaper than wiring between clocks. If you hook up a switch for daylight savings, or program in when it happens, you would never need to set the clocks, they would be right. Depends on if you can get a GPS signal at the right place.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Seif_1999 wrote:
I want to design and implement 4 clock system for a swimming pool.

Is this a timing system for 4 lanes for competitive swimming events?

 

Jim

 

 

(Possum Lodge oath) Quando omni flunkus, moritati.

"I thought growing old would take longer"

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm guessing lap timers: you can look at any one of four clocks to know when to start.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The clocks just counts seconds an minutes till 99:59 ana then repeats and the processor do nothing more.
The clocks are at the 4 corners of a 25×20m pool.
I just need them to tell the same time and if is there something wrong I think I would be able to fine tune it but my problem is for them to be the same.
One clock will act as master and others are slaves (if I start the master the rest should start at the same time).
Unfortunately a gps receiver is not commercially available in my country and if I could get from abroad I think it will be much expensive than wiring.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ki0bk wrote:

Seif_1999 wrote:
I want to design and implement 4 clock system for a swimming pool.

No not competitive (not a stop watch) it is just for practice.

Is this a timing system for 4 lanes for competitive swimming events?

 

Jim

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 by connecting all four clocks 

Why do the micros even need to keep separate time? If they are communicating then why doesn't the master alone keep "the time" then broadcast the same thing for display to the other three? That way the others can never get out of sync as they are not trying to maintain time?

 

Or did you really mean "one clock, four display units" ?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

That's what I am asking about how can do this? How to connect them with each other.
Maybe "one clock, four display units" is what I am trying to do you are right, but how can I do this either?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You may want to look into this as a way to sync your clocks to each other:

https://en.wikipedia.org/wiki/Be...

 

I remember back in grade school the mechanical wall clocks were all sync'd to the master clock in the principles office.

Not sure how that was done, but it was before micro's were available, but perhaps the principle can be used to keep all your clocks in sync.

 

Jim

 

 

(Possum Lodge oath) Quando omni flunkus, moritati.

"I thought growing old would take longer"

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Sounds to me you want one clock and 4 displays.

If you don't know my whole story, keep your mouth shut.

If you know my whole story, you're an accomplice. Keep your mouth shut. 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes, how can I do it?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Sounds to me you want one clock and 4 displays.

Apparently that IS what he's asking about. His use of "four clocks" in #1 was just misleading. He really means four display units. 

 

In which case you might as well just wire the master SPI to all four slaves and just keep pumping out the time string with some kind of packet header every hundred milliseconds or something? In fact you only need MOSI and SCK, forget MISO. No need for slave selects either but if you do (in case of rogue pulses or something) then one SS to them all should do.

Last Edited: Tue. May 21, 2019 - 04:21 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
In which case you might as well just wire the master SPI to all four slaves and just keep pumping out the time string with some kind of packet header every hundred milliseconds or something? In fact you only need MOSI and SCK, forget MISO. No need for slave selects either but if you do (in case of rogue pulses or something) then one SS to them all should do.

 

The clocks are at the 4 corners of a 25×20m pool

That's some looong SPI wires ... Maybe use RS-485 ??

 

/Bingo

Last Edited: Tue. May 21, 2019 - 05:04 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'd consider using NRF24L0+ radios for the sync'  , and make the corner displays intelligent (mcu + radio + display)

Even the clones are usable.

 

/Bingo

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Seif,

 

Indoor or outdoor pool?

 

If outdoor, then as mentioned above a GPS receiver at each site is definitely the way to go.

 

My second choice would be an RF link, either as Bingo mentioned, or WiFi (ESP8266, for example), or perhaps XBee or Bluetooth.

 

My last choice would be hard wiring 20x25 meters, corner connectivity, by wire, around a pool.

 

If, for some reason you decide you have to use wiring, then don't forget your nearby lightning strike voltage protection circuitry on your boards.

 

JC

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Since transfer speed is not crucial here (unit time is likely 1 sec), I just use coaxial audio stereo cables (not expensive) and TWI (Two Wire Interface). For an 8 MHz crystal, the TWI frequency could be made as low as 163 250 Hz (TWBR=255 & TWPS=3).

 

Assuming 4 bytes to be transferred every second (likely by using a general call by the master to all 3 slaves), about 50 TWI clocks will complete it. The transfer time would be 50/163=307 50/250=200 msec.

Even using inexpensive audio cables, the attenuation at 163 250 Hz along 45 m. is relatively low (this could be checked by measuring the DC resistance of the cable). I suggest adding a 1K pull-up to every TWI pin (SCK and SDA) of the master and the 3 slaves.

 

One may experiment using a higher frequency in case more bytes will need to be transferred within 1 sec.

 

Kerim

 

Last Edited: Tue. May 21, 2019 - 06:18 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

And if one were to go that route, (hardwired with a low speed clock), then perhaps an additional I/O pin is used to monitor the data transmission line ( s ).

 

When the first transition takes place the clock updates the time variable, (and / display, depending upon how frequently one sends a data packet).

 

The data packet itself then holds the correct time info, and a checksum.

 

The micro then verifies that its time and the correct time as per the packet match, or it corrects its own time variables.

 

What this means is that the slave boards will update their time variables within uSec's of the Start of the (very low speed and hence slow) Data Packet.

The length of the data packet, and the time to send it, are then irrelevant.

 

To be clear, you use a very slow data rate to limit the bandwidth required to get your signal down the relatively long wires with inexpensive wire, (lots of capacitance / meter), and cheap drivers.

 

That said, hardwired would still be my third choice.

 

JC

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If, for some reason you decide you have to use wiring, then don't forget your nearby lightning strike voltage protection circuitry on your boards 

Make sure your unit(s) is battery powered to avoid all kinds of shock hazard troubles, especially if you are running wires around a pool. Even the unit itself would need all kinds of isolation (or possibly use a "pool rated" power supply.

 

There are all kinds of super-cheapo 1-way transmitters that can send the info to your displays.  

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If you can't get GPS units then how about 433MHz transmitter/receivers. There's articles online how to use them - here's one

For simplicity, have 5 modules - one to keep time and transmit, four receivers that display what they receive. If all 4 receivers are the same, they will update at the same time.

If you can only use wires, reliability gets better as transmit rate goes down. Taking this idea to extreme, you only need one pulse per second. You can encode the time by the length of pulse -

On rising pulse, display time and update seconds counter by 1
If length of pulse less than 200mS, set received count to zero, shift to zero
If length of pulse 300 - 600mS, next bit is zero, shift receive counter
If length of pulse greater than 600mS, next bit is one, shift receive counter
If shift = 13 copy receive counter to seconds counter

When the system starts, the clocks will all display the wrong time. But after a few seconds the shift count gets to 13 and they all will set to the time. 13 bits counts up to 8191, 100 minutes is 6000 seconds so only 13 bits needed. That assumes the count is in seconds but could easily be binary coded decimal, 4 bits per character, in which case 16 bits are required.

For noise immunity, sample the input every few mS, say every 2mS for 25 samples. If the majority are high return a high, if the majority are low return low.

Just throwing out some ideas ...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Bingo600 wrote:

I'd consider using NRF24L0+ radios for the sync'  , and make the corner displays intelligent (mcu + radio + display)

Even the clones are usable.

 

/Bingo

 

That's what I would do. Forget even short wires these days as counterfeit NRF24L01 boards are like a dollar and work beautifully. Just be sure your stupid PC layout has 1mm holes, not .7mm holes for the stupid modules. <grr> (I'll change the pin headers to wires.)

 

If you don't know my whole story, keep your mouth shut.

If you know my whole story, you're an accomplice. Keep your mouth shut. 

Last Edited: Wed. May 22, 2019 - 03:06 PM