{"id":1636,"date":"2016-12-19T15:20:52","date_gmt":"2016-12-19T14:20:52","guid":{"rendered":"http:\/\/www.macerobotics.com\/?p=1636"},"modified":"2016-12-19T15:21:11","modified_gmt":"2016-12-19T14:21:11","slug":"utiliser-un-timer","status":"publish","type":"post","link":"http:\/\/www.macerobotics.com\/?p=1636","title":{"rendered":"Utiliser un timer"},"content":{"rendered":"<p>Ce tutoriel pr\u00e9sente l&#8217;utilisation d&#8217;un timer avec la carte Esus. La fr\u00e9quence du microcontr\u00f4leur ESP8266 est de 80Mhz soit 12.5ns le cycle processeur.<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"\" src=\"https:\/\/openclipart.org\/image\/2400px\/svg_to_png\/83113\/TSD-free--zone-starts.png\" alt=\"TSD-free -zone-starts by netalloy\" width=\"70\" height=\"70\" \/><\/p>\n<h1>Exemple n\u00b01<\/h1>\n<p>L&#8217;exemple n\u00b01 permet de faire clignoter une led toute les secondes. La led est c\u00e2ble sur la sortie IO2 de la carte Esus.<\/p>\n<pre><strong>#include &lt;esusBoard.h&gt;<\/strong>\r\n\r\n<strong><span style=\"color: #008000;\">\/\/ (80Mhz frequence ESP8266) 1 cycle = 12.5ns =&gt; 1seconde\/12.5ns = 80000000<\/span> <\/strong>\r\n<strong>const int timer_period=80000000;<\/strong>\r\n\r\n<strong>void setup() <\/strong>\r\n<strong>{<\/strong>\r\n<strong>\u00a0 initEsusBoard();<\/strong>\r\n\r\n  <strong><span style=\"color: #008000;\">\/\/ sortie 2 pour la led<\/span><\/strong>\r\n<strong>\u00a0 pinMode(2, OUTPUT);<\/strong>\r\n\r\n<strong>\u00a0 noInterrupts();\r\n \r\n  <span style=\"color: #008000;\">\/\/ initialisation timer 0 avec interruption<\/span><\/strong>\r\n<strong>\u00a0 timer0_isr_init();\r\n\r\n  <span style=\"color: #008000;\">\/\/ sp\u00e9cifie la fonction \u00e0 appeler lorsqu'une interruption du timer survient<\/span>  <\/strong>\r\n<strong>\u00a0 timer0_attachInterrupt(handler);<\/strong>\r\n\r\n  <span style=\"color: #008000;\"><strong>\/\/ p\u00e9riode du timer<\/strong><\/span>\r\n<strong>\u00a0 timer0_write(ESP.getCycleCount() + timer_period); <\/strong>\r\n<strong>\u00a0 interrupts();<\/strong>\r\n\r\n<strong>}<\/strong>\r\n\r\n<strong>void loop()<\/strong>\r\n<strong>{<\/strong>\r\n\r\n<strong>}<\/strong>\r\n\r\n<strong>void handler(void)<\/strong>\r\n<strong>{<\/strong>\r\n<strong>\u00a0timer0_write(ESP.getCycleCount() + timer_period);<\/strong>\r\n\r\n <strong><span style=\"color: #008000;\">\/\/ toggle sortie 2<\/span><\/strong>\r\n<strong>\u00a0digitalWrite(2, !digitalRead(2));<\/strong>\r\n<strong>\u00a0<\/strong>\r\n<strong>}<\/strong><\/pre>\n<h1>Exemple n\u00b02<\/h1>\n<p>L&#8217;exemple n\u00b02 permet de faire clignoter une led toute les 5 secondes. La led est c\u00e2bl\u00e9 sur la sortie IO2 de la carte Esus.<\/p>\n<pre><strong>#include &lt;esusBoard.h&gt;<\/strong>\r\n\r\n<strong><span style=\"color: #008000;\">\/\/ (80Mhz frequence ESP8266) 1 cycle = 12.5ns =&gt; 1seconde\/12.5ns = 80000000<\/span> <\/strong>\r\n<strong>const int timer_period=80000000;<\/strong>\r\n\r\n<strong>void setup() <\/strong>\r\n<strong>{<\/strong>\r\n<strong>\u00a0 initEsusBoard();<\/strong>\r\n\r\n  <strong><span style=\"color: #008000;\">\/\/ sortie 2 pour la led<\/span><\/strong>\r\n<strong>\u00a0 pinMode(2, OUTPUT);<\/strong>\r\n\r\n<strong>\u00a0 noInterrupts();<\/strong>\r\n<strong>\u00a0 timer0_isr_init();<\/strong>\r\n<strong>\u00a0 timer0_attachInterrupt(handler);<\/strong>\r\n\r\n<strong>\u00a0 timer0_write(ESP.getCycleCount() + timer_period); <\/strong>\r\n<strong>\u00a0 interrupts();<\/strong>\r\n\r\n<strong>}<\/strong>\r\n\r\n<strong>void loop()<\/strong>\r\n<strong>{<\/strong>\r\n\r\n<strong>}<\/strong>\r\n\r\n<strong>void handler(void)<\/strong>\r\n<strong>{<\/strong>\r\n<strong>\u00a0timer0_write(ESP.getCycleCount() + timer_period);<\/strong>\r\n\r\n <strong><span style=\"color: #008000;\">\/\/ toggle sortie 2<\/span><\/strong>\r\n<strong>\u00a0digitalWrite(2, !digitalRead(2));<\/strong>\r\n<strong>\u00a0<\/strong>\r\n<strong>}<\/strong><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Ce tutoriel pr\u00e9sente l&#8217;utilisation d&#8217;un timer avec la carte Esus. La fr\u00e9quence du microcontr\u00f4leur ESP8266 est de 80Mhz soit 12.5ns le cycle processeur. Exemple n\u00b01 L&#8217;exemple n\u00b01 permet de faire clignoter une led toute les secondes. La led est c\u00e2ble sur la sortie IO2 de la carte Esus. #include &lt;esusBoard.h&gt; \/\/ (80Mhz frequence ESP8266) 1 &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[50,44,26],"tags":[],"class_list":["post-1636","post","type-post","status-publish","format-standard","hentry","category-esp8266","category-esus","category-tutoriel"],"_links":{"self":[{"href":"http:\/\/www.macerobotics.com\/index.php?rest_route=\/wp\/v2\/posts\/1636","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.macerobotics.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.macerobotics.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.macerobotics.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.macerobotics.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1636"}],"version-history":[{"count":1,"href":"http:\/\/www.macerobotics.com\/index.php?rest_route=\/wp\/v2\/posts\/1636\/revisions"}],"predecessor-version":[{"id":1637,"href":"http:\/\/www.macerobotics.com\/index.php?rest_route=\/wp\/v2\/posts\/1636\/revisions\/1637"}],"wp:attachment":[{"href":"http:\/\/www.macerobotics.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1636"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.macerobotics.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1636"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.macerobotics.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1636"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}