{"id":407,"date":"2014-01-31T07:28:02","date_gmt":"2014-01-31T07:28:02","guid":{"rendered":"https:\/\/ibex.tech\/embedded\/?p=407"},"modified":"2022-02-18T15:37:49","modified_gmt":"2022-02-18T15:37:49","slug":"delays","status":"publish","type":"post","link":"https:\/\/ibex.tech\/embedded\/microchip\/pic32\/xc32-v2-old\/timers-and-delays\/delays","title":{"rendered":"Delays"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\">uS Delay Function Using Core Timer<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/******************************\n\/\/******************************\n\/\/********** DELAY US **********\n\/\/******************************\n\/\/******************************\n\/\/Uses Core Timer\nvoid delay_us (uint16_t delay)\n{\n\tunsigned int int_status;\n\n\tint_status = INTDisableInterrupts();\n\tOpenCoreTimer((INSTRUCTION_CLOCK_FREQUENCY \/ 2000000) * delay);\t\/\/ Core Timer updates every 2 ticks\n\tmCTClearIntFlag();\t\t\t\t\t\/\/Clear core timer interrupt flag before re-enabling interrupts to avoid posibility of ISR from another interrupt causing us to miss the CT interrupt.\n\tINTRestoreInterrupts(int_status);\n\twhile( !mCTGetIntFlag() )\n\t\t;\n\n\tmCTClearIntFlag();\n}<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">mS Delay Function Using Core Timer<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/#define\tINSTRUCTION_CLOCK_FREQUENCY\t80000000\n  \n\/\/******************************\n\/\/******************************\n\/\/********** DELAY MS **********\n\/\/******************************\n\/\/******************************\n\/\/Uses Core Timer\nvoid delay_ms (uint16_t delay)\n{\n\tunsigned int int_status;\n\twhile(delay--)\n\t{\n\t\tint_status = INTDisableInterrupts();\n\t\tOpenCoreTimer(INSTRUCTION_CLOCK_FREQUENCY \/ 2000);\t\/\/ Core Timer updates every 2 ticks\n\t\tmCTClearIntFlag();\t\t\t\t\t\/\/Clear core timer interrupt flag before re-enabling interrupts to avoid posibility of ISR from another interrupt causing us to miss the CT interrupt.\n\t\tINTRestoreInterrupts(int_status);\n\t\twhile( !mCTGetIntFlag() )\n\t\t\t;\n\t}\n\tmCTClearIntFlag();\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>uS Delay Function Using Core Timer mS Delay Function Using Core Timer<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[41],"tags":[],"class_list":["post-407","post","type-post","status-publish","format-standard","hentry","category-timers-and-delays"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/embedded\/wp-json\/wp\/v2\/posts\/407","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=407"}],"version-history":[{"count":5,"href":"https:\/\/ibex.tech\/embedded\/wp-json\/wp\/v2\/posts\/407\/revisions"}],"predecessor-version":[{"id":1233,"href":"https:\/\/ibex.tech\/embedded\/wp-json\/wp\/v2\/posts\/407\/revisions\/1233"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/embedded\/wp-json\/wp\/v2\/media?parent=407"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/embedded\/wp-json\/wp\/v2\/categories?post=407"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/embedded\/wp-json\/wp\/v2\/tags?post=407"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}