{"id":219,"date":"2020-07-17T14:03:58","date_gmt":"2020-07-17T21:03:58","guid":{"rendered":"https:\/\/boom-tracker.com\/tracker\/?p=219"},"modified":"2020-07-17T14:04:03","modified_gmt":"2020-07-17T21:04:03","slug":"timing-problems","status":"publish","type":"post","link":"https:\/\/boom-tracker.com\/tracker\/blog\/timing-problems\/","title":{"rendered":"Timing problems"},"content":{"rendered":"\n<p>I definitely still have timing problems.  I happened to catch a squeak from my office chair (<em>hurrah for squeaky chairs<\/em>) which spanned two captured buffers.  Here&#8217;s what I looks like:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/boom-tracker.com\/tracker\/wp-content\/uploads\/2020\/07\/overlap.png\" alt=\"Overlapping waveforms\" class=\"wp-image-218\" width=\"688\" height=\"516\" srcset=\"https:\/\/boom-tracker.com\/tracker\/wp-content\/uploads\/2020\/07\/overlap.png 640w, https:\/\/boom-tracker.com\/tracker\/wp-content\/uploads\/2020\/07\/overlap-300x225.png 300w, https:\/\/boom-tracker.com\/tracker\/wp-content\/uploads\/2020\/07\/overlap-250x188.png 250w, https:\/\/boom-tracker.com\/tracker\/wp-content\/uploads\/2020\/07\/overlap-550x413.png 550w, https:\/\/boom-tracker.com\/tracker\/wp-content\/uploads\/2020\/07\/overlap-240x180.png 240w, https:\/\/boom-tracker.com\/tracker\/wp-content\/uploads\/2020\/07\/overlap-400x300.png 400w\" sizes=\"auto, (max-width: 688px) 100vw, 688px\" \/><figcaption>Overlapping times<\/figcaption><\/figure>\n\n\n\n<p>As you can clearly see, there&#8217;s a definite backwards time jump.  With a little more gnuplot-fu, I managed to get a clearer picture that shows a ~6.5 ms backwards jump.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"640\" height=\"480\" src=\"https:\/\/boom-tracker.com\/tracker\/wp-content\/uploads\/2020\/07\/overlap_micros_closeup.png\" alt=\"\" class=\"wp-image-220\" srcset=\"https:\/\/boom-tracker.com\/tracker\/wp-content\/uploads\/2020\/07\/overlap_micros_closeup.png 640w, https:\/\/boom-tracker.com\/tracker\/wp-content\/uploads\/2020\/07\/overlap_micros_closeup-300x225.png 300w, https:\/\/boom-tracker.com\/tracker\/wp-content\/uploads\/2020\/07\/overlap_micros_closeup-250x188.png 250w, https:\/\/boom-tracker.com\/tracker\/wp-content\/uploads\/2020\/07\/overlap_micros_closeup-550x413.png 550w, https:\/\/boom-tracker.com\/tracker\/wp-content\/uploads\/2020\/07\/overlap_micros_closeup-240x180.png 240w, https:\/\/boom-tracker.com\/tracker\/wp-content\/uploads\/2020\/07\/overlap_micros_closeup-400x300.png 400w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><figcaption>it&#8217;s not supposed to do that<\/figcaption><\/figure>\n\n\n\n<p>There are several sources of error that I need to track down for this. <\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Assuming the timer interrupt is perfect<\/li><li>Assuming that time never jumps backward<\/li><li>Assuming that every reading takes exactly the same amount of time<\/li><\/ol>\n\n\n\n<p>My first poor assumption is that the timer interrupt fires exactly every 100 microseconds (as it would for a perfect 10kHz signal). However, if it were actually (say) every 110 microseconds (aproximately a 9kHz signal), then over 512 readings (the size of the buffer), it would have a cumulative error of 5120 microseconds, or ~5 milliseconds.  A negative 6.5 ms error would indicate am actual time of about 87 microseconds and a clock frequency of about 11.5 kHz.  I can correct for this on average by calculating the time it takes to read a whole buffer and dividing by the size of the buffer.  I&#8217;ll do that next.<\/p>\n\n\n\n<p>My second poor assumption is that my timer never jumps backwards, though as I&#8217;ve documented, it does, though I&#8217;ve only observed a few 10&#8217;s of microsecond jump.  That doesn&#8217;t mean it doesn&#8217;t jump more at other times however, and I need to find a way to model that.<\/p>\n\n\n\n<p>My third poor assumption is that every reading takes the <strong>same <\/strong>time, whether that&#8217;s 100 micros, 110 micros, or 90 micros.  This is the hardest to measure, because my clock just isn&#8217;t accurate enough to measure a 10 microsecond skew.  I suspect that I&#8217;m just going to have to punt on this one and assume the buffer wide average is good enough.  It&#8217;s probably good enough to account for the drift in clock frequency with temperature.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I definitely still have timing problems. I happened to catch a squeak from my office chair (hurrah for squeaky chairs) which spanned two captured buffers. Here&#8217;s what I looks like: As you can clearly see, there&#8217;s a definite backwards time jump. With a little more gnuplot-fu, I managed to get a clearer picture that shows&hellip; <a class=\"more-link\" href=\"https:\/\/boom-tracker.com\/tracker\/blog\/timing-problems\/\">Continue reading <span class=\"screen-reader-text\">Timing problems<\/span> <span class=\"meta-nav\" aria-hidden=\"true\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"bgseo_title":"","bgseo_description":"","bgseo_robots_index":"index","bgseo_robots_follow":"follow","footnotes":""},"categories":[3,9,8],"tags":[],"class_list":["post-219","post","type-post","status-publish","format-standard","hentry","category-blog","category-experimentation","category-implementation"],"_links":{"self":[{"href":"https:\/\/boom-tracker.com\/tracker\/wp-json\/wp\/v2\/posts\/219","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/boom-tracker.com\/tracker\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/boom-tracker.com\/tracker\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/boom-tracker.com\/tracker\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/boom-tracker.com\/tracker\/wp-json\/wp\/v2\/comments?post=219"}],"version-history":[{"count":1,"href":"https:\/\/boom-tracker.com\/tracker\/wp-json\/wp\/v2\/posts\/219\/revisions"}],"predecessor-version":[{"id":221,"href":"https:\/\/boom-tracker.com\/tracker\/wp-json\/wp\/v2\/posts\/219\/revisions\/221"}],"wp:attachment":[{"href":"https:\/\/boom-tracker.com\/tracker\/wp-json\/wp\/v2\/media?parent=219"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/boom-tracker.com\/tracker\/wp-json\/wp\/v2\/categories?post=219"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/boom-tracker.com\/tracker\/wp-json\/wp\/v2\/tags?post=219"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}