
{"id":7480,"date":"2018-06-27T12:43:06","date_gmt":"2018-06-27T03:43:06","guid":{"rendered":"https:\/\/okiraku-camera.tokyo\/blog\/?p=7480"},"modified":"2023-11-23T21:42:15","modified_gmt":"2023-11-23T12:42:15","slug":"attiny85%e3%81%a7%e8%b5%a4%e5%a4%96%e7%b7%9a%e3%83%aa%e3%83%a2%e3%82%b3%e3%83%b3%e7%94%a8%e3%81%ae%e6%b3%a2%e5%bd%a2%e3%82%92%e4%bd%9c%e3%82%8b%e8%a9%b1","status":"publish","type":"post","link":"https:\/\/okiraku-camera.tokyo\/blog\/?p=7480","title":{"rendered":"ATtiny85\u3067\u8d64\u5916\u7dda\u30ea\u30e2\u30b3\u30f3\u7528\u306e\u6ce2\u5f62\u3092\u4f5c\u308b\u8a71"},"content":{"rendered":"<h1>\u6982\u8981<\/h1>\n<p>ATtiny5\u30b7\u30ea\u30fc\u30ba(ATtiny85\/45\/25)\u306e\u3082\u3064PWM\u6a5f\u80fd\u3092\u4f7f\u3063\u3066\u3001\u5bb6\u96fb\u7528\u306e\u8d64\u5916\u7dda\u30ea\u30e2\u30b3\u30f3\u306e\u305f\u3081\u306e\u6ce2\u5f62(38kHz\u3001\u30c7\u30e5\u30fc\u30c6\u30a31\/3)\u3092\u4f5c\u3063\u3066\u307f\u308b\u3002Arduino\u3067\u4f7f\u308f\u308c\u3066\u3044\u308bATmega8\u30b7\u30ea\u30fc\u30ba\u3067\u306f\u3001<strong>\u30bf\u30a4\u30de\u30fc\u30ab\u30a6\u30f3\u30bf\u30e6\u30cb\u30c3\u30c8(TC\u30e6\u30cb\u30c3\u30c8)<\/strong>\u304c\u3082\u3064PWM\u6a5f\u80fd\u3092\u4f7f\u3046\u306e\u304c\u4e00\u756a\u7c21\u5358\u3060\u3063\u305f\u306e\u3067\u3001ATtiny\u3067\u3082\u540c\u3058\u3088\u3046\u306b\u3067\u304d\u308b\u3060\u308d\u3046\u3068\u671f\u5f85\u3057\u3066<a href=\"http:\/\/ww1.microchip.com\/downloads\/en\/DeviceDoc\/Atmel-2586-AVR-8-bit-Microcontroller-ATtiny25-ATtiny45-ATtiny85_Datasheet.pdf\" target=\"_blank\" rel=\"noopener\">\u30c7\u30fc\u30bf\u30b7\u30fc\u30c8<\/a>\u3092\u53c2\u8003\u306b\u8abf\u3079\u3066\u307f\u305f\u3002<\/p>\n<p>\u8d64\u5916\u7dda\u30ea\u30e2\u30b3\u30f3\u304c\u9001\u4fe1\u3059\u308b\u30c7\u30fc\u30bf\u3084\u6ce2\u5f62\u306b\u3064\u3044\u3066\u306f<a href=\"https:\/\/okiraku-camera.tokyo\/blog\/?p=4854\" target=\"_blank\" rel=\"noopener\">\u4ee5\u524d\u307e\u3068\u3081\u305f\u3082\u306e<\/a>\u3092\u53c2\u7167\u306e\u3053\u3068\u3002<\/p>\n<h1>PWM\u3067\u306e\u6ce2\u5f62\u306e\u4f5c\u6210<\/h1>\n<p>ATtiny5\u30b7\u30ea\u30fc\u30ba\u306b\u306f\u3001TC0\u3068TC1\u306e2\u3064\u306eTC\u30e6\u30cb\u30c3\u30c8\u304c\u3042\u308a\u3001\u304a\u306e\u304a\u306ePWM\u6a5f\u80fd\u3092\u5099\u3048\u3066\u3044\u308b\u3002\u5404TC\u30e6\u30cb\u30c3\u30c8\u306e\u30ab\u30a6\u30f3\u30bf(<em>TCNT0<\/em>\u304a\u3088\u3073<em>TCNT1<\/em>)\u306f8\u30d3\u30c3\u30c8\u9577\u3067\u3001\u30b7\u30b9\u30c6\u30e0\u30af\u30ed\u30c3\u30af(\u3042\u308b\u3044\u306fTC\u30e6\u30cb\u30c3\u30c8\u306e\u30d7\u30ea\u30b9\u30b1\u30fc\u30e9\u3067\u5206\u5468\u3057\u305f\u30af\u30ed\u30c3\u30af)\u306e\u523b\u307f\u306b\u3088\u308a\u3001\u52d5\u4f5c\u30e2\u30fc\u30c9\u306b\u5fdc\u3058\u3066\u30ab\u30a6\u30f3\u30c8\u30a2\u30c3\u30d7\u3055\u308c\u305f\u308a\u30ab\u30a6\u30f3\u30c8\u30c0\u30a6\u30f3\u3055\u308c\u305f\u308a\u3059\u308b\u3002<br \/>\n\u524d\u306b\u3082\u66f8\u3044\u305f\u3088\u3046\u306bATtiny5\u30b7\u30ea\u30fc\u30ba\u306f\u5c11\u306a\u3044\u30d4\u30f3\u6570(8\u30d4\u30f3)\u306e\u4e2d\u306b\u3044\u308d\u3044\u308d\u306a\u6a5f\u80fd\u304c\u8a70\u3081\u8fbc\u307e\u308c\u3066\u3044\u308b\u304b\u3089\u3001PWM\u6ce2\u5f62\u3092\u51fa\u529b\u3067\u304d\u308b\u30d4\u30f3\u306b\u3088\u3063\u3066\u3001\u5168\u4f53\u306e\u69cb\u6210\u304c\u6c7a\u307e\u3063\u3066\u3057\u307e\u3046\u304b\u3082\u3057\u308c\u306a\u3044\u3002PWM\u6ce2\u5f62\u304c\u51fa\u529b\u3067\u304d\u308b\u30d4\u30f3(TC\u30e6\u30cb\u30c3\u30c8\u306e\u6bd4\u8f03\u51fa\u529b\u30d4\u30f3\u00a0 : <em><strong>Output Compare pin<\/strong><\/em> )\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u3063\u3066\u3044\u308b\u3002<\/p>\n<ul>\n<li>PB0 (#5) : OC0A\u3001 \/OC1A\u00a0(OC1A\u306e\u53cd\u8ee2\u51fa\u529b)\u3002<\/li>\n<li>PB1(#6) : OC0B\u3001 OC1A<\/li>\n<li>PB3(#2) : \/OC1B(OC1B\u306e\u53cd\u8ee2\u51fa\u529b)\u3002<\/li>\n<li>PB4 (#3) : OC1B<br \/>\n(OC\u306e\u3042\u3068\u306e\u6570\u5b57\u306f\u3001TC\u30e6\u30cb\u30c3\u30c8\u306e\u756a\u53f7)<\/li>\n<\/ul>\n<p>\u3064\u307e\u308a\u3001\u5404TC\u30e6\u30cb\u30c3\u30c8\u3054\u3068\u306bA\u3068B\u306e2\u3064\u306e\u6bd4\u8f03\u51fa\u529b\u30d4\u30f3\u304c\u3042\u308b\u3002\u6bd4\u8f03\u51fa\u529b\u30d4\u30f3\u306f\u3001TC\u30e6\u30cb\u30c3\u30c8\u306e\u30ab\u30a6\u30f3\u30bf\u5024\u304c\u5bfe\u5fdc\u3059\u308b\u6bd4\u8f03\u51fa\u529b\u30ec\u30b8\u30b9\u30bf(<em><strong>Output Compare RegisterA<\/strong> \u304a\u3088\u3073<strong>B<\/strong><\/em>) \u306e\u5024\u306b\u4e00\u81f4\u3057\u305f\u3068\u304d\u3001\u30bb\u30c3\u30c8(HIGH\u3092\u51fa\u529b)\u307e\u305f\u306f\u30ea\u30bb\u30c3\u30c8(LOW\u3092\u51fa\u529b)\u3055\u308c\u308b\u3002\u307e\u305f\u3001\u30ab\u30a6\u30f3\u30bf\u306e\u5024\u304c0\u306b\u623b\u3063\u305f\u3068\u304d\u306b\u3082\u30bb\u30c3\u30c8\u3055\u308c\u305f\u308a\u30ea\u30bb\u30c3\u30c8\u3055\u308c\u305f\u308a\u3059\u308b\u3002\u3053\u3046\u3044\u3063\u305f\u6319\u52d5\u3092\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u3059\u308b\u3053\u3068\u3067\u3001\u4efb\u610f\u306e\u6ce2\u5f62\u3092\u51fa\u529b\u3055\u305b\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u3002\u30ea\u30e2\u30b3\u30f3\u7528\u306e\u6ce2\u5f62\u3092\u4f5c\u308b\u3068\u304d\u306f\u3001<strong>Fast PWM\u30e2\u30fc\u30c9<\/strong>\u3092\u4f7f\u3046\u306e\u304c\u7c21\u5358\u3060\u3063\u305f\u3002<\/p>\n<p>Fast PWM\u30e2\u30fc\u30c9\u3067\u306f\u3001TC\u30e6\u30cb\u30c3\u30c8\u306e\u30ab\u30a6\u30f3\u30bf(TCNT0\u307e\u305f\u306fTCNT1)\u306e\u5024\u306f\u3001\u30af\u30ed\u30c3\u30af(\u30d7\u30ea\u30b9\u30b1\u30fc\u30e9\u306b\u3088\u3063\u3066\u5206\u5468\u3055\u308c\u305f\u30b7\u30b9\u30c6\u30e0\u30af\u30ed\u30c3\u30af)\u304c\u523b\u307e\u308c\u308b\u305f\u3073\u306b\u30a4\u30f3\u30af\u30ea\u30e1\u30f3\u30c8\u3055\u308c\u308b(Phase Correct PWM\u30e2\u30fc\u30c9\u306e\u5834\u5408\u3001\u6307\u5b9a\u671f\u9593\u306e\u30a4\u30f3\u30af\u30ea\u30e1\u30f3\u30c8\u3068\u30c7\u30af\u30ea\u30e1\u30f3\u30c8\u3092\u7e70\u308a\u8fd4\u3059\u3053\u3068\u306b\u306a\u308b\u304c\u3001\u3053\u3053\u3067\u306f\u89e6\u308c\u306a\u3044)\u3002<\/p>\n<p>\u5358\u7d14\u5897\u52a0\u3059\u308b\u30ab\u30a6\u30f3\u30bf\u5024\u306f\u3001\u6bd4\u8f03\u51fa\u529b\u30ec\u30b8\u30b9\u30bf\u306b\u8a2d\u5b9a\u53ef\u80fd\u306aTOP\u5024\u306b\u4e00\u81f4\u3059\u308b\u30680\u306b\u623b\u308a\u30010\u304b\u3089\u30ab\u30a6\u30f3\u30c8\u30a2\u30f3\u30d7\u3092\u518d\u958b\u3059\u308b\u3002\u3053\u306e\u3053\u3068\u304b\u3089\u3001<span style=\"text-decoration: underline;\">TOP\u306e\u5024\u306b\u3088\u3063\u3066\u51fa\u529b\u6ce2\u5f62\u306e\u5468\u671f\u3092\u8868\u73fe\u3059\u308b<\/span>\u3053\u3068\u304c\u3067\u304d\u308b\u3002<br \/>\n\u307e\u305f\u3001\u5225\u306e\u6bd4\u8f03\u51fa\u529b\u30ec\u30b8\u30b9\u30bf\u306b\u6ce2\u5f62\u306eHIGH\u671f\u9593\u3092\u5165\u308c\u3066\u304a\u304d\u3001\u5bfe\u5fdc\u3059\u308b\u6bd4\u8f03\u51fa\u529b\u30d4\u30f3\u304c\u3001<br \/>\n\u30fb\u30ab\u30a6\u30f3\u30bf\u304c0\u306a\u3089\u30bb\u30c3\u30c8(HIGH\u51fa\u529b)<br \/>\n\u30fb\u5024\u4e00\u81f4\u306a\u3089\u30ea\u30bb\u30c3\u30c8(LOW\u51fa\u529b)<br \/>\n\u3068\u52d5\u4f5c\u3059\u308b\u3088\u3046\u8a2d\u5b9a\u3057\u3066\u304a\u3051\u3070\u3001\u4efb\u610f\u306e\u30c7\u30e5\u30fc\u30c6\u30a3\u30fc\u6bd4\u306e\u6ce2\u5f62\u3092\u4f5c\u6210\u3067\u304d\u308b\u3002<\/p>\n<h2>PB1\u30d4\u30f3\u306b\u6ce2\u5f62\u3092\u51fa\u529b\u3059\u308b<\/h2>\n<p>PB1\u30d4\u30f3\u306fTC0\u306eOC0B\u3067\u3042\u308aTC1\u306eOC1A\u3067\u3082\u3042\u308b\u3002TC0\u30e6\u30cb\u30c3\u30c8\u3092\u4f7f\u3046\u5834\u5408\u3068TC1\u30e6\u30cb\u30c3\u30c8\u3092\u4f7f\u3046\u5834\u5408\u305d\u308c\u305e\u308c\u3092\u8a66\u3057\u3066\u307f\u305f\u3002<\/p>\n<h6>TC0\u3067\u306e\u65b9\u6cd5<\/h6>\n<ul>\n<li>\u4e8b\u524d\u306bPB1\u3092\u51fa\u529b\u65b9\u5411\u306b\u8a2d\u5b9a\u3057\u3066\u304a\u304f\u3002<\/li>\n<li>3\u30d3\u30c3\u30c8\u3042\u308b<strong>\u6ce2\u5f62\u751f\u6210\u30e2\u30fc\u30c9\u30d3\u30c3\u30c8(Waveform Generation Mode bits: WGM02-00<\/strong>)\u3092111B \u3068\u3059\u308b\u3053\u3068\u3067\u3001Fast PWM\u30e2\u30fc\u30c9\u3092\u6307\u5b9a\u3002<em>OCR0A<\/em>\u306e\u3082\u3064\u5024\u304c\u30ab\u30a6\u30f3\u30bf\u306eTOP\u5024\u3068\u306a\u308b\u3002<br \/>\nWGM01\u3068WGM00\u306fTCCR0A\u306b\u3001WGM02\u306fTCCR0B\u306b\u3042\u308b\u3002<\/li>\n<li><strong>\u6bd4\u8f03\u51fa\u529b\u30ec\u30b8\u30b9\u30bfA (<em>OCR0A<\/em>)<\/strong> \u306b\u51fa\u529b\u6ce2\u5f62\u306e\u5468\u671f\u3092\u8a2d\u5b9a\u3002\u30ab\u30a6\u30f3\u30bfTCNT0\u306e\u5024\u304cOCR0A\u306e\u3082\u3064\u5024\u3068\u4e00\u81f4\u3059\u308b\u3068\u3001TCNT0\u306f0\u3068\u306a\u308a\u30ab\u30a6\u30f3\u30c8\u30a2\u30c3\u30d7\u3092\u3084\u308a\u76f4\u3059\u3002\u3064\u307e\u308a\u3001\u30ab\u30a6\u30f3\u30bf\u306e\u5024\u306f0\uff5eOCR0A\u3092\u7e70\u308a\u8fd4\u3059\u3053\u3068\u306b\u306a\u308b\u3002<\/li>\n<li><strong>\u6bd4\u8f03\u51fa\u529b\u30ec\u30b8\u30b9\u30bfB (OCR0B)<\/strong> \u306b\u3001\u6ce2\u5f62\u306eHIGH\u671f\u9593\u3092\u8a2d\u5b9a\u3059\u308b\u3002<\/li>\n<li><em>T<strong>CCR0A<\/strong><\/em><strong> (TC0\u30b3\u30f3\u30c8\u30ed\u30fc\u30eb\u30ec\u30b8\u30b9\u30bfA)<\/strong>\u306e\u3001COM0B1\u30d3\u30c3\u30c8\u30921\uff0cCOM0B0\u30d3\u30c3\u30c8\u30920\u306b\u8a2d\u5b9a\u3002 \u3053\u308c\u306b\u3088\u308a\u3001OC0B\u30d4\u30f3\u306f\u3001<em>TCNT0 == 0<\/em> \u306e\u3068\u304d\u30bb\u30c3\u30c8\u3055\u308c\u3001<em>TCNT0 == OCR0B<\/em> \u306e\u3068\u304d\u30ea\u30bb\u30c3\u30c8\u3055\u308c\u308b\u3002<\/li>\n<li>OC0A\u30d4\u30f3(PB0)\u3092PWM\u51fa\u529b\u3068\u5207\u308a\u96e2\u3059\u305f\u3081\u3001<strong>COM0A1\u30d3\u30c3\u30c8\u3068COM0A0\u30d3\u30c3\u30c8\u306b\u306f0<\/strong>\u3092\u8a2d\u5b9a\u3059\u308b\u3002<\/li>\n<\/ul>\n<p>\u30ea\u30e2\u30b3\u30f3\u7528\u306b38kHz\u306e\u6ce2\u5f62\u3092\u4f5c\u308b\u306e\u3067\u5468\u671f\u306f\u7d0426.3\u03bcsec\u3068\u306a\u308a\u3001\u30c7\u30e5\u30fc\u30c6\u30a3\u30fc1\/3\u306a\u306e\u3067H\u671f\u9593\u306f\u7d048\u03bcsec\u3068\u3044\u3046\u3053\u3068\u306b\u306a\u308b\u3002IrLED\u3092\u99c6\u52d5\u3059\u308b\u3068\u304d\u306b\u306fH\u671f\u9593\u304c\u77ed\u3044\u307b\u3069\u96fb\u529b\u7684\u306b\u306f\u6709\u5229\u306b\u306a\u308b\u3057\u3001\u5927\u304d\u306a\u96fb\u6d41\u3092\u6d41\u305b\u308b\u306e\u3067\u3001\u7fd2\u6163\u7684\u306b6\uff5e7\u03bcsec\u306b\u3057\u3066\u3044\u308b\u3002\u30b7\u30b9\u30c6\u30e0\u30af\u30ed\u30c3\u30af1MHz(1\u5468\u671f\u304c1\u03bcsec) \u306a\u306e\u3067\u3001TC\u30e6\u30cb\u30c3\u30c8\u306e\u30af\u30ed\u30c3\u30af\u306f\u30b7\u30b9\u30c6\u30e0\u30af\u30ed\u30c3\u30af\u305d\u306e\u307e\u307e(\u30d7\u30ea\u30b9\u30b1\u30fc\u30e9 x1) \u3068\u3059\u308b\u3002<\/p>\n<h4>\u203b \u6ce8\u610f\u70b9<\/h4>\n<p>TC0\u30e6\u30cb\u30c3\u30c8\u306fArduino\u306e\u30b3\u30a2\u90e8\u5206\u304c\u5229\u7528\u3057\u3066\u3044\u308b\u3002TC0\u306e\u30d7\u30ea\u30b9\u30b1\u30fc\u30e9\u3084\u30ab\u30a6\u30f3\u30c8\u5024\u306a\u3069\u3092\u5909\u3048\u308b\u5834\u5408\u3001<em>millis()\u3001micros()\u3001delay()<\/em> \u3068\u3044\u3063\u305f\u95a2\u6570\u306f\u4ed5\u69d8\u3069\u304a\u308a\u306b\u306f\u52d5\u304b\u306a\u304f\u306a\u308b\u3002\u30b9\u30b1\u30c3\u30c1\u5185\u3067\u9045\u5ef6\u3092\u304a\u304d\u305f\u3044\u3068\u304d\u306b\u306f\u3001<em>delayMicroseconds()<\/em> \u3060\u3051\u304c\u5229\u7528\u3067\u304d\u308b\u3002<\/p>\n<figure id=\"attachment_7407\" aria-describedby=\"caption-attachment-7407\" style=\"width: 552px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/okiraku-camera.tokyo\/blog\/wp-content\/uploads\/2018\/06\/2916492bc96d3728d5175487ffe44751.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-large wp-image-7407\" src=\"https:\/\/okiraku-camera.tokyo\/blog\/wp-content\/uploads\/2018\/06\/2916492bc96d3728d5175487ffe44751-552x414.jpg\" alt=\"\" width=\"552\" height=\"414\" \/><\/a><figcaption id=\"caption-attachment-7407\" class=\"wp-caption-text\">Arduino ISP + ATtiny<\/figcaption><\/figure>\n<p>\u6ce8\u610f\uff1a\u4ee5\u4e0b\u306e\u30b9\u30b1\u30c3\u30c1\u306f<span style=\"text-decoration: underline;\"><strong>8MHz\u5185\u90e8\u767a\u632f\u3092\u30af\u30ed\u30c3\u30af\u30d7\u30ea\u30b9\u30b1\u30fc\u30e9\u30671\/8 (FUSE\u30ed\u30fc\u30d0\u30a4\u30c8\u306eCLKDIV8 == 1) \u3057\u305f\u30b7\u30b9\u30c6\u30af\u30ed\u30c3\u30af1MHz\u52d5\u4f5c\u306eATTiny\u3092\u7528\u3044\u308b\u524d\u63d0<\/strong><\/span>\u3067\u66f8\u3044\u3066\u3042\u308a\u307e\u3059\u3002\u30af\u30ed\u30c3\u30af\u304c\u9055\u3048\u3070\u3001\u8a2d\u5b9a\u3059\u3079\u304d\u30d1\u30e9\u30e1\u30fc\u30bf\u3082\u5909\u308f\u3063\u3066\u304d\u307e\u3059\u3002<\/p>\n<h6>TC0\u7528\u30b9\u30b1\u30c3\u30c1<\/h6>\n<p>\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u77ed\u3044\u30b9\u30b1\u30c3\u30c1\u3092Arduino IDE\u3067\u30d3\u30eb\u30c9\u3057\u3066ATtiny85\u306b\u66f8\u304d\u8fbc\u307f\u3001USB\u30ed\u30b8\u30a2\u30ca(ZEROPLUS Logic Cube) \u3092\u4f7f\u3063\u3066\u6ce2\u5f62\u3092\u8abf\u3079\u3066\u307f\u305f\u3002\u96fb\u6e90\u306fUSB\u304b\u3089\u306e+5V\u5f31\u3001ATtiny\u81ea\u4f53\u306f\u524d\u306b\u8f09\u305b\u305fArduino PRO MINI\u306eISP\u30dc\u30fc\u30c9\u306b\u8f09\u305b\u305f\u307e\u307e\u3067\u52d5\u304b\u3057\u305f\u3002\u306a\u304a\u3001<span style=\"text-decoration: underline;\">PB4\u306e\u7acb\u4e0a\u308a\u3092\u30c8\u30ea\u30ac<\/span>\u3068\u3057\u3066\u5229\u7528\u3057\u3066\u3044\u308b\u3002<\/p>\n<pre class=\"lang:c++ decode:true\" title=\"TC0 PB1(OC0B)\">#include &lt;avr\/wdt.h&gt;\r\n#define OUTPUT_PIN  (_BV(4) | _BV(1))\r\nvoid pwm_out() {\r\n  PORTB |= _BV(4);\r\n  OCR0A = 25;  \/\/ TOP value :  38kHz --&gt; 26.3us.\r\n  OCR0B = 6;  \/\/  H period  : 6.4us.\r\n  TCCR0A = B00100011; \/\/ COM0A: 00, COM0B: 10, WGM01-00: 11\r\n  TCCR0B = B00001001; \/\/ FOC:00, WGM02:1, CS02-01: 001 (system clock x1)\r\n  TCNT0 = OCR0A;\r\n  delayMicroseconds(560);\r\n  TCCR0A = 0;\r\n  TCCR0B = 0;\r\n  PORTB &amp;= ~_BV(4);\r\n}\r\n\r\nvoid setup() {\r\n  cli();\r\n  DDRB = OUTPUT_PIN; \/\/ input\u306f0\r\n  PORTB = 0;  \/\/ \u4ed6\u306f0\r\n  ACSR |= 0x80;    \/\/ \u30a2\u30ca\u30ed\u30b0\u30b3\u30f3\u30d1\u30ec\u30fc\u30bf\u7981\u6b62\r\n  ADCSRA &amp;= 0x7f;  \/\/ disable ADC\r\n  wdt_disable();\r\n  TIMSK = 0;  \/\/ disable Timer0\/1 overflow interrupt.\r\n  sei();\r\n  for(;;) {\r\n    pwm_out();  \r\n    delayMicroseconds(560);\r\n  }\r\n}\r\nvoid loop() {}\r\n<\/pre>\n<h4>void setup()<\/h4>\n<p>\u30dd\u30fc\u30c8\u30d4\u30f3\u306e\u521d\u671f\u5316\u3068\u7701\u96fb\u529b\u5316\u306e\u305f\u3081\u306e\u5b9a\u756a\u306e\u8a2d\u5b9a\u3092\u884c\u3044\u3001\u30bf\u30a4\u30de\u30fc0\u306e\u30aa\u30fc\u30d0\u30fc\u30d5\u30ed\u30fc\u5272\u8fbc\u307f\u306f\u4e0d\u8981\u306a\u306e\u3067\u7981\u6b62\u3057\u3066\u3044\u308b\u3002\u30bf\u30a4\u30de\u30fc0\u306e\u5272\u8fbc\u307f\u306f\u3001Arduino \u306e\u30b3\u30a2\u90e8\u5206\u306b\u3042\u308a setup()\u306e\u76f4\u524d\u306b\u547c\u3070\u308c\u308b\u00a0<em>init();<\/em> \u3067\u8a31\u53ef\u3055\u308c\u3066\u3044\u308b\u3002<\/p>\n<h4>void pwm_out()<\/h4>\n<p>\u5148\u306b\u66f8\u3044\u305f\u3088\u3046\u306a\u3053\u3068\u3092TC0\u306e\u5404\u30ec\u30b8\u30b9\u30bf\u306b\u5bfe\u3057\u3066\u5b9f\u65bd\u3057\u3001\u8d64\u5916\u7dda\u30ea\u30e2\u30b3\u30f3\u306eNEC\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u3092\u610f\u8b58\u3057\u3066 560\u03bcsec\u306e\u9045\u5ef6\u3092\u7f6e\u3044\u305f\u3002\u3053\u306e\u9045\u5ef6\u306e\u3042\u3068\u3001TCCR0A\/B\u30920\u3068\u3057\u3066\u6ce2\u5f62\u51fa\u529b\u3092\u505c\u6b62\u3057\u3066\u3044\u308b\u3002<\/p>\n<p>TOP\u5024\u3068\u3057\u3066 OCR0A = 25; \u3068\u3057\u3066\u3044\u308b\u306e\u306f\u30011\u5468\u671f\u3092\u7d0426\u03bcsec\u3068\u3059\u308b\u305f\u3081\u3067\u30010\u306e\u3068\u304d1\u30af\u30ed\u30c3\u30af\u30011\u306e\u3068\u304d1\u30af\u30ed\u30c3\u30af\u2026 25\u306e\u3068\u304d1\u30af\u30ed\u30c3\u30af\u306726\u03bcsec\u306b\u306a\u308b\u304b\u3089\u3002<\/p>\n<p><strong><em>TCNT0 = OCR0A;<\/em> <\/strong>\u3068\u3059\u308b\u3053\u3068\u3067\u3001\u6b21\u306e\u30af\u30ed\u30c3\u30af\u3067\u30ab\u30a6\u30f3\u30bf\u3068TOP\u5024\u306e\u4e00\u81f4\u304c\u8a8d\u8b58\u3055\u308c\u30ab\u30a6\u30f3\u30bf\u304c0\u306b\u623b\u308b(\u3068\u601d\u3046)\u3002\u30ab\u30a6\u30f3\u30bf\u304c0\u306b\u306a\u3063\u305f\u6642\u70b9\u3067\u3001OCR0B\u306e\u5024\u304c\u6bd4\u8f03\u306e\u305f\u3081\u306e\u5185\u90e8\u30ec\u30b8\u30b9\u30bf\u306b\u8ee2\u9001\u3055\u308c\u3001\u610f\u56f3\u3057\u305f\u5024\u3067\u306e\u6bd4\u8f03\u52d5\u4f5c\u304c\u884c\u308f\u308c\u308b\u3088\u3046\u306b\u306a\u308b\u306f\u305a\u3002<br \/>\nTC0\u306ePWM\u30e2\u30fc\u30c9\u3067\u306f\u3001\u6bd4\u8f03\u51fa\u529b\u30ec\u30b8\u30b9\u30bf\u306f\u30d7\u30ed\u30b0\u30e9\u30e0\u304b\u3089\u306e\u30a2\u30af\u30bb\u30b9\u7528\u306e\u30ec\u30b8\u30b9\u30bf\u3068\u3001TCNT0\u3068\u306e\u6bd4\u8f03\u306b\u4f7f\u308f\u308c\u308b\u30ec\u30b8\u30b9\u30bf\u3068\u306b\u4e8c\u91cd\u5316\u3055\u308c\u3066\u3044\u308b\u3002\u6ce2\u5f62\u751f\u6210\u30e2\u30fc\u30c9\u30d3\u30c3\u30c8\u306b\u5fdc\u3058\u3066\u3001TOP\u307e\u305f\u306f0\u306e\u3068\u304d\u3001\u30d7\u30ed\u30b0\u30e9\u30e0\u304b\u3089\u8a2d\u5b9a\u3057\u305f\u5024\u304c\u5185\u90e8\u30ec\u30b8\u30b9\u30bf\u306b\u8ee2\u9001\u3055\u308c\u308b\u3088\u3046\u3067\u3042\u308b\u3002<\/p>\n<h6>TC0\u3067\u306e\u5b9f\u884c\u7d50\u679c<\/h6>\n<p>\u30ed\u30b8\u30a2\u30ca\u3067\u89b3\u6e2c\u3057\u305f\u7d50\u679c\u306f\u4ee5\u4e0b\u306e\u3068\u304a\u308a(1MHz\u30b5\u30f3\u30d7\u30ea\u30f3\u30b0)\u3002<\/p>\n<figure id=\"attachment_7503\" aria-describedby=\"caption-attachment-7503\" style=\"width: 552px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/okiraku-camera.tokyo\/blog\/wp-content\/uploads\/2018\/06\/cut_TC0_PB1-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-large wp-image-7503\" src=\"https:\/\/okiraku-camera.tokyo\/blog\/wp-content\/uploads\/2018\/06\/cut_TC0_PB1-1-552x162.png\" alt=\"\" width=\"552\" height=\"162\" \/><\/a><figcaption id=\"caption-attachment-7503\" class=\"wp-caption-text\">TC0\u3092\u4f7f\u3063\u305fPB1\u51fa\u529b<\/figcaption><\/figure>\n<p>\u610f\u56f3\u901a\u308a\u306e\u6ce2\u5f62\u304c\u3067\u304d\u3066\u3044\u308b\u3002\u7d0426\u03bcsec\u5468\u671f\u3067\u7d047\u03bcsec\u5e45\u306eH\u671f\u9593\u3092\u3082\u3064\u6ce2\u5f62\u3068\u306a\u3063\u305f\u3002\u6c34\u8272\u306e\u30c8\u30ea\u30ac\u4fe1\u53f7\u304cHIGH\u306e\u671f\u9593\u306b21\u5468\u671f\u5206\u51fa\u529b\u3057\u3066\u3044\u308b\u306e\u3067\u8d64\u5916\u7dda\u30ea\u30e2\u30b3\u30f3\u306e\u30aa\u30f3\u671f\u9593\u3068\u3057\u3066\u4f7f\u3048\u308b\u3060\u308d\u3046\u3002<\/p>\n<p>9\u884c\u76ee\u3092\u3001<strong><em>TCNT0 = OCR0A;\u00a0<\/em><\/strong>\u3067\u306f\u306a\u304f\u3001<strong><em>TCNT = 0;<\/em> <\/strong>\u3068\u3057\u305f\u5834\u5408\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u308b\u3002<\/p>\n<figure id=\"attachment_7504\" aria-describedby=\"caption-attachment-7504\" style=\"width: 552px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/okiraku-camera.tokyo\/blog\/wp-content\/uploads\/2018\/06\/cut_TC0_PB1-2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-large wp-image-7504\" src=\"https:\/\/okiraku-camera.tokyo\/blog\/wp-content\/uploads\/2018\/06\/cut_TC0_PB1-2-552x160.png\" alt=\"\" width=\"552\" height=\"160\" \/><\/a><figcaption id=\"caption-attachment-7504\" class=\"wp-caption-text\">TC0\u3092\u4f7f\u3063\u305fPB1\u51fa\u529b (\u30ab\u30a6\u30f3\u30c80\u304b\u3089\u958b\u59cb\u6642)<\/figcaption><\/figure>\n<p>\u30c8\u30ea\u30ac\u4fe1\u53f7\u306e\u7acb\u4e0a\u308a\u6642\u70b9\u304b\u3089\u3001\u7d0426\u03bcsec\u5f8c\u306b\u6700\u521d\u306eH\u30d1\u30eb\u30b9\u304c\u51fa\u3066\u304a\u308a\u3001\u51fa\u529b\u306f20\u5468\u671f\u5206\u3068\u306a\u3063\u3066\u3044\u308b\u3002\u3053\u308c\u306f\u3001TCNT0\u304cTOP( = 25 )\u306b\u9054\u3057\u305f\u3042\u3068\u3067OCR0B\u306e\u6307\u5b9a\u304c\u6709\u52b9\u306b\u306a\u3063\u305f\u3053\u3068\u306b\u3088\u308b\u3002\u3082\u3063\u3068\u3082\u3001\u3053\u308c\u3067\u3082\u30ea\u30e2\u30b3\u30f3\u3068\u3057\u3066\u306f\u6a5f\u80fd\u3059\u308b\u306e\u3060\u304c\u3002<\/p>\n<p>pwm_out() \u5185\u3067<em>delayMicroseconds(560);<\/em> \u3068\u3057\u3066\u3044\u308b\u304c\u3001\u30c8\u30ea\u30ac\u4fe1\u53f7\u306e\u89b3\u6e2c\u3055\u308c\u305fHIGH\u671f\u9593\u304c\u3061\u3087\u3063\u3068\u77ed\u3044\u306e\u304c\u6c17\u306b\u306a\u308b\u3068\u3053\u308d\u3002\u6570\u30d1\u30fc\u30bb\u30f3\u30c8\u306e\u76f8\u9055\u306a\u306e\u3067\u3001\u5185\u8535RC\u30aa\u30b7\u30ec\u30fc\u30bf\u306e\u8a31\u5bb9\u7bc4\u56f2\u5185\u304b\u3082\u3057\u308c\u306a\u3044\u304c\u3002<\/p>\n<p>TC0\u3067\u306e\u3084\u308a\u65b9\u306f\u3001Arduino PRO MINI\u306a\u3069\u3067\u4f7f\u308f\u308c\u3066\u3044\u308bATmega328p\u3067\u8d64\u5916\u7dda\u30ea\u30e2\u30b3\u30f3\u7528\u306e\u6ce2\u5f62\u3092\u51fa\u529b\u3059\u308b\u3068\u304d\u3068\u3088\u304f\u4f3c\u3066\u304a\u308a\u3001\u307b\u307c\u540c\u3058\u3084\u308a\u65b9\u3092\u8e0f\u8972\u3067\u304d\u308b\u3068\u601d\u3046\u3002<\/p>\n<h6>TC1\u3067\u306e\u65b9\u6cd5<\/h6>\n<p>TC0\u3092\u89e6\u308a\u305f\u304f\u306a\u3044(Arduino\u672c\u6765\u306e\u4f7f\u3044\u65b9\u306e\u307e\u307e\u306b\u3057\u305f\u3044)\u3088\u3046\u306a\u3068\u304d\u306fTC1\u30e6\u30cb\u30c3\u30c8\u3092\u4f7f\u3063\u3066\u51fa\u529b\u3059\u308b\u3053\u3068\u306b\u306a\u308b\u304c\u3001TC0\u3068\u306f\u82e5\u5e72\u69cb\u6210\u3084\u6ce2\u5f62\u306e\u4f5c\u308a\u65b9\u304c\u9055\u3063\u3066\u3044\u308b\u3002<br \/>\n\u30c7\u30fc\u30bf\u30b7\u30fc\u30c8\u306b\u3088\u308c\u3070\u3001\u975e\u540c\u671f\u30e2\u30fc\u30c9\u3067\u306f\u5185\u8535\u306ePLL\u30aa\u30b7\u30ec\u30fc\u30bf\u306b\u3088\u308b\u6700\u592764MHz\u306e\u30bd\u30fc\u30b9\u30af\u30ed\u30c3\u30af\u309214\u30d3\u30c3\u30c8\u5206\u89e3\u80fd\u306e\u30d7\u30ea\u30b9\u30b1\u30fc\u30e9\u3067\u5206\u5468\u3059\u308b\u3053\u3068\u3067\u3001\u6b63\u78ba\u304b\u3064\u9ad8\u901f\u306aPWM\u304c\u5b9f\u73fe\u3067\u304d\u308b\u3068\u306e\u3053\u3068\u3060\u304c\u3001\u3053\u3053\u3067\u306f\u30b7\u30b9\u30c6\u30e0\u30af\u30ed\u30c3\u30af(1MHz)\u3092\u30bd\u30fc\u30b9\u3068\u3057\u3066\u7528\u3044\u308b\u540c\u671f\u30e2\u30fc\u30c9\u3092\u7528\u3044\u3066\u3044\u308b\u3002<\/p>\n<ul>\n<li>\u6bd4\u8f03\u51fa\u529b\u30ec\u30b8\u30b9\u30bf\u304c3\u672c(<em>OCR1A\u3001OCR1B\u3001 OCR1C<\/em>)\u3002<\/li>\n<li><span style=\"text-decoration: underline;\">\u30ab\u30a6\u30f3\u30bf\u306eTOP\u5024\u306e\u6307\u5b9a\u306fOCR1C<\/span>\u3067\u884c\u3046\u3002<strong>TCCR1(TC1\u30b3\u30f3\u30c8\u30ed\u30fc\u30eb\u30ec\u30b8\u30b9\u30bf)<\/strong>\u5185\u306e<strong>CTC\u30d3\u30c3\u30c8<\/strong>\u306b\u3088\u308a\u3001TCNT1 == OCR1C\u306e\u3068\u304d\u306e\u6319\u52d5(TCNT1\u30920\u3068\u3059\u308b\u304b\u3001\u4f55\u3082\u3057\u306a\u3044\u304b)\u3092\u6c7a\u3081\u308b\u3002OCR1C\u3092TOP\u5024\u3068\u3057\u3066\u4f7f\u3046\u306e\u3067&#8221;1&#8243;\u3092\u8a2d\u5b9a\u3002<\/li>\n<li>OCR1A\u307e\u305f\u306fOCR1B\u306e\u5024\u304cTCNT1\u3068\u4e00\u81f4\u3059\u308b\u3068\u3001\u5bfe\u5fdc\u3059\u308b\u6bd4\u8f03\u51fa\u529b\u30d4\u30f3(OC1A\u3001OC1B)\u304c\u30bb\u30c3\u30c8\u307e\u305f\u306f\u30ea\u30bb\u30c3\u30c8\u3055\u308c\u308b\u3002<br \/>\n\u30bb\u30c3\u30c8\u306b\u3059\u308b\u304b\u30ea\u30bb\u30c3\u30c8\u306b\u3059\u308b\u304b\u306f\u3001TCCR1\u306e<strong>COM1A1\u30d3\u30c3\u30c8\u3068COM1A0\u30d3\u30c3\u30c8<\/strong>\u3001\u304a\u3088\u3073\u3001<strong>GTCCR (\u6c4e\u7528TC\u30b3\u30f3\u30c8\u30ed\u30fc\u30eb\u30ec\u30b8\u30b9\u30bf )<\/strong> \u5185\u306e<strong>COM1B1\u30d3\u30c3\u30c8\u3068COM1B0\u30d3\u30c3\u30c8<\/strong>\u306b\u8a2d\u5b9a\u3059\u308b\u5024\u3067\u6c7a\u307e\u308b\u3002<\/li>\n<li>A\u5074\u3067PWM\u3092\u4f7f\u3046\u3068\u304d\u306fTCCR1\u306e<strong>PWM1A\u30d3\u30c3\u30c8<\/strong>\u3092&#8221;1&#8243;\u306b\u3001B\u5074\u3067\u306f\u3001GTCCR\u306e<strong>PWM1B\u30d3\u30c3\u30c8<\/strong>\u3092&#8221;1&#8243;\u306b\u3059\u308b\u3002<\/li>\n<li>\u6bd4\u8f03\u51fa\u529b\u30d4\u30f3\u306f2\u7cfb\u7d71(OC1A\u3068OC1B)\u3060\u304c\u3001\u305d\u308c\u305e\u308c\u53cd\u8ee2\u51fa\u529b\u7528\u306e\u30d4\u30f3\u3082\u3042\u308b\u3002\u305f\u3060\u3057\u3001COM1A1\u307e\u305f\u306fCOM1B1\u3092&#8221;1&#8243;\u3068\u3057\u305f\u5834\u5408\u3001\u5bfe\u5fdc\u3059\u308b\u53cd\u8ee2\u51fa\u529b\u30d4\u30f3\u306fPWM\u6a5f\u80fd\u304b\u3089\u5207\u308a\u96e2\u3055\u308c\u3001\u4ed6\u306e\u7528\u9014\u3067\u5229\u7528\u53ef\u80fd\u3068\u306a\u308b\u3002<\/li>\n<li>\u30d7\u30ed\u30b0\u30e9\u30e0\u304b\u3089\u306eOCR1n\u3084TCCR1\u3078\u306e\u66f8\u304d\u8fbc\u307f\u306f\u3001\u5373\u5ea7(2\u30af\u30ed\u30c3\u30af\u4ee5\u5185)\u306b\u6bd4\u8f03\u3084\u8a2d\u5b9a\u7528\u306e\u5185\u90e8\u30ec\u30b8\u30b9\u30bf\u306b\u53cd\u6620\u3055\u308c\u308b\u3002<\/li>\n<\/ul>\n<h6>TC1\u7528\u30b9\u30b1\u30c3\u30c1\u3068\u5b9f\u884c\u7d50\u679c<\/h6>\n<p>\u5148\u306eTC0\u7528\u3068\u306e\u76f8\u9055\u306fpwm_out(); \u5185\u3060\u3051\u306b\u306a\u308b\u3002<\/p>\n<pre class=\"lang:default decode:true\">void pwm_out() {\r\n  PORTB |= _BV(4);\r\n  OCR1C = 25;  \/\/ TOP value :  38kHz --&gt; 26.3us.\r\n  OCR1A = 6;  \/\/  H period  : 6.4us.\r\n  TCCR1 = B11010001; \/\/ CTC=1, PWM1A=1, COM1A[1-0] = 01, CS13-10: 0001 (x1)\r\n  GTCCR = 0;\r\n  TCNT1 = 0;\r\n  delayMicroseconds(560);\r\n  TCCR1 = 0;\r\n  GTCCR = 0;\r\n  PORTB &amp;= ~_BV(4);\r\n}<\/pre>\n<p>TCCR1\u306eCOM1A1\u30920, COM1A0\u30921\u3068\u3059\u308b\u3053\u3068\u3067\u3001TCNT1 == 0\u306e\u3068\u304dOC1A\u304c\u30bb\u30c3\u30c8\u3055\u308c\u3001TCNT1 == OCR1A\u306e\u3068\u304d\u30ea\u30bb\u30c3\u30c8\u3055\u308c\u308b\u3002<br \/>\n\u30ed\u30b8\u30a2\u30ca\u3067\u306e\u89b3\u6e2c\u7d50\u679c\u306f\u4ee5\u4e0b\u306e\u3068\u304a\u308a\u3002<\/p>\n<figure id=\"attachment_7506\" aria-describedby=\"caption-attachment-7506\" style=\"width: 552px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/okiraku-camera.tokyo\/blog\/wp-content\/uploads\/2018\/06\/cut_TC1_PB1-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-large wp-image-7506\" src=\"https:\/\/okiraku-camera.tokyo\/blog\/wp-content\/uploads\/2018\/06\/cut_TC1_PB1-1-552x161.png\" alt=\"\" width=\"552\" height=\"161\" \/><\/a><figcaption id=\"caption-attachment-7506\" class=\"wp-caption-text\">TC1\u3092\u4f7f\u3063\u305fPB1\u51fa\u529b<\/figcaption><\/figure>\n<p>TC0\u30e6\u30cb\u30c3\u30c8\u3068\u9055\u3063\u3066OCR1A\u304c\u5373\u6642\u53cd\u6620\u3055\u308c\u3066\u3044\u308b\u306e\u3067\u3001TCNT1 = 0\u304b\u3089\u958b\u59cb\u3057\u3066\u3082\u3059\u3050\u306bH\u30d1\u30eb\u30b9\u304c\u51fa\u3066\u3044\u308b\u3002<\/p>\n<p>\u3068\u601d\u3063\u3066\u3044\u305f\u3089\u3001\u30c7\u30fc\u30bf\u30b7\u30fc\u30c8\u306bTC1\u306ePWM\u30e2\u30fc\u30c9\u3067OCR1A\/B\u306e\u5024\u304c\u78ba\u5b9a\u3059\u308b\u306e\u306fTCNT1\u306e\u5024\u304cOCR1C\u306e\u5024\u3068\u4e00\u81f4\u3057\u305f\u3068\u304d\u3068\u66f8\u3044\u3066\u3042\u3063\u305f\u3002\u6ce2\u5f62\u3092\u898b\u308b\u3068\u3001TCNT1 = 0 \u304b\u3089\u958b\u59cb\u3057\u3066\u3082OCR1B\u306f\u53cd\u6620\u3055\u308c\u3066\u3044\u308b\u3088\u3046\u306b\u601d\u3048\u308b\u306e\u3060\u304c\u3002\u4f55\u304b\u8aa4\u8aad\u304c\u3042\u308b\u306e\u304b\u3082\u3057\u308c\u306a\u3044\u3002<\/p>\n<h2>TC0\u3068TC1\u306ePWM\u6ce2\u5f62\u306e\u76f8\u9055<\/h2>\n<p>TOP\u5024\u3084HIGH\u671f\u9593\u306e\u5e45\u306f\u540c\u3058\u3088\u3046\u306b\u6307\u5b9a\u3057\u305f\u306e\u306b\u3001TC0\u306e\u6ce2\u5f62\u3068TC1\u306e\u6ce2\u5f62\u3092\u3088\u304f\u898b\u308b\u3068\u3001TC1\u306e\u65b9\u304cHIGH\u671f\u9593\u306e\u5e45\u304c1\u03bcsec\u77ed\u3044\u3002\u6c17\u306b\u306a\u3063\u305f\u306e\u3067\u3001TC0\u306fPB1(OC0B)\u306b\u3001TC1\u306fPB4(OC1B)\u306b\u540c\u6642\u306b\u51fa\u529b\u3055\u305b\u3001\u30c8\u30ea\u30ac\u4fe1\u53f7\u306fPB3\u304b\u3089\u51fa\u3059\u3088\u3046\u306b\u3057\u3066\u6ce2\u5f62\u3092\u89b3\u6e2c\u3057\u3066\u307f\u305f\u3002<\/p>\n<figure id=\"attachment_7512\" aria-describedby=\"caption-attachment-7512\" style=\"width: 552px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/okiraku-camera.tokyo\/blog\/wp-content\/uploads\/2018\/06\/TC01-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-large wp-image-7512\" src=\"https:\/\/okiraku-camera.tokyo\/blog\/wp-content\/uploads\/2018\/06\/TC01-1-552x161.png\" alt=\"\" width=\"552\" height=\"161\" \/><\/a><figcaption id=\"caption-attachment-7512\" class=\"wp-caption-text\">TC0\u304b\u3089PB1(\u30aa\u30ec\u30f3\u30b8)\u3001TC1\u304b\u3089PB4(\u6c34\u8272)<\/figcaption><\/figure>\n<p>2\u3064\u306e\u6ce2\u5f62\u3092\u6bd4\u3079\u3066\u307f\u308b\u3068\u5468\u671f\u306f\u4e00\u81f4\u3057\u3066\u3044\u308b\u304c\u3001TC1\u304b\u3089\u51fa\u529b\u3057\u305f\u6c34\u8272\u306e\u6ce2\u5f62\u306fHIGH\u671f\u9593\u304c1\u03bcsec\u77ed\u3044\u3053\u3068\u304c\u5206\u304b\u308b\u3002<\/p>\n<p>\u30b9\u30b1\u30c3\u30c1\u306f\u3001TC1\u306e\u51fa\u529b\u5148\u3092OC1B\u3068\u3059\u308b\u305f\u3081\u306e\u5909\u66f4\u3092\u5165\u308c\u3001\u307b\u307c\u540c\u6642\u306b\u6ce2\u5f62\u3092\u51fa\u3059\u305f\u3081\u306e\u5c0f\u7d30\u5de5\u3092\u5165\u308c\u305f\u304c\u3001\u3042\u3068\u306f\u307b\u3068\u3093\u3069\u540c\u3058\u3067\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u3063\u305f\u3002<\/p>\n<pre class=\"lang:default decode:true \">void pwm_out() {\r\n \/\/ TC0 PB1 (OC0B) and TC1 PB4\r\n  DDRB = _BV(4) | _BV(1) | _BV(3);\r\n  PORTB |= _BV(3);\r\n\r\n  OCR0A = OCR1C = 25;  \/\/ TOP value :  38kHz --&gt; 26.3us.\r\n  OCR0B = OCR1B = 6;  \/\/  H period  : 6.4us.\r\n  TCCR0A = B00100011; \/\/ COM0A: 00, COM0B: 10, WGM01-00: 11\r\n  TCCR0B = B00001000; \/\/ FOC:00, WGM02:1, CS02-01: 000 (stop clock)\r\n  GTCCR = B01100000; \/\/ OC1B cleared on compare match. Set when TCNT1 = $00.\r\n  TCCR1 = B10000001; \/\/ CTC=1. clear TCNT1 on OCR1C==TCNT1. CS13-10 = 0001B (x1)\r\n  TCNT1 = 0;\r\n  TCCR0B |= 1;  \/\/ enable clock (x1).\r\n  TCNT0 = OCR0A ;\r\n  delayMicroseconds(560);\r\n  TCCR0A = 0;\r\n  TCCR0B = 0;\r\n  TCCR1 = 0;\r\n  GTCCR = 0;\r\n  PORTB &amp;= ~_BV(3);\r\n}<\/pre>\n<p>\u89b3\u6e2c\u6ce2\u5f62\u304b\u3089\u5206\u304b\u308b\u3088\u3046\u306b\u5468\u671f\u306f\u4e00\u81f4\u3057\u3066\u3044\u308b\u304b\u3089\u3001\u30ab\u30a6\u30f3\u30bf(TCNT0\/1) \u306f\u540c\u3058\u3088\u3046\u306b\u632f\u52d5\u3057\u3066\u3044\u308b\u3068\u601d\u308f\u308c\u308b\u3002\u6ce2\u5f62\u3092\u51fa\u529b\u3059\u308b\u969b\u306e\u3001OCR1B\u3068OCR1C\u306e\u6bd4\u8f03\u306e\u30bf\u30a4\u30df\u30f3\u30b0\u3001\u3042\u308b\u3044\u306f\u3001\u6bd4\u8f03\u5f8c\u306e\u51fa\u529b\u30ea\u30bb\u30c3\u30c8\u306e\u30bf\u30a4\u30df\u30f3\u30b0\u304c\u9055\u3046\u306e\u3060\u308d\u3046\u304b\u3002<\/p>\n<p>\u30c7\u30fc\u30bf\u30b7\u30fc\u30c8\u3092\u8aad\u3093\u3067\u3082\u76f8\u9055\u306e\u7406\u7531\u306f\u3088\u304f\u5206\u304b\u3089\u306a\u304b\u3063\u305f\u3002TC0\u30e6\u30cb\u30c3\u30c8\u3067\u306f\u671f\u5f85\u3059\u308bHIGH\u671f\u9593\u3092-1\u3057\u305f\u5024\u3092\u30bb\u30c3\u30c8\u3059\u308b\u304c\u3001TC1\u3067\u306f\u305d\u306e\u307e\u307e(7\u03bcsec\u306a\u30897)\u6307\u5b9a\u3059\u308b\u3001\u3068\u899a\u3048\u3066\u304a\u304f\u3057\u304b\u306a\u3055\u305d\u3046\u3002\u4e0a\u8a18\u30b9\u30b1\u30c3\u30c1\u306e7\u884c\u76ee\u3092\u3001<\/p>\n<pre class=\"lang:default decode:true\">\/\/  OCR0B = OCR1B = 6;  \/\/  H period  : 6.4us.\r\n  OCR0B = 6;\r\n  OCR1B = 7;<\/pre>\n<p>\u3068\u3059\u308b\u3068\u3001\u540c\u3058HIGH\u671f\u9593\u3092\u3082\u3064\u6ce2\u5f62\u304c\u751f\u6210\u3055\u308c\u308b\u3053\u3068\u306f\u78ba\u8a8d\u3057\u305f\u3002<\/p>\n<h2>\u304d\u3087\u3046\u306e\u307e\u3068\u3081<\/h2>\n<p>ATtiny85\u304b\u3089\u8d64\u5916\u7dda\u30ea\u30e2\u30b3\u30f3\u7528\u6ce2\u5f62\u3092\u51fa\u529b\u3059\u308b\u969b\u306f\u3001PB1(OC0B\u3042\u308b\u3044\u306fOC1A)\u307e\u305f\u306fPB4(OC1B)\u3092\u4f7f\u3046\u3053\u3068\u306b\u306a\u308a\u305d\u3046\u3002\u540c\u6642\u306bA\/D\u30b3\u30f3\u30d0\u30fc\u30bf\u3082\u4f7f\u3046\u306a\u3089\u3001PB1\u304b\u3089\u51fa\u3059\u3053\u3068\u306b\u306a\u308b\u3060\u308d\u3046\u3002<\/p>\n<p>PWM\u51fa\u529b\u7528\u4ee5\u5916\u306b\u30dd\u30fc\u30c8\u30d4\u30f3\u3092\u3042\u30684\u672c\u4f7f\u3048\u308b\u306e\u3067\u3001\u30b9\u30a4\u30c3\u30c14\u3064\u306e\u30ea\u30e2\u30b3\u30f3\u306e\u4f5c\u6210\u306f\u7c21\u5358\u3060\u308d\u3046\u3002<\/p>\n<p>\u8ab0\u3067\u3082\u77e5\u3063\u3066\u308b\u8a71\u306b\u6642\u9593\u304b\u3051\u3066\u3069\u3046\u3059\u308b\u7684\u306a\u5370\u8c61\u3082\u3042\u308b\u306e\u3060\u3051\u3069\u3001\u3053\u308c\u3082\u904a\u3073\u306e\u3046\u3061\u3068\u3044\u3046\u3053\u3068\u3067\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6982\u8981 ATtiny5\u30b7\u30ea\u30fc\u30ba(ATtiny85\/45\/25)\u306e\u3082\u3064PWM\u6a5f\u80fd\u3092\u4f7f\u3063\u3066\u3001\u5bb6\u96fb\u7528\u306e\u8d64\u5916\u7dda\u30ea\u30e2\u30b3\u30f3\u306e\u305f\u3081\u306e\u6ce2\u5f62(38kHz\u3001\u30c7\u30e5\u30fc\u30c6\u30a31\/3)\u3092\u4f5c\u3063\u3066\u307f\u308b\u3002Arduino\u3067\u4f7f\u308f\u308c\u3066\u3044\u308bATmega8\u30b7\u30ea\u30fc\u30ba\u3067\u306f &hellip; <a href=\"https:\/\/okiraku-camera.tokyo\/blog\/?p=7480\" class=\"more-link\">\u7d9a\u304d\u3092\u8aad\u3080 <span class=\"screen-reader-text\">ATtiny85\u3067\u8d64\u5916\u7dda\u30ea\u30e2\u30b3\u30f3\u7528\u306e\u6ce2\u5f62\u3092\u4f5c\u308b\u8a71<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":7380,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[69],"tags":[65,95,86],"class_list":["post-7480","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-programming","tag-arduino","tag-attiny","tag-remocon"],"_links":{"self":[{"href":"https:\/\/okiraku-camera.tokyo\/blog\/index.php?rest_route=\/wp\/v2\/posts\/7480","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/okiraku-camera.tokyo\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/okiraku-camera.tokyo\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/okiraku-camera.tokyo\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/okiraku-camera.tokyo\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7480"}],"version-history":[{"count":0,"href":"https:\/\/okiraku-camera.tokyo\/blog\/index.php?rest_route=\/wp\/v2\/posts\/7480\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/okiraku-camera.tokyo\/blog\/index.php?rest_route=\/wp\/v2\/media\/7380"}],"wp:attachment":[{"href":"https:\/\/okiraku-camera.tokyo\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7480"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/okiraku-camera.tokyo\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7480"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/okiraku-camera.tokyo\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7480"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}