Question about simulating clock modules in Omnet++












0















Scenario:



Node 1 (Sender) has a local clock (40.000 MHz) and sends this clock signal as a continuous bit stream (01010101...) on a serial (i.e. fiberoptic) link to Node 2 (Receiver).



Node 2 has its own (local or global, e.g. 41.000 MHz) clock and must determine the phase and frequency of the local clock of Node 1 with respect to its own clock using the (clock) data it is receiving from Node 1.



Alternatively, I can think of Node 1 sending individual messages, but at a well-defined frequency of 40.000 MHz, to Node 2. Again, Node 2 (which has its own local or global 41.000 MHz clock) must determine the phase and frequency of Node 1's local clock with respect to its own clock using the arrival timing of the messages it is receiving from Node 1



Question: How would I implement either of these scenarios in OMNet++?










share|improve this question



























    0















    Scenario:



    Node 1 (Sender) has a local clock (40.000 MHz) and sends this clock signal as a continuous bit stream (01010101...) on a serial (i.e. fiberoptic) link to Node 2 (Receiver).



    Node 2 has its own (local or global, e.g. 41.000 MHz) clock and must determine the phase and frequency of the local clock of Node 1 with respect to its own clock using the (clock) data it is receiving from Node 1.



    Alternatively, I can think of Node 1 sending individual messages, but at a well-defined frequency of 40.000 MHz, to Node 2. Again, Node 2 (which has its own local or global 41.000 MHz clock) must determine the phase and frequency of Node 1's local clock with respect to its own clock using the arrival timing of the messages it is receiving from Node 1



    Question: How would I implement either of these scenarios in OMNet++?










    share|improve this question

























      0












      0








      0








      Scenario:



      Node 1 (Sender) has a local clock (40.000 MHz) and sends this clock signal as a continuous bit stream (01010101...) on a serial (i.e. fiberoptic) link to Node 2 (Receiver).



      Node 2 has its own (local or global, e.g. 41.000 MHz) clock and must determine the phase and frequency of the local clock of Node 1 with respect to its own clock using the (clock) data it is receiving from Node 1.



      Alternatively, I can think of Node 1 sending individual messages, but at a well-defined frequency of 40.000 MHz, to Node 2. Again, Node 2 (which has its own local or global 41.000 MHz clock) must determine the phase and frequency of Node 1's local clock with respect to its own clock using the arrival timing of the messages it is receiving from Node 1



      Question: How would I implement either of these scenarios in OMNet++?










      share|improve this question














      Scenario:



      Node 1 (Sender) has a local clock (40.000 MHz) and sends this clock signal as a continuous bit stream (01010101...) on a serial (i.e. fiberoptic) link to Node 2 (Receiver).



      Node 2 has its own (local or global, e.g. 41.000 MHz) clock and must determine the phase and frequency of the local clock of Node 1 with respect to its own clock using the (clock) data it is receiving from Node 1.



      Alternatively, I can think of Node 1 sending individual messages, but at a well-defined frequency of 40.000 MHz, to Node 2. Again, Node 2 (which has its own local or global 41.000 MHz clock) must determine the phase and frequency of Node 1's local clock with respect to its own clock using the arrival timing of the messages it is receiving from Node 1



      Question: How would I implement either of these scenarios in OMNet++?







      c++ simulation omnet++






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 19 '18 at 16:18









      MinsooMinsoo

      1




      1
























          1 Answer
          1






          active

          oldest

          votes


















          0














          I don't know OMNet++ but if you have the ticks of both clocks, would



          the_other_clocks_freq = the_other_clocks_ticks*your_own_freq/your_own_ticks


          work to get the frequency? Example:



          #include <iostream>

          class Clock {
          uint64_t m_freq;
          uint64_t m_ticks;
          public:
          Clock(uint64_t Base) : m_freq(Base), m_ticks(0) {}
          void tick() { ++m_ticks; }
          operator double () const { return static_cast<double>(m_ticks)/static_cast<double>(m_freq); }
          uint64_t getTicks() const { return m_ticks; }
          uint64_t getOtherClockFreq(uint64_t other_ticks) {
          return (other_ticks*m_freq)/m_ticks;
          }

          };
          int main() {
          Clock Node1(40000000);
          Clock Node2(41000000);

          // simulate 0.00075s
          for(int i=0; i<40000*75/100; ++i) Node1.tick();
          for(int i=0; i<41000*75/100; ++i) Node2.tick();

          std::cout << Node1 << "sn"; // 0.00075s
          std::cout << Node2 << "sn"; // 0.00075s

          // calculate the base freq of the other clock
          std::cout << Node1.getOtherClockFreq(Node2.getTicks()) << " Node2 basen";
          std::cout << Node2.getOtherClockFreq(Node1.getTicks()) << " Node1 basen";
          }


          Output



          0.00075s
          0.00075s
          41000000 Node2 base
          40000000 Node1 base


          At these speeds you may need something larger than uint64_t to store the ticks though ... and I don't know what phase is in this case.






          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53378750%2fquestion-about-simulating-clock-modules-in-omnet%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            I don't know OMNet++ but if you have the ticks of both clocks, would



            the_other_clocks_freq = the_other_clocks_ticks*your_own_freq/your_own_ticks


            work to get the frequency? Example:



            #include <iostream>

            class Clock {
            uint64_t m_freq;
            uint64_t m_ticks;
            public:
            Clock(uint64_t Base) : m_freq(Base), m_ticks(0) {}
            void tick() { ++m_ticks; }
            operator double () const { return static_cast<double>(m_ticks)/static_cast<double>(m_freq); }
            uint64_t getTicks() const { return m_ticks; }
            uint64_t getOtherClockFreq(uint64_t other_ticks) {
            return (other_ticks*m_freq)/m_ticks;
            }

            };
            int main() {
            Clock Node1(40000000);
            Clock Node2(41000000);

            // simulate 0.00075s
            for(int i=0; i<40000*75/100; ++i) Node1.tick();
            for(int i=0; i<41000*75/100; ++i) Node2.tick();

            std::cout << Node1 << "sn"; // 0.00075s
            std::cout << Node2 << "sn"; // 0.00075s

            // calculate the base freq of the other clock
            std::cout << Node1.getOtherClockFreq(Node2.getTicks()) << " Node2 basen";
            std::cout << Node2.getOtherClockFreq(Node1.getTicks()) << " Node1 basen";
            }


            Output



            0.00075s
            0.00075s
            41000000 Node2 base
            40000000 Node1 base


            At these speeds you may need something larger than uint64_t to store the ticks though ... and I don't know what phase is in this case.






            share|improve this answer




























              0














              I don't know OMNet++ but if you have the ticks of both clocks, would



              the_other_clocks_freq = the_other_clocks_ticks*your_own_freq/your_own_ticks


              work to get the frequency? Example:



              #include <iostream>

              class Clock {
              uint64_t m_freq;
              uint64_t m_ticks;
              public:
              Clock(uint64_t Base) : m_freq(Base), m_ticks(0) {}
              void tick() { ++m_ticks; }
              operator double () const { return static_cast<double>(m_ticks)/static_cast<double>(m_freq); }
              uint64_t getTicks() const { return m_ticks; }
              uint64_t getOtherClockFreq(uint64_t other_ticks) {
              return (other_ticks*m_freq)/m_ticks;
              }

              };
              int main() {
              Clock Node1(40000000);
              Clock Node2(41000000);

              // simulate 0.00075s
              for(int i=0; i<40000*75/100; ++i) Node1.tick();
              for(int i=0; i<41000*75/100; ++i) Node2.tick();

              std::cout << Node1 << "sn"; // 0.00075s
              std::cout << Node2 << "sn"; // 0.00075s

              // calculate the base freq of the other clock
              std::cout << Node1.getOtherClockFreq(Node2.getTicks()) << " Node2 basen";
              std::cout << Node2.getOtherClockFreq(Node1.getTicks()) << " Node1 basen";
              }


              Output



              0.00075s
              0.00075s
              41000000 Node2 base
              40000000 Node1 base


              At these speeds you may need something larger than uint64_t to store the ticks though ... and I don't know what phase is in this case.






              share|improve this answer


























                0












                0








                0







                I don't know OMNet++ but if you have the ticks of both clocks, would



                the_other_clocks_freq = the_other_clocks_ticks*your_own_freq/your_own_ticks


                work to get the frequency? Example:



                #include <iostream>

                class Clock {
                uint64_t m_freq;
                uint64_t m_ticks;
                public:
                Clock(uint64_t Base) : m_freq(Base), m_ticks(0) {}
                void tick() { ++m_ticks; }
                operator double () const { return static_cast<double>(m_ticks)/static_cast<double>(m_freq); }
                uint64_t getTicks() const { return m_ticks; }
                uint64_t getOtherClockFreq(uint64_t other_ticks) {
                return (other_ticks*m_freq)/m_ticks;
                }

                };
                int main() {
                Clock Node1(40000000);
                Clock Node2(41000000);

                // simulate 0.00075s
                for(int i=0; i<40000*75/100; ++i) Node1.tick();
                for(int i=0; i<41000*75/100; ++i) Node2.tick();

                std::cout << Node1 << "sn"; // 0.00075s
                std::cout << Node2 << "sn"; // 0.00075s

                // calculate the base freq of the other clock
                std::cout << Node1.getOtherClockFreq(Node2.getTicks()) << " Node2 basen";
                std::cout << Node2.getOtherClockFreq(Node1.getTicks()) << " Node1 basen";
                }


                Output



                0.00075s
                0.00075s
                41000000 Node2 base
                40000000 Node1 base


                At these speeds you may need something larger than uint64_t to store the ticks though ... and I don't know what phase is in this case.






                share|improve this answer













                I don't know OMNet++ but if you have the ticks of both clocks, would



                the_other_clocks_freq = the_other_clocks_ticks*your_own_freq/your_own_ticks


                work to get the frequency? Example:



                #include <iostream>

                class Clock {
                uint64_t m_freq;
                uint64_t m_ticks;
                public:
                Clock(uint64_t Base) : m_freq(Base), m_ticks(0) {}
                void tick() { ++m_ticks; }
                operator double () const { return static_cast<double>(m_ticks)/static_cast<double>(m_freq); }
                uint64_t getTicks() const { return m_ticks; }
                uint64_t getOtherClockFreq(uint64_t other_ticks) {
                return (other_ticks*m_freq)/m_ticks;
                }

                };
                int main() {
                Clock Node1(40000000);
                Clock Node2(41000000);

                // simulate 0.00075s
                for(int i=0; i<40000*75/100; ++i) Node1.tick();
                for(int i=0; i<41000*75/100; ++i) Node2.tick();

                std::cout << Node1 << "sn"; // 0.00075s
                std::cout << Node2 << "sn"; // 0.00075s

                // calculate the base freq of the other clock
                std::cout << Node1.getOtherClockFreq(Node2.getTicks()) << " Node2 basen";
                std::cout << Node2.getOtherClockFreq(Node1.getTicks()) << " Node1 basen";
                }


                Output



                0.00075s
                0.00075s
                41000000 Node2 base
                40000000 Node1 base


                At these speeds you may need something larger than uint64_t to store the ticks though ... and I don't know what phase is in this case.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 19 '18 at 17:05









                Ted LyngmoTed Lyngmo

                2,2561317




                2,2561317






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53378750%2fquestion-about-simulating-clock-modules-in-omnet%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    How to change which sound is reproduced for terminal bell?

                    Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

                    Can I use Tabulator js library in my java Spring + Thymeleaf project?