{"id":848,"date":"2018-10-30T14:29:50","date_gmt":"2018-10-30T14:29:50","guid":{"rendered":"https:\/\/ibex.tech\/embedded\/?p=848"},"modified":"2022-02-18T15:37:48","modified_gmt":"2022-02-18T15:37:48","slug":"input-capture","status":"publish","type":"post","link":"https:\/\/ibex.tech\/embedded\/microchip\/pic32\/xc32-v2-old\/input-capture\/input-capture","title":{"rendered":"Input Capture"},"content":{"rendered":"<h5>\nSetup Input Capture<br \/>\n<\/h5>\n<pre>\r\n<code>\r\n\t\/\/----- SETUP TIMER 3 -----\r\n\t\/\/Used for: Input capture\r\n\tOpenTimer3((T3_ON | T3_IDLE_CON | T3_GATE_OFF | T3_PS_1_1 | T3_SOURCE_INT), 0xffff);\r\n\t\r\n\t\/\/-------------------------------\r\n\t\/\/----- SETUP INPUT CAPTURE -----\r\n\t\/\/-------------------------------\r\n\t\/\/Parameter 1:\r\n\t\/\/IC_EVERY_FALL_EDGE\t\t\tCapture timer value on every falling edge of input applied at the ICx pin\r\n\t\/\/IC_EVERY_RISE_EDGE&nbsp;\t\t\tCapture timer value on every rising edge of input applied at the ICx pin\r\n\t\/\/IC_EVERY_4_RISE_EDGE&nbsp;\t\t\tCapture timer value on every fourth rising edge of input applied at the ICx pin\r\n\t\/\/IC_EVERY_16_RISE_EDGE&nbsp;\t\tCapture timer value on every sixteenth rising edge of input applied at the ICx pin\r\n\t\/\/IC_EVERY_EDGE\t\t\t\t\tCapture timer value on every rising and falling edge of input applied at the ICx pin\r\n\t\/\/IC_SP_EVERY_EDGE\t\t\t\tCapture timer value on the specified edge and every edge thereafter\r\n\t\/\/\r\n\t\/\/Parameter 2:\r\n\t\/\/IC_INT_1CAPTURE&nbsp;\t\t\t\/\/Interrupt on first Capture&nbsp;\r\n\t\/\/IC_INT_2CAPTURE&nbsp;\t\t\t\/\/Interrupt on second Capture&nbsp;\r\n\t\/\/IC_INT_3CAPTURE&nbsp;\t\t\t\/\/Interrupt on third Capture&nbsp;\r\n\t\/\/IC_INT_4CAPTURE&nbsp;\t\t\t\/\/Interrupt on fourth Capture&nbsp;\r\n\t\/\/\r\n\t\/\/Parameter 3:\r\n\t\/\/IC_TIMER2_SRC&nbsp;\t\t\t\t\/\/Timer2 is the clock source for Capture&nbsp;\r\n\t\/\/IC_TIMER3_SRC&nbsp;\t\t\t\t\/\/Timer 3 is the clock source for Capture&nbsp;\r\n\t\/\/\r\n\t\/\/Parameter 4:\r\n\t\/\/IC_FEDGE_FALL&nbsp;\t\t\t\t\/\/Capture Falling Edge First&nbsp;\r\n\t\/\/IC_FEDGE_RISE&nbsp;\t\t\t\t\/\/Capture Rising Edge First&nbsp;\r\n    OpenCapture1( IC_EVERY_FALL_EDGE | IC_INT_1CAPTURE | IC_TIMER3_SRC | IC_FEDGE_RISE | IC_ON );\r\n\tOpenCapture2( IC_EVERY_FALL_EDGE | IC_INT_1CAPTURE | IC_TIMER3_SRC | IC_FEDGE_RISE | IC_ON );\r\n\tOpenCapture3( IC_EVERY_FALL_EDGE | IC_INT_1CAPTURE | IC_TIMER3_SRC | IC_FEDGE_RISE | IC_ON );\r\n\tOpenCapture4( IC_EVERY_EDGE | IC_INT_1CAPTURE | IC_TIMER3_SRC | IC_FEDGE_RISE | IC_ON );\r\n\t\r\n\t\/\/FIF0\r\n\t\/\/Each Input Capture has a four-level deep FIFO buffer\r\n\t\/\/If the FIFO is full with four capture events and a fifth capture event occurs prior to a read of the FIFO, ICOV bit (ICxCON&lt;4&gt;) is set\/\r\n\t\/\/The fifth capture event is not recorded, subsequent capture events do not alter the current FIFO contents until the overrun condition is\r\n\t\/\/cleared, and an input capture error interrupt will be generated.\r\n<\/code><\/pre>\n<h5>\nReading the Input Capture<br \/>\n<\/h5>\n<pre>\r\n<code>\r\n\t\/\/GET INPUT CAPTURE\r\n\tif (mICxCaptureReady())\r\n\t{\r\n\t\t\/\/if (ICxCONbits.ICOV)\r\n\t\t\/\/{\r\n\t\t\/\/\t\/\/INPUT CAPTURE HAS OVERRUN\r\n\t\t\/\/\t\/\/You don&#39;t have to worry about this if you don&#39;t care about every capture as reading the 4 FIFO entries will clear it and start it storing\r\n\t\t\/\/\t\/\/again - it just stops storing while the FIFO is full).\r\n\t\t\/\/\t\/\/If you care then disable the input capture and then re-enable it again\r\n\t\t\/\/}\r\n\t\t\t\t\r\n\t\twhile(mICxCaptureReady())\t\t\t\/\/Each Input Capture has a four-level deep FIFO buffer\r\n\t\t{\r\n\t\t\tint CaptureTime = mICxReadCapture();\r\n\t\t}\r\n\t}\r\n<\/code><\/pre>\n<p>\n&nbsp;\n<\/p>\n<p>\n&nbsp;\n<\/p>\n<p>\n&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Setup Input Capture \/\/&#8212;&#8211; SETUP TIMER 3 &#8212;&#8211; \/\/Used for: Input capture OpenTimer3((T3_ON | T3_IDLE_CON | T3_GATE_OFF | T3_PS_1_1 | T3_SOURCE_INT), 0xffff); \/\/&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;- \/\/&#8212;&#8211; SETUP INPUT CAPTURE &#8212;&#8211; \/\/&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;- \/\/Parameter 1: \/\/IC_EVERY_FALL_EDGE Capture timer value on every falling edge of input applied at the ICx pin \/\/IC_EVERY_RISE_EDGE&nbsp; Capture timer value on every rising edge of [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[72],"tags":[],"class_list":["post-848","post","type-post","status-publish","format-standard","hentry","category-input-capture"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/embedded\/wp-json\/wp\/v2\/posts\/848","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/embedded\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/embedded\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/embedded\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/embedded\/wp-json\/wp\/v2\/comments?post=848"}],"version-history":[{"count":3,"href":"https:\/\/ibex.tech\/embedded\/wp-json\/wp\/v2\/posts\/848\/revisions"}],"predecessor-version":[{"id":861,"href":"https:\/\/ibex.tech\/embedded\/wp-json\/wp\/v2\/posts\/848\/revisions\/861"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/embedded\/wp-json\/wp\/v2\/media?parent=848"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/embedded\/wp-json\/wp\/v2\/categories?post=848"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/embedded\/wp-json\/wp\/v2\/tags?post=848"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}