{"id":2620,"date":"2019-11-12T17:42:08","date_gmt":"2019-11-12T16:42:08","guid":{"rendered":"https:\/\/ridgesolutions.ie\/?p=2620"},"modified":"2019-11-12T18:30:15","modified_gmt":"2019-11-12T17:30:15","slug":"use-pic-timer2-not-timer0-accurate-timing-embedded","status":"publish","type":"post","link":"https:\/\/www.ridgesolutions.ie\/index.php\/2019\/11\/12\/use-pic-timer2-not-timer0-accurate-timing-embedded\/","title":{"rendered":"Use PIC Timer2 not Timer0 for accurate Interval Timing on an Embedded system"},"content":{"rendered":"<p>Recently I was struggling to achieve very accurately synchronised camera and light triggers for a real-time computer vision project that I was working on, my original PIC embedded system for triggering everything using a PIC micro-controller had a fairly reliable accuracy of about 250us which was sufficient for a few years, but for various reasons this needed to be reduced by a factor of 10 to about 25us.  The problem was that as I reduced the timer&#8217;s overflow period it started to become quite inaccurate and erratic.<\/p>\n<p>It is possible to achieve quite accurate timing on your embedded software system using a PIC, however it can take a bit of work to tune things.  Most articles that introduce the use of timers on the PIC use the Timer0 module as an example, maybe because it has a &#8216;0&#8217; in it?<\/p>\n<p>Now, when using Timer0 to produce a repeated time interval, its High &#038; Low overflow registers must be manually reset in the interrupt handler to setup the next time period, all while the timer is still counting away.<\/p>\n<p>This it makes it difficult to know what values to put into the registers to get an accurate overflow period &#8211; you end up trying to account for the interrupt latency and counting assembly instructions in the interrupt handler to estimate times etc.<\/p>\n<p>The upshot is that it&#8217;s hard to get a reliable overflow period with a desired accuracy when using Timer0.<\/p>\n<p>Example, initial Timer0 setup code:<\/p>\n<pre>\r\nvoid init_timers() {\r\n\r\n    \/\/ See http:\/\/www.enmcu.com\/software\/timer0calculatorandcodegeneration\r\n    \/\/ for values.\r\n\r\n    INTCON.GIE=1;         \/\/ global interrupt enable\r\n    INTCON.PEIE=1;        \/\/ peripheral interrupt enable\r\n    INTCON.TMR0IF = 0x0;  \/\/ Clear timer0 overflow interrupt flag\r\n    INTCON.TMR0IE = 1;    \/\/ enable the timer0 by setting TRM0IE flag\r\n\r\n    T0CON.T08BIT = 0;     \/\/ 16 Bit timer\r\n    T0CON.T0CS = 0;       \/\/ Internal clock\r\n    T0CON.PSA = 1;        \/\/ Set scaler to 1:4\r\n\r\n    \/\/ Set timer counts\r\n    TMR0H = TIMER_HIGH;\r\n    TMR0L = TIMER_LOW;\r\n\r\n    T0CON.TMR0ON = 1;     \/\/ Turn Timer0 on.\r\n}\r\n\r\n\/\/ interrupt handler for the timer overflow\r\nvoid interrupt(void) {\r\n\r\n    \/\/ Is this a Timer 0 interrupt?\r\n    if (INTCON.TMR0IF) {\r\n        \/\/ yes!\r\n \r\n        \/\/ Reset the timer values\r\n        \/\/ These are actually now incorrect\r\n        \/\/ as time has elapsed since the timer\r\n        \/\/ overflow and now!\r\n        TMR0H = TIMER_HIGH;\r\n        TMR0L = TIMER_LOW;\r\n        \r\n        \/\/ Reset interrupt flag\r\n        INTCON.TMR0IF = 0;\r\n\r\n        \/\/ Increase some counter\r\n        ++counter;\r\n    }\r\n}\r\n<\/pre>\n<p>The best thing to do is to ditch Timer0 and switch to Timer2 instead.  Timer2 automatically handles this kind of pattern (and it&#8217;s not much harder to use even though it&#8217;s got a &#8216;2&#8217; in its name!).<\/p>\n<p>When using Timer2 you don&#8217;t need to reload the overflow registers and so it is much easier to get an accurate and reliable overflow period!  Have a look here if you need <a href=\"http:\/\/eng-serve.com\/pic\/pic_timer.html\">help<\/a> in figuring how to setup Timer2 for your desired timing parameters &#8211; it&#8217;s very handy!<\/p>\n<pre>\r\n\r\nvoid init_timers() {\r\n  \r\n    \/\/ Have a look at the URL below for setting up Timer2\r\n    \/\/ http:\/\/eng-serve.com\/pic\/pic_timer.html\r\n    \/\/\r\n    \/\/ Setup Timer2 for 40KHz, period = 25us\r\n    \r\n    \/\/ Timer2 Registers\r\n    \/\/ Prescaler = 1 - TMR2\r\n    \/\/ PostScaler = 1 - PR2 = 200 \r\n    \/\/ Freq = 40000.00 Hz \r\n    \/\/ Period = 0.000025 seconds\r\n    T2CON |= 0;         \/\/ bits 6-3 Post scaler 1:1 thru 1:16\r\n    T2CON.TMR2ON = 1;   \/\/ bit 2 turn timer2 on;\r\n    T2CON.T2CKPS1 = 0;  \/\/ bits 1-0  Prescaler Rate Select bits\r\n    T2CON.T2CKPS0 = 0;\r\n    PR2 = 200 - 1;      \/\/ PR2 (Timer2 Match value), 200 - 1 (1 = magic value, KG)\r\n\r\n    \/\/ Interrupt Registers\r\n    INTCON = 0;           \/\/ clear the interrupt control register\r\n    INTCON.TMR0IE = 0;    \/\/ bit5 TMR0 Overflow Interrupt Enable bit...0 = Disables the TMR0 interrupt\r\n    PIR1.TMR2IF = 0;      \/\/ clear timer1 interrupt flag TMR1IF\r\n    PIE1.TMR2IE = 1;      \/\/ enable Timer2 interrupts\r\n    INTCON.TMR0IF = 0;    \/\/ bit2 clear timer 0 interrupt flag\r\n    INTCON.GIE = 1;       \/\/ bit7 global interrupt enable\r\n    INTCON.PEIE = 1;      \/\/ bit6 Peripheral Interrupt Enable bit...1 = Enables all unmasked peripheral interrupts\r\n}\r\n\r\nvoid interrupt(void) {\r\n\r\n    \/\/ Is this a timer 2 interrupt?\r\n    if (PIR1.TMR2IF == 1) {\r\n        \/\/ Yes, all we have to do is clear the\r\n        \/\/ flag, we don't need to reload any registers!\r\n        \/\/ Clear interrupt flag\r\n        PIR1.TMR2IF = 0;        \r\n        ++counter;\r\n    }\r\n}\r\n\r\n<\/pre>\n<p>Once Timer2 is initialised in this manner, it will cycle automatically without the need to reload any values yielding a stable (and hopefully more accurate) time period.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Recently I was struggling to achieve very accurately synchronised camera and light triggers for a real-time computer vision project that I was working on, my original PIC embedded system for triggering everything using a PIC micro-controller had a fairly reliable accuracy of about 250us which was sufficient for a few years, but for various reasons [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-2620","post","type-post","status-publish","format-standard","hentry","category-tech-stuff"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.0.1 - aioseo.com -->\n\t<meta name=\"description\" content=\"Recently I was struggling to achieve very accurately synchronised camera and light triggers for a real-time computer vision project that I was working on, my original PIC embedded system for triggering everything using a PIC micro-controller had a fairly reliable accuracy of about 250us which was sufficient for a few years, but for various reasons\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Kevin Godden\"\/>\n\t<meta name=\"google-site-verification\" content=\"Kyj52YLp6GOPA44PVBffo9fjW8rgWHYYRF0ZYjfy6ss\" \/>\n\t<link rel=\"canonical\" href=\"https:\/\/www.ridgesolutions.ie\/index.php\/2019\/11\/12\/use-pic-timer2-not-timer0-accurate-timing-embedded\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.0.1\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"Systems and Embedded Software Engineering, Ireland. | Some thoughts of a busy Computer Engineer\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"Use PIC Timer2 not Timer0 for accurate Interval Timing on an Embedded system\" \/>\n\t\t<meta property=\"og:description\" content=\"Recently I was struggling to achieve very accurately synchronised camera and light triggers for a real-time computer vision project that I was working on, my original PIC embedded system for triggering everything using a PIC micro-controller had a fairly reliable accuracy of about 250us which was sufficient for a few years, but for various reasons\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/www.ridgesolutions.ie\/index.php\/2019\/11\/12\/use-pic-timer2-not-timer0-accurate-timing-embedded\/\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2019-11-12T16:42:08+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2019-11-12T17:30:15+00:00\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:title\" content=\"Use PIC Timer2 not Timer0 for accurate Interval Timing on an Embedded system\" \/>\n\t\t<meta name=\"twitter:description\" content=\"Recently I was struggling to achieve very accurately synchronised camera and light triggers for a real-time computer vision project that I was working on, my original PIC embedded system for triggering everything using a PIC micro-controller had a fairly reliable accuracy of about 250us which was sufficient for a few years, but for various reasons\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/index.php\\\/2019\\\/11\\\/12\\\/use-pic-timer2-not-timer0-accurate-timing-embedded\\\/#article\",\"name\":\"Use PIC Timer2 not Timer0 for accurate Interval Timing on an Embedded system\",\"headline\":\"Use PIC Timer2 not Timer0 for accurate Interval Timing on an Embedded system\",\"author\":{\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/index.php\\\/author\\\/kgodden\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/#organization\"},\"image\":{\"@type\":\"ImageObject\",\"url\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/wp-content\\\/uploads\\\/2013\\\/09\\\/ridge_logo1.jpg\",\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/#articleImage\",\"width\":400,\"height\":81},\"datePublished\":\"2019-11-12T17:42:08+00:00\",\"dateModified\":\"2019-11-12T18:30:15+00:00\",\"inLanguage\":\"en-US\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/index.php\\\/2019\\\/11\\\/12\\\/use-pic-timer2-not-timer0-accurate-timing-embedded\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/index.php\\\/2019\\\/11\\\/12\\\/use-pic-timer2-not-timer0-accurate-timing-embedded\\\/#webpage\"},\"articleSection\":\"Tech Stuff\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/index.php\\\/2019\\\/11\\\/12\\\/use-pic-timer2-not-timer0-accurate-timing-embedded\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.ridgesolutions.ie\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/index.php\\\/category\\\/tech-stuff\\\/#listItem\",\"name\":\"Tech Stuff\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/index.php\\\/category\\\/tech-stuff\\\/#listItem\",\"position\":2,\"name\":\"Tech Stuff\",\"item\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/index.php\\\/category\\\/tech-stuff\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/index.php\\\/2019\\\/11\\\/12\\\/use-pic-timer2-not-timer0-accurate-timing-embedded\\\/#listItem\",\"name\":\"Use PIC Timer2 not Timer0 for accurate Interval Timing on an Embedded system\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/index.php\\\/2019\\\/11\\\/12\\\/use-pic-timer2-not-timer0-accurate-timing-embedded\\\/#listItem\",\"position\":3,\"name\":\"Use PIC Timer2 not Timer0 for accurate Interval Timing on an Embedded system\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/index.php\\\/category\\\/tech-stuff\\\/#listItem\",\"name\":\"Tech Stuff\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/#organization\",\"name\":\"Ridge Solutions, Software Development and Software Engineering, Ireland.\",\"description\":\"Some thoughts of a busy Computer Engineer\",\"url\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"url\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/wp-content\\\/uploads\\\/2013\\\/09\\\/ridge_logo1.jpg\",\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/index.php\\\/2019\\\/11\\\/12\\\/use-pic-timer2-not-timer0-accurate-timing-embedded\\\/#organizationLogo\",\"width\":400,\"height\":81},\"image\":{\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/index.php\\\/2019\\\/11\\\/12\\\/use-pic-timer2-not-timer0-accurate-timing-embedded\\\/#organizationLogo\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/index.php\\\/author\\\/kgodden\\\/#author\",\"url\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/index.php\\\/author\\\/kgodden\\\/\",\"name\":\"Kevin Godden\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/index.php\\\/2019\\\/11\\\/12\\\/use-pic-timer2-not-timer0-accurate-timing-embedded\\\/#authorImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d2833f41e59a25cf2a9741a05ec383bfdd278762a5e0798a90940e7ab0a107a2?s=96&d=mm&r=g\",\"width\":96,\"height\":96,\"caption\":\"Kevin Godden\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/index.php\\\/2019\\\/11\\\/12\\\/use-pic-timer2-not-timer0-accurate-timing-embedded\\\/#webpage\",\"url\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/index.php\\\/2019\\\/11\\\/12\\\/use-pic-timer2-not-timer0-accurate-timing-embedded\\\/\",\"name\":\"Use PIC Timer2 not Timer0 for accurate Interval Timing on an Embedded system\",\"description\":\"Recently I was struggling to achieve very accurately synchronised camera and light triggers for a real-time computer vision project that I was working on, my original PIC embedded system for triggering everything using a PIC micro-controller had a fairly reliable accuracy of about 250us which was sufficient for a few years, but for various reasons\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/index.php\\\/2019\\\/11\\\/12\\\/use-pic-timer2-not-timer0-accurate-timing-embedded\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/index.php\\\/author\\\/kgodden\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/index.php\\\/author\\\/kgodden\\\/#author\"},\"datePublished\":\"2019-11-12T17:42:08+00:00\",\"dateModified\":\"2019-11-12T18:30:15+00:00\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/#website\",\"url\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/\",\"name\":\"Ridge Solutions, Software Development and Software Engineering, Ireland.\",\"description\":\"Some thoughts of a busy Computer Engineer\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"Use PIC Timer2 not Timer0 for accurate Interval Timing on an Embedded system","description":"Recently I was struggling to achieve very accurately synchronised camera and light triggers for a real-time computer vision project that I was working on, my original PIC embedded system for triggering everything using a PIC micro-controller had a fairly reliable accuracy of about 250us which was sufficient for a few years, but for various reasons","canonical_url":"https:\/\/www.ridgesolutions.ie\/index.php\/2019\/11\/12\/use-pic-timer2-not-timer0-accurate-timing-embedded\/","robots":"max-image-preview:large","keywords":"","webmasterTools":{"google-site-verification":"Kyj52YLp6GOPA44PVBffo9fjW8rgWHYYRF0ZYjfy6ss","miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.ridgesolutions.ie\/index.php\/2019\/11\/12\/use-pic-timer2-not-timer0-accurate-timing-embedded\/#article","name":"Use PIC Timer2 not Timer0 for accurate Interval Timing on an Embedded system","headline":"Use PIC Timer2 not Timer0 for accurate Interval Timing on an Embedded system","author":{"@id":"https:\/\/www.ridgesolutions.ie\/index.php\/author\/kgodden\/#author"},"publisher":{"@id":"https:\/\/www.ridgesolutions.ie\/#organization"},"image":{"@type":"ImageObject","url":"https:\/\/www.ridgesolutions.ie\/wp-content\/uploads\/2013\/09\/ridge_logo1.jpg","@id":"https:\/\/www.ridgesolutions.ie\/#articleImage","width":400,"height":81},"datePublished":"2019-11-12T17:42:08+00:00","dateModified":"2019-11-12T18:30:15+00:00","inLanguage":"en-US","mainEntityOfPage":{"@id":"https:\/\/www.ridgesolutions.ie\/index.php\/2019\/11\/12\/use-pic-timer2-not-timer0-accurate-timing-embedded\/#webpage"},"isPartOf":{"@id":"https:\/\/www.ridgesolutions.ie\/index.php\/2019\/11\/12\/use-pic-timer2-not-timer0-accurate-timing-embedded\/#webpage"},"articleSection":"Tech Stuff"},{"@type":"BreadcrumbList","@id":"https:\/\/www.ridgesolutions.ie\/index.php\/2019\/11\/12\/use-pic-timer2-not-timer0-accurate-timing-embedded\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/www.ridgesolutions.ie#listItem","position":1,"name":"Home","item":"https:\/\/www.ridgesolutions.ie","nextItem":{"@type":"ListItem","@id":"https:\/\/www.ridgesolutions.ie\/index.php\/category\/tech-stuff\/#listItem","name":"Tech Stuff"}},{"@type":"ListItem","@id":"https:\/\/www.ridgesolutions.ie\/index.php\/category\/tech-stuff\/#listItem","position":2,"name":"Tech Stuff","item":"https:\/\/www.ridgesolutions.ie\/index.php\/category\/tech-stuff\/","nextItem":{"@type":"ListItem","@id":"https:\/\/www.ridgesolutions.ie\/index.php\/2019\/11\/12\/use-pic-timer2-not-timer0-accurate-timing-embedded\/#listItem","name":"Use PIC Timer2 not Timer0 for accurate Interval Timing on an Embedded system"},"previousItem":{"@type":"ListItem","@id":"https:\/\/www.ridgesolutions.ie#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/www.ridgesolutions.ie\/index.php\/2019\/11\/12\/use-pic-timer2-not-timer0-accurate-timing-embedded\/#listItem","position":3,"name":"Use PIC Timer2 not Timer0 for accurate Interval Timing on an Embedded system","previousItem":{"@type":"ListItem","@id":"https:\/\/www.ridgesolutions.ie\/index.php\/category\/tech-stuff\/#listItem","name":"Tech Stuff"}}]},{"@type":"Organization","@id":"https:\/\/www.ridgesolutions.ie\/#organization","name":"Ridge Solutions, Software Development and Software Engineering, Ireland.","description":"Some thoughts of a busy Computer Engineer","url":"https:\/\/www.ridgesolutions.ie\/","logo":{"@type":"ImageObject","url":"https:\/\/www.ridgesolutions.ie\/wp-content\/uploads\/2013\/09\/ridge_logo1.jpg","@id":"https:\/\/www.ridgesolutions.ie\/index.php\/2019\/11\/12\/use-pic-timer2-not-timer0-accurate-timing-embedded\/#organizationLogo","width":400,"height":81},"image":{"@id":"https:\/\/www.ridgesolutions.ie\/index.php\/2019\/11\/12\/use-pic-timer2-not-timer0-accurate-timing-embedded\/#organizationLogo"}},{"@type":"Person","@id":"https:\/\/www.ridgesolutions.ie\/index.php\/author\/kgodden\/#author","url":"https:\/\/www.ridgesolutions.ie\/index.php\/author\/kgodden\/","name":"Kevin Godden","image":{"@type":"ImageObject","@id":"https:\/\/www.ridgesolutions.ie\/index.php\/2019\/11\/12\/use-pic-timer2-not-timer0-accurate-timing-embedded\/#authorImage","url":"https:\/\/secure.gravatar.com\/avatar\/d2833f41e59a25cf2a9741a05ec383bfdd278762a5e0798a90940e7ab0a107a2?s=96&d=mm&r=g","width":96,"height":96,"caption":"Kevin Godden"}},{"@type":"WebPage","@id":"https:\/\/www.ridgesolutions.ie\/index.php\/2019\/11\/12\/use-pic-timer2-not-timer0-accurate-timing-embedded\/#webpage","url":"https:\/\/www.ridgesolutions.ie\/index.php\/2019\/11\/12\/use-pic-timer2-not-timer0-accurate-timing-embedded\/","name":"Use PIC Timer2 not Timer0 for accurate Interval Timing on an Embedded system","description":"Recently I was struggling to achieve very accurately synchronised camera and light triggers for a real-time computer vision project that I was working on, my original PIC embedded system for triggering everything using a PIC micro-controller had a fairly reliable accuracy of about 250us which was sufficient for a few years, but for various reasons","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/www.ridgesolutions.ie\/#website"},"breadcrumb":{"@id":"https:\/\/www.ridgesolutions.ie\/index.php\/2019\/11\/12\/use-pic-timer2-not-timer0-accurate-timing-embedded\/#breadcrumblist"},"author":{"@id":"https:\/\/www.ridgesolutions.ie\/index.php\/author\/kgodden\/#author"},"creator":{"@id":"https:\/\/www.ridgesolutions.ie\/index.php\/author\/kgodden\/#author"},"datePublished":"2019-11-12T17:42:08+00:00","dateModified":"2019-11-12T18:30:15+00:00"},{"@type":"WebSite","@id":"https:\/\/www.ridgesolutions.ie\/#website","url":"https:\/\/www.ridgesolutions.ie\/","name":"Ridge Solutions, Software Development and Software Engineering, Ireland.","description":"Some thoughts of a busy Computer Engineer","inLanguage":"en-US","publisher":{"@id":"https:\/\/www.ridgesolutions.ie\/#organization"}}]},"og:locale":"en_US","og:site_name":"Systems and Embedded Software Engineering, Ireland. | Some thoughts of a busy Computer Engineer","og:type":"article","og:title":"Use PIC Timer2 not Timer0 for accurate Interval Timing on an Embedded system","og:description":"Recently I was struggling to achieve very accurately synchronised camera and light triggers for a real-time computer vision project that I was working on, my original PIC embedded system for triggering everything using a PIC micro-controller had a fairly reliable accuracy of about 250us which was sufficient for a few years, but for various reasons","og:url":"https:\/\/www.ridgesolutions.ie\/index.php\/2019\/11\/12\/use-pic-timer2-not-timer0-accurate-timing-embedded\/","article:published_time":"2019-11-12T16:42:08+00:00","article:modified_time":"2019-11-12T17:30:15+00:00","twitter:card":"summary","twitter:title":"Use PIC Timer2 not Timer0 for accurate Interval Timing on an Embedded system","twitter:description":"Recently I was struggling to achieve very accurately synchronised camera and light triggers for a real-time computer vision project that I was working on, my original PIC embedded system for triggering everything using a PIC micro-controller had a fairly reliable accuracy of about 250us which was sufficient for a few years, but for various reasons"},"aioseo_meta_data":{"post_id":"2620","title":null,"description":null,"keywords":[{"label":"Embedded","value":"Embedded"},{"label":"PIC","value":"PIC"},{"label":"timer","value":"timer"},{"label":"timer0","value":"timer0"},{"label":"timer2","value":"timer2"}],"keyphrases":{"focus":[],"additional":[]},"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":null,"og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"","isEnabled":true},"graphs":[]},"schema_type":null,"schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"local_seo":null,"breadcrumb_settings":null,"limit_modified_date":false,"ai":null,"created":"2021-09-13 11:19:05","updated":"2026-08-07 16:46:47","seo_analyzer_scan_date":null,"focus_keyword":null,"additional_keywords":null,"truseo_locale":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.ridgesolutions.ie\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.ridgesolutions.ie\/index.php\/category\/tech-stuff\/\" title=\"Tech Stuff\">Tech Stuff<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tUse PIC Timer2 not Timer0 for accurate Interval Timing on an Embedded system\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/www.ridgesolutions.ie"},{"label":"Tech Stuff","link":"https:\/\/www.ridgesolutions.ie\/index.php\/category\/tech-stuff\/"},{"label":"Use PIC Timer2 not Timer0 for accurate Interval Timing on an Embedded system","link":"https:\/\/www.ridgesolutions.ie\/index.php\/2019\/11\/12\/use-pic-timer2-not-timer0-accurate-timing-embedded\/"}],"_links":{"self":[{"href":"https:\/\/www.ridgesolutions.ie\/index.php\/wp-json\/wp\/v2\/posts\/2620","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ridgesolutions.ie\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ridgesolutions.ie\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ridgesolutions.ie\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ridgesolutions.ie\/index.php\/wp-json\/wp\/v2\/comments?post=2620"}],"version-history":[{"count":0,"href":"https:\/\/www.ridgesolutions.ie\/index.php\/wp-json\/wp\/v2\/posts\/2620\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.ridgesolutions.ie\/index.php\/wp-json\/wp\/v2\/media?parent=2620"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ridgesolutions.ie\/index.php\/wp-json\/wp\/v2\/categories?post=2620"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ridgesolutions.ie\/index.php\/wp-json\/wp\/v2\/tags?post=2620"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}