{"id":1409,"date":"2023-09-14T17:55:20","date_gmt":"2023-09-14T16:55:20","guid":{"rendered":"https:\/\/ibex.tech\/embedded\/?p=1409"},"modified":"2023-09-21T10:42:26","modified_gmt":"2023-09-21T09:42:26","slug":"timer-interrupt-driven","status":"publish","type":"post","link":"https:\/\/ibex.tech\/embedded\/microchip\/pic32\/xc32\/timers-and-delays-xc32\/timer-interrupt-driven","title":{"rendered":"Timer (interrupt driven)"},"content":{"rendered":"\n<p>Configure the timer in MCC and select interrupt driven.<\/p>\n\n\n\n<p>Once you Geneate the MCC code it will have dealt with initialising the timer ready for you to use it.<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">In your code<\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;definitions.h>\t\t\t\/\/Include all the MCC generated files so their fucntions can be called\n\n\/\/IN YOUR INITIALSE CODE\n\t\/\/----- SETUP TIMER 5 -----\n\t\/\/Used for: Heartbeat\n\t\/\/Config done in MCC:\n\t\/\/\tSetup Timer:\n\t\/\/\t\tEnable interrupts: Yes\n\t\/\/\t\tPrescaller: 1:1\n\t\/\/\t\tClock source: Internal peripheral clock\n\t\/\/\t\tTime: 1mS\n\t\/\/\tSetup interrupts:\n\t\/\/\t\tPriority (set for all): 3\t\/\/&lt;&lt;&lt;Set as required for your application\n\t\/\/\t\tSubpriority (set for all): 0\t\/\/&lt;&lt;&lt;Set as required for your application\n\n\tTMR5_CallbackRegister(TMR5_MyEventHandler, (uintptr_t)NULL);\t\t\/\/Register our callback function to be called when the timer interrupts\n\tTMR5_Start();\t\t\t\t\/\/Start the timer\n\n\/\/YOUR FUNCTION TO BE CALLED ON EACH TIMER ROLL OVER\n\/\/*********************************************\n\/\/*********************************************\n\/\/********** HEARTBEAT IRQ (Timer 5) **********\n\/\/*********************************************\n\/\/*********************************************\nvoid TMR5_MyEventHandler(uint32_t status, uintptr_t context)\n{\n\t\n\t\/\/Toggle a pin:\n\tif (LATAbits.LATA6)\n\t\tLATAbits.LATA6 = 0;\n\telse\n\t\tLATAbits.LATA6 = 1;\n\t\n}<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">Other timer functions<\/h5>\n\n\n\n<p>MCC will have created a few useful functions you can call &#8211; see the file it generated in: \/config\/default\/peripheral\/tmr\/<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Configure the timer in MCC and select interrupt driven. Once you Geneate the MCC code it will have dealt with initialising the timer ready for you to use it. In your code Other timer functions MCC will have created a few useful functions you can call &#8211; see the file it generated in: \/config\/default\/peripheral\/tmr\/<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[111],"tags":[],"class_list":["post-1409","post","type-post","status-publish","format-standard","hentry","category-timers-and-delays-xc32"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/embedded\/wp-json\/wp\/v2\/posts\/1409","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=1409"}],"version-history":[{"count":9,"href":"https:\/\/ibex.tech\/embedded\/wp-json\/wp\/v2\/posts\/1409\/revisions"}],"predecessor-version":[{"id":1471,"href":"https:\/\/ibex.tech\/embedded\/wp-json\/wp\/v2\/posts\/1409\/revisions\/1471"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/embedded\/wp-json\/wp\/v2\/media?parent=1409"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/embedded\/wp-json\/wp\/v2\/categories?post=1409"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/embedded\/wp-json\/wp\/v2\/tags?post=1409"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}