{"id":333,"date":"2013-10-25T09:41:36","date_gmt":"2013-10-25T09:41:36","guid":{"rendered":"http:\/\/www.electronic-products-development.com\/?p=333"},"modified":"2022-02-17T10:13:11","modified_gmt":"2022-02-17T10:13:11","slug":"time-since-event-from-a-master-timer","status":"publish","type":"post","link":"https:\/\/ibex.tech\/c\/c\/timing\/time-since-event-from-a-master-timer","title":{"rendered":"Time Since Event From A Master Timer"},"content":{"rendered":"<h4>\nAn Example Using A Master Roll Over Timer To Get Time Since Last Event<br \/>\n<\/h4>\n<pre>\r\n<code>\r\n\/\/----- DO IN 1mS HEARTBEAT TIMER -----\r\nmain_1ms_clock_timer_irq++;\r\n\r\n\r\n\/\/----- USING THE TIMER -----\r\nunsigned long main_1ms_clock_timer_irq;\r\nunsigned long main_1ms_clock_timer;\r\nunsigned long process_last_time;\r\nunsigned long process_1ms_time_since_last;\r\n\r\n\r\n  \/\/Create a local copy of the timer (which won&#39;t change in the interrupt when being used - if no interrupt then no need to use)\r\n  main_1ms_clock_timer = main_1ms_clock_timer_irq;\r\n  while (main_1ms_clock_timer != main_1ms_clock_timer_irq)    \/\/Use sizeof(main_1ms_clock_timer) != the processor native bit length\r\n    main_1ms_clock_timer = main_1ms_clock_timer_irq;\r\n  \r\n\r\n  \/\/Start timing\r\n  process_last_time = main_1ms_clock_timer;\r\n\r\n\r\n  \/\/Time since start\r\n  process_1ms_time_since_last = (main_1ms_clock_timer - process_last_time);    \/\/Time in mS since last time point with roll over of the timer inherantly compensated for\r\n\r\n<\/code><\/pre>\n<p>\n&nbsp;\n<\/p>\n<p>\n&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>An Example Using A Master Roll Over Timer To Get Time Since Last Event \/\/&#8212;&#8211; DO IN 1mS HEARTBEAT TIMER &#8212;&#8211; main_1ms_clock_timer_irq++; \/\/&#8212;&#8211; USING THE TIMER &#8212;&#8211; unsigned long main_1ms_clock_timer_irq; unsigned long main_1ms_clock_timer; unsigned long process_last_time; unsigned long process_1ms_time_since_last; \/\/Create a local copy of the timer (which won&#39;t change in the interrupt when being used [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[32],"tags":[],"class_list":["post-333","post","type-post","status-publish","format-standard","hentry","category-timing"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/c\/wp-json\/wp\/v2\/posts\/333","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/c\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/c\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/c\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/c\/wp-json\/wp\/v2\/comments?post=333"}],"version-history":[{"count":2,"href":"https:\/\/ibex.tech\/c\/wp-json\/wp\/v2\/posts\/333\/revisions"}],"predecessor-version":[{"id":336,"href":"https:\/\/ibex.tech\/c\/wp-json\/wp\/v2\/posts\/333\/revisions\/336"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/c\/wp-json\/wp\/v2\/media?parent=333"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/c\/wp-json\/wp\/v2\/categories?post=333"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/c\/wp-json\/wp\/v2\/tags?post=333"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}