0
\$\begingroup\$

This is my first post here, first off let me know how I go.

I am going to be taking on a new project soon, to design a protocol for communication between two microcontrollers (I understand there is stuff out there but I would like to learn how low level stuff works). At the moment, I am doing some research of encodings and came across Manchester encoding, I understand how the data is sent.

But my current question is how would you get the clocks in sync, there would be a preamble in front of every message, which would give the receiver some time to detect the clock, but how would I calculate the amount of time between each read. For clarification, there would be no set transfer rate. Maybe I would have to sample the preamble every so often and see if there is a change, but maybe that could fail, if I read in the centre of a high or low.

If it is possible, I would like a detailed explanation on how I could do this, no something vague, but any information would help.

Thank you in advance.

If my question is too vague, please let me know.

EDIT: A solution through software, not hardware

\$\endgroup\$
8
  • 1
    \$\begingroup\$ A very warm welcome to the site. It's a Q&A site and not a personal tutorial service or an on-line technical encyclopaedia, copied out to you on demand. You can very easily research this and find this information on the internet. There already exists a great amount of information and software examples on this subject - plenty as I found on my first attempt. \$\endgroup\$
    – TonyM
    Commented Nov 22, 2020 at 10:59
  • \$\begingroup\$ You either need hardware or a very fast over-clocking measurement like a UART (16x clock rate of data). \$\endgroup\$
    – Andy aka
    Commented Nov 22, 2020 at 11:00
  • \$\begingroup\$ I have been researching for the last few hours, and still have found much about getting clocks in sync. If you can recommend any resources that would be greatly appreciated. @TonyM \$\endgroup\$
    – Jpac14
    Commented Nov 22, 2020 at 11:01
  • \$\begingroup\$ I am designing it to be fast at the moment but do you think a circuit do decode it would be better. @Andyaka \$\endgroup\$
    – Jpac14
    Commented Nov 22, 2020 at 11:03
  • 1
    \$\begingroup\$ No, you continually use the data edges to decode the data. Don't measure then assume no drift out for the rest of the message. \$\endgroup\$
    – Andy aka
    Commented Nov 22, 2020 at 11:11

1 Answer 1

1
\$\begingroup\$

if you wanted to create an answer, I would be happy to mark it as correct.

If you want a software solution then you can ascertain what the embedded clock rate is by 16x oversampling the data and looking for clock edges. This is precisely what a UART does because it has to find the optimum position to sample the data to get best reliability.

For Manchester encoding (see picture below), the clock is embedded into the data stream hence there are edges that define the clock every data symbol but, you would still need to detect those edges so you can remain in sync and decode the data correctly. You could of course use a hardware interrupt scheme but that is, strictly speaking a hardware/software solution.

enter image description here

You should also continue to perform clock recovery throughout the whole packet of data in case of small drifts but it's less of a problem with Manchester decoding compared to UART asynchronous data or scrambled synchronous data. But, the bottom line is; use a continual method to detect clock edges and not some initial calculation based on the preamble and hope that you stay in sync for the payload data. I mean, you might get away with that but, it's not ideal.

\$\endgroup\$
2
  • 2
    \$\begingroup\$ It is amusing to read "if you wanted to create an answer, I would be happy to mark it as correct" at the start of your answer. Please note that the asker can only accept an answer, and that does not mean that the accepted answer is correct. \$\endgroup\$ Commented Nov 22, 2020 at 12:55
  • \$\begingroup\$ @ShashankVM yeah I could add all sorts of gobbledygook into it LOL \$\endgroup\$
    – Andy aka
    Commented Nov 22, 2020 at 13:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.