{"id":270,"date":"2014-08-15T17:53:52","date_gmt":"2014-08-15T08:53:52","guid":{"rendered":"http:\/\/goji2100.s199.coreserver.jp\/blog\/?p=270"},"modified":"2022-04-11T06:40:40","modified_gmt":"2022-04-10T21:40:40","slug":"mbed-nxp-lpc1768%ef%bc%8b%e2%98%86board-orange%e3%81%a7-wav%e3%83%95%e3%82%a1%e3%82%a4%e3%83%ab%e3%81%ae%e5%86%8d%e7%94%9f","status":"publish","type":"post","link":"https:\/\/goji2100.com\/blog\/?p=270","title":{"rendered":"mbed NXP LPC1768\uff0b\u2606board Orange\u3067.WAV\u30d5\u30a1\u30a4\u30eb\u306e\u518d\u751f"},"content":{"rendered":"<p>\u300c<a title=\"Arduino UNO\/Mega 2560 .WAV\u30d5\u30a1\u30a4\u30eb\u306e\u518d\u751f\" href=\"https:\/\/goji2100.com\/blog\/?p=210\" target=\"_blank\" rel=\"noopener\">Arduino UNO\/Mega 2560 .WAV\u30d5\u30a1\u30a4\u30eb\u306e\u518d\u751f<\/a>\u300d\u3067\u306f\u3001\u975e\u529b\u306aCPU\u3067\u300c16000Hz\/8bit\/Mono\u300d\u5f62\u5f0f\u306e.WAV\u30d5\u30a1\u30a4\u30eb\u3092\u518d\u751f\u3057\u3066\u307f\u307e\u3057\u305f\u3002<br \/>\n\u4eca\u56de\u306f\u3001mbed NXP LPC1768\u3067\u300c44100Hz\/16bit\/Stereo\u300d\u5f62\u5f0f\u306e.WAV\u30d5\u30a1\u30a4\u30eb\u306e\u518d\u751f\u3092\u8a66\u884c\u3057\u307e\u3059\u3002<\/p>\n<p>\u300c44100Hz\/16bit\/Stereo\u300d\u5f62\u5f0f\u306b\u306a\u308b\u3068\u5358\u7d14\u8a08\u7b97\u306744,100*2*2=176,400(Byte\/s)\u306e\u8ee2\u9001\u80fd\u529b\u304c\u5fc5\u8981\u306b\u306a\u308a\u307e\u3059\u3002<br \/>\n\u6700\u521d\u306e\u30cd\u30c3\u30af\u306fSD\u304b\u3089\u306e.WAV\u30d5\u30a1\u30a4\u30eb\u306e\u8aad\u307f\u51fa\u3057\u901f\u5ea6\u3067\u3059\u304c\u3001SDFileSystem\u306e\u30c7\u30d5\u30a9\u30eb\u30c8\u3067\u306f\u3001SPI\u306e\u30af\u30ed\u30c3\u30af\u306f1MHz\u306b\u8a2d\u5b9a\u3055\u308c\u3066\u3044\u308b\u305f\u3081\u306b\u7d04125,000(Byte\/s)\u3068\u306a\u308a\u3001\u5fc5\u8981\u306a\u8ee2\u9001\u901f\u5ea6\u3092\u4e0b\u56de\u308a\u307e\u3059\u3002<br \/>\n\u5b9f\u9a13\u306e\u305f\u3081\u306bSDFileSystem.cpp\u5185\u306eSPI\u30af\u30ed\u30c3\u30af\u306e\u8a2d\u5b9a\u309224MHz\u306b\u5909\u66f4\u3057\u30013MB\/s(\u7406\u8ad6\u5024)\u306e\u8ee2\u9001\u901f\u5ea6\u306b\u3057\u3066\u5b9f\u9a13\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p><!--more-->SDFileSystem.cpp\u306e\u5909\u66f4\u884c<\/p>\n<pre class=\"lang:cpp; decode:true; first-line: 210;\" title=\"SDFileSystem.cpp\u306e\u5909\u66f4\u884c(220)\">\r\n    _spi.frequency(24000000); \/\/ Set to 24MHz for data transfer\r\n<\/pre>\n<p>PlayWav.cpp (2014\/8\/24)<br \/>\n\u51fa\u529b\u306f\u524d\u56de\u3068\u540c\u69d8\u306bPWM\u306b\u3088\u3063\u3066\u51fa\u529b\u3057\u307e\u3059\u304c\u3001\u4eca\u56de\u306f44100Hz\u3067\u51fa\u529b\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"lang:cpp; decode:true\" title=\"PlayWav.cpp\">\r\n#include \"mbed.h\"\r\n#include \"SDFileSystem.h\"\r\n\r\nSDFileSystem sd(p5, p6, p7, p8, \"sd\");  \/\/ Star board ORANGE\r\nPwmOut Line_L(p21), Line_R(p22);\r\nDigitalOut statLED1(LED1), statLED2(LED2);\r\n\r\nTicker Tick_Timer;\r\n\r\nuint16_t Wave_CHs, Wave_BITs;\r\nuint32_t Wave_BPS, Wave_dlen;\r\nvolatile uint16_t  bufGP, bufPP; \/\/ buffer index for Get\/Put\r\n#define BUFSIZE 512 \/\/ buffer size\r\nuint8_t Wave_Buff[BUFSIZE * 2];\r\n#define _WU8(v)  Wave_Buff[v]\r\n#define _WS16(v) *( int16_t*)&amp;Wave_Buff[v]\r\n#define _WU16(v) *(uint16_t*)&amp;Wave_Buff[v]\r\n#define _WU32(v) *(uint32_t*)&amp;Wave_Buff[v]\r\n\r\nvoid ISR_Tick(void)\r\n{\r\n  if (bufGP != bufPP) {\r\n    statLED2 = 1;\r\n    switch (Wave_BITs) {\r\n      case 8:\r\n        Line_L = float(_WU8(bufGP)) \/ 255.0;\r\n        if (Wave_CHs &gt; 1) bufGP ++;\r\n        Line_R = float(_WU8(bufGP)) \/ 255.0;\r\n        bufGP ++;\r\n        break;\r\n      case 16:\r\n        Line_L = float(_WS16(bufGP) + 32768) \/ 65537.0;\r\n        if (Wave_CHs &gt; 1) bufGP += 2;\r\n        Line_R = float(_WS16(bufGP) + 32768) \/ 65537.0;\r\n        bufGP += 2;\r\n        break;\r\n    }\r\n    if (bufGP &gt;= (BUFSIZE * 2)) bufGP = 0;\r\n    statLED2 = 0;\r\n  }\r\n}\r\n\r\nvoid disp_Err(int rc)\r\n{\r\n  while (1) {\r\n    for (int i = 0; i &lt; rc; i++) { statLED1 = 1; wait(0.5); statLED1 = 0; wait(0.5); } wait(2); } } int main() { DIR *d; FILE *f; char path[256]; struct dirent *p; int getln; Line_L.period_us(10); Line_R.period_us(10); if ((d = opendir(\"\/sd\/music\")) == NULL) disp_Err(2); while ((p = readdir(d)) != NULL) { char* s = p-&gt;d_name + (strlen(p-&gt;d_name) - 4);\r\n    if (strcmp(s, \".wav\") != 0) continue;\r\n    snprintf(path, sizeof path, \"\/sd\/music\/%s\", p-&gt;d_name);\r\n    if ((f = fopen(path, \"rb\")) == NULL) disp_Err(3);\r\n\r\n    bufPP = fread(Wave_Buff, 1, BUFSIZE, f);\r\n    if (bufPP &lt; 46) disp_Err(4); \/\/ invalid file\r\n\r\n    if ((_WU32( 0) != 0x46464952) || \/\/ \"RIFF\"\r\n        (_WU32( 8) != 0x45564157) || \/\/ \"WAVE\"\r\n        (_WU32(12) != 0x20746D66)) disp_Err(5); \/\/ \"fmt \"\r\n\r\n    Wave_CHs  = _WU16(22);\r\n    Wave_BPS  = _WU32(24);\r\n    Wave_BITs = _WU16(34);\r\n\r\n    bufGP = 38;\r\n    if (_WU32(bufGP) == 0x74636166) bufGP+=12;   \/\/\"fact\"\r\n    if (_WU32(bufGP) != 0x61746164) disp_Err(6); \/\/\"data\"\r\n    bufGP += 4;\r\n    Wave_dlen = _WU32(bufGP) - (bufPP - (bufGP + 4));\r\n\r\n    bufGP += 4;\r\n    Tick_Timer.attach(&amp;ISR_Tick, 1.02 \/ float(Wave_BPS));\r\n\r\n    while (Wave_dlen) {\r\n      if (((bufPP &lt; bufGP) &amp;&amp; ((bufPP + BUFSIZE) &lt; bufGP)) || ((bufPP &gt; bufGP) &amp;&amp; ((bufPP - BUFSIZE) &lt; bufGP))) { statLED1 = 1; getln = (Wave_dlen &gt; BUFSIZE) ? BUFSIZE : Wave_dlen;\r\n        if (fread(&amp;Wave_Buff[bufPP], 1, getln, f) != getln)\r\n          disp_Err(7);\r\n        if ((Wave_dlen -= getln) == 0) getln &amp;= -4;\r\n        bufPP += getln;\r\n        if (bufPP &gt;= (BUFSIZE * 2)) bufPP = 0;\r\n        statLED1 = 0;\r\n      }\r\n    }\r\n    fclose(f);\r\n    for (int i=0; ((i&lt;10)||(bufGP!=bufPP)); i++) wait(0.1);\r\n    Tick_Timer.detach();    \/\/ Stop!\r\n  }\r\n  closedir(d);\r\n  while (1);\r\n}\r\n<\/pre>\n<p><br clear=\"all\" \/><strong>mbed NXP LPC1768\uff0b\u2606board Orange<\/strong><\/p>\n<div id=\"attachment_315\" style=\"width: 310px\" class=\"wp-caption alignnone\"><a href=\"https:\/\/goji2100.com\/blog\/wp-content\/uploads\/2014\/08\/P01.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-315\" class=\"size-medium wp-image-315\" src=\"https:\/\/goji2100.com\/blog\/wp-content\/uploads\/2014\/08\/P01-300x222.jpg\" alt=\"P01. mbed NXP LPC1768\uff0b\u2606board Orange\" width=\"300\" height=\"222\" srcset=\"https:\/\/goji2100.com\/blog\/wp-content\/uploads\/2014\/08\/P01-300x222.jpg 300w, https:\/\/goji2100.com\/blog\/wp-content\/uploads\/2014\/08\/P01.jpg 1024w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><p id=\"caption-attachment-315\" class=\"wp-caption-text\">P01. mbed NXP LPC1768\uff0b\u2606board Orange<\/p><\/div>\n<p>\u4e21\u30c1\u30e3\u30f3\u30cd\u30eb\u306ePWM\u51fa\u529b\u304b\u3089330\u03a9\u306e\u5236\u9650\u62b5\u6297\u3092\u901a\u3057\u3066\u3001\u30d8\u30c3\u30c9\u30d5\u30a9\u30f3\u306b\u63a5\u7d9a\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p><br clear=\"all\" \/><strong>\u51e6\u7406\u6642\u9593\u8a08\u6e2c<\/strong><br \/>\n\u4e0a\u8a18\u306e\u300c<a href=\"https:\/\/mbed.org\/platforms\/mbed-LPC1768\/\" target=\"_blank\" rel=\"noopener\">mbed LPC1768<\/a>\u300d\uff0b\u300c<a href=\"https:\/\/mbed.org\/users\/logic_star\/notebook\/star_board_orange\/\" target=\"_blank\" rel=\"noopener\">\u2606board Orange<\/a>\u300d\u3067\u5b9f\u884c\u3057\u305f\u3068\u304d\u306e\u51e6\u7406\u6642\u9593\u3092\u8a08\u6e2c\u3057\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n<p><br clear=\"all\" \/><strong>SD\u4e0a\u306e.WAV\u30d5\u30a1\u30a4\u30eb\u306e\u8aad\u8fbc\u51e6\u7406\u6642\u9593\u89b3\u6e2c<\/strong>\uff08LED1\u306e\u6ce2\u5f62\uff09<\/p>\n<div id=\"attachment_272\" style=\"width: 160px\" class=\"wp-caption alignleft\"><a href=\"https:\/\/goji2100.com\/blog\/wp-content\/uploads\/2014\/08\/LED10.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-272\" class=\"size-thumbnail wp-image-272\" src=\"https:\/\/goji2100.com\/blog\/wp-content\/uploads\/2014\/08\/LED10-150x150.png\" alt=\"P10. \u8aad\u8fbc\u51e6\u7406\u9593\u9694\" width=\"150\" height=\"150\" hspace=\"10\" \/><\/a><p id=\"caption-attachment-272\" class=\"wp-caption-text\">P11. \u8aad\u8fbc\u51e6\u7406\u9593\u9694<\/p><\/div>\n<div id=\"attachment_273\" style=\"width: 160px\" class=\"wp-caption alignleft\"><a href=\"https:\/\/goji2100.com\/blog\/wp-content\/uploads\/2014\/08\/LED11.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-273\" class=\"size-thumbnail wp-image-273\" src=\"https:\/\/goji2100.com\/blog\/wp-content\/uploads\/2014\/08\/LED11-150x150.png\" alt=\"P11. \u8aad\u8fbc\u51e6\u7406\u6642\u9593\" width=\"150\" height=\"150\" hspace=\"10\" \/><\/a><p id=\"caption-attachment-273\" class=\"wp-caption-text\">P12. \u8aad\u8fbc\u51e6\u7406\u6642\u9593<\/p><\/div>\n<p><br clear=\"all\" \/>\u4e0a\u8a18\u306f\u901a\u5e38\u306e\u8aad\u8fbc\u6642\u9593\u3067\u3059\u304c\u3001\u5b9f\u969b\u306b\u306fFAT\u306e\u8aad\u8fbc\u307f\u306a\u3069\u3067\u3053\u308c\u4ee5\u4e0a\u306e\u6642\u9593\u304c\u5fc5\u8981\u306a\u3053\u3068\u3082\u3042\u308a\u307e\u3059\u3002\u3053\u308c\u3092\u898b\u308b\u3068NXP LPC176(ARM Cortex-M3 96MHz)\u3067\u3082\u518d\u751f\u4e2d\u306b\u306f\u3001\u30d5\u30a1\u30a4\u30eb\u8aad\u8fbc\u307f\u4ee5\u5916\u306e\u51e6\u7406\u306b\u4f7f\u3048\u308b\u6642\u9593\u306f\u7d0437%\u4f4d\u3057\u304b\u6b8b\u308a\u307e\u305b\u3093\u3002<br \/>\n\uff08\u97f3\u697d\u30d5\u30a1\u30a4\u30eb\u3092\u518d\u751f\u3057\u306a\u304c\u3089\u3001TFT\u6db2\u6676\u306b\u30b8\u30e3\u30b1\u30c3\u30c8\u5199\u771f\u306a\u3069\u3092\u8868\u793a\u3059\u308b\u3088\u3046\u306a\u30d7\u30ed\u30b0\u30e9\u30e0\u306f\u53b3\u3057\u3044\u304b\u3082\uff09<br \/>\n<br clear=\"all\" \/><strong>PWM\u51fa\u529b\u51e6\u7406\u6642\u9593\u89b3\u6e2c<\/strong>\uff08LED2\u306e\u6ce2\u5f62\uff09<\/p>\n<div id=\"attachment_274\" style=\"width: 160px\" class=\"wp-caption alignleft\"><a href=\"https:\/\/goji2100.com\/blog\/wp-content\/uploads\/2014\/08\/LED21.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-274\" class=\"size-thumbnail wp-image-274\" src=\"https:\/\/goji2100.com\/blog\/wp-content\/uploads\/2014\/08\/LED21-150x150.png\" alt=\"P21. \u5272\u8fbc\u51e6\u7406\u9593\u9694\" width=\"150\" height=\"150\" \/><\/a><p id=\"caption-attachment-274\" class=\"wp-caption-text\">P21. \u5272\u8fbc\u51e6\u7406\u9593\u9694<\/p><\/div>\n<div id=\"attachment_275\" style=\"width: 160px\" class=\"wp-caption alignleft\"><a href=\"https:\/\/goji2100.com\/blog\/wp-content\/uploads\/2014\/08\/LED22.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-275\" class=\"size-thumbnail wp-image-275\" src=\"https:\/\/goji2100.com\/blog\/wp-content\/uploads\/2014\/08\/LED22-150x150.png\" alt=\"P22. \u5272\u8fbc\u51e6\u7406\u6642\u9593\" width=\"150\" height=\"150\" \/><\/a><p id=\"caption-attachment-275\" class=\"wp-caption-text\">P22. \u5272\u8fbc\u51e6\u7406\u6642\u9593<\/p><\/div>\n<p><br clear=\"all\" \/>\u5272\u8fbc\u9593\u9694\u306f\u300144,100Hz\u3067\u3042\u308c\u307022.675us\u306b\u306a\u308a\u307e\u3059\u304c\u3001\u30bf\u30a4\u30de\u30fc\u7cbe\u5ea6\u306e\u95a2\u4fc2\u304b\u308923us\uff08\u8aa4\u5dee=\u7d04-1.4%\uff09\u306b\u8a2d\u5b9a\u3057\u3066\u3044\u307e\u3059\u3002<br \/>\n\u5272\u8fbc\u51e6\u7406\u306e\u4e2d\u3067\u306e\u4e21\u30c1\u30e3\u30f3\u30cd\u30eb\u306ePWM\u5024\u306e\u66f8\u8fbc\u307f\u306b\u7d047.6us\u3092\u8981\u3057\u3066\u3044\u307e\u3059\u3001\u3053\u306e\u5272\u8fbc\u51e6\u7406\u4e2d\u306fSD(SPI)\u304b\u3089\u306e\u5272\u8fbc\u307f\u306f\u4fdd\u7559\u3055\u308c\u308b\u305f\u3081\u306b\u8aad\u8fbc\u307f\u901f\u5ea6\u304c\u4f4e\u4e0b\u3057\u307e\u3059\u3002<br \/>\n\u4eee\u306b\u3001\u3053\u306ePWM\u5024\u306e\u8a2d\u5b9a\u3092\u884c\u308f\u306a\u3044\u3068\u5272\u8fbc\u51e6\u7406\u6642\u9593\u306f\u7d040.43us\u3068\u77ed\u304f\u306a\u308a\u307e\u3059\u3001\u3053\u306e\u5834\u5408P11\u306eSD\u8aad\u8fbc\u51e6\u7406\u6642\u9593\u306f1.13ms\u306b\u306a\u308a\u3001\u7a7a\u304d\u6642\u9593\u306e\u5272\u5408\u306f\u7d0462%\u306b\u5897\u3048\u307e\u3059\u3002<br \/>\nPwmOut\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u66f8\u66ff\u3048\u3066\u3001\u5b9f\u6570\u6f14\u7b97\u3092\u56de\u907f\u3059\u308b\u3053\u3068\u3067\u5272\u8fbc\u307f\u51e6\u7406\u6642\u9593\u306f\u5927\u5e45\u306b\u77ed\u7e2e\u3067\u304d\u307e\u3059\u3002<br \/>\n<strong>\uff08\u300c\u77ed\u7e2e\u3067\u304d\u307e\u3057\u305f\u300d\u3067\u306f\u306a\u304f\u3001\u300c\u77ed\u7e2e\u3067\u304d\u308b\u3060\u308d\u3046\u306a\u3041\u300d\u3067\u3059(\uffe3\u30fc\uffe3;\uff09<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u300cArduino UNO\/Mega 2560 .WAV\u30d5\u30a1\u30a4\u30eb\u306e\u518d\u751f\u300d\u3067\u306f\u3001\u975e\u529b\u306aCPU\u3067\u300c16000Hz\/8bit\/Mono\u300d\u5f62\u5f0f\u306e.WAV\u30d5\u30a1\u30a4\u30eb\u3092\u518d\u751f\u3057\u3066\u307f\u307e\u3057\u305f\u3002 \u4eca\u56de\u306f\u3001mbed NXP LPC1768\u3067\u300c44 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17],"tags":[],"_links":{"self":[{"href":"https:\/\/goji2100.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/270"}],"collection":[{"href":"https:\/\/goji2100.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/goji2100.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/goji2100.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/goji2100.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=270"}],"version-history":[{"count":63,"href":"https:\/\/goji2100.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/270\/revisions"}],"predecessor-version":[{"id":1415,"href":"https:\/\/goji2100.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/270\/revisions\/1415"}],"wp:attachment":[{"href":"https:\/\/goji2100.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=270"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/goji2100.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=270"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/goji2100.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=270"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}