{"id":110,"date":"2022-02-26T21:54:58","date_gmt":"2022-02-26T13:54:58","guid":{"rendered":"https:\/\/blog.lickoo.fun\/?p=110"},"modified":"2022-02-26T21:55:00","modified_gmt":"2022-02-26T13:55:00","slug":"%e7%ac%ac%e4%b8%89%e5%91%a8-stm32%e5%88%a9%e7%94%a8%e4%b8%b2%e5%8f%a3%e5%92%8cpwm%e4%bf%a1%e5%8f%b7%e6%8e%a7%e5%88%b6%e8%88%b5%e6%9c%ba%e8%a7%92%e5%ba%a6","status":"publish","type":"post","link":"https:\/\/blog.lickoo.fun\/?p=110","title":{"rendered":"\u7b2c\u4e09\u5468--STM32\u5229\u7528\u4e32\u53e3\u548cPWM\u4fe1\u53f7\u63a7\u5236\u8235\u673a\u89d2\u5ea6"},"content":{"rendered":"\n<!doctype html>\n<html>\n<head>\n<meta charset='UTF-8'><meta name='viewport' content='width=device-width initial-scale=1'>\n<\/head>\n<body>\n<h2>\u64cd\u4f5c\u6d41\u7a0b\uff1a<\/h2>\n<br>\n<p>\u7b80\u5355\u5730\u7f1d\u5408\u4e86\u4e00\u4e0b\u4ee3\u7801\u3002\n<i>\u96be\u5ea6\uff1a<font color = green>\u6709\u624b\u5c31\u884c<\/font><\/i><\/p>\n<hr>\n<p>\u53c2\u8003\uff1a<a href='http:\/\/news.eeworld.com.cn\/mcu\/article_2016122732679.html' target='_blank' rel=\"noopener\">http:\/\/news.eeworld.com.cn\/mcu\/article_2016122732679.html<\/a><\/p>\n<blockquote><p>\ud83d\udca1 \u6309\u4e0a\u8ff0\u6d41\u7a0b\u5c06\u4ee3\u7801\u5c01\u88c5\u8fdb\u5165\u4e00\u4e2a\u51fd\u6570PWM_init\u4e2d\uff0c\u6210\u529f\u5f97\u5230&quot;pwm.h\u548cpwm.c&quot;\u3002<\/p>\n<\/blockquote>\n<blockquote><p>\ud83d\udca1 \u6253\u5f00\u91ce\u706b\u7684\u793a\u4f8b\u4ee3\u7801\u5e93\uff0c\u5c06usart\u90e8\u5206\u7684&quot;usart.h\u548cusart.c&quot;\u52a0\u5165\u5de5\u7a0b\u6587\u4ef6\u3002<\/p>\n<\/blockquote>\n<blockquote><p>:idea:\u7f16\u5199\u4e3b\u51fd\u6570\uff0c\u76f4\u63a5\u6839\u636e\u5404\u51fd\u6570\u7684\u540d\u79f0\u53ca\u53d8\u91cf\u8c03\u7528\u5373\u53ef\u3002<\/p>\n<\/blockquote>\n<pre><code>#include &quot;stm32f10x.h&quot;\n#include &quot;pwm.h&quot;\n#include &quot;bsp_usart.h&quot;\n\nvoid Delay( uint32_t count )\n{\n\tfor(; count!=0; count--);\n}\n\nint main(void)\n{\n\tchar deg;\n  uint32_t num = 500;\n\tUSART_Config();\n\tPWM_init(9999,143);     \/\/\u9891\u7387\u4e3a\uff1a72*10^6\/(9999+1)\/(143+1)=50Hz\n\tTIM_SetCompare2(TIM3,500);\n\twhile(1){\n\tprintf(&quot;\u8bf7\u8f93\u5165\u4e00\u4e2aN\u6765\u786e\u5b9a\u89d2\u5ea6Deg = N*20\u00b0\\n&quot;);\n\tdeg = getchar();\n\t\tif(deg != &#39;x&#39;)\n\t\t{\n  \t\tswitch(deg)\n  \t\t{\n  \t\t\tcase &#39;1&#39;: \n  \t\t\t{\n  \t\t\t\tnum = 111;\n  \t\t\t\tbreak;\n  \t\t\t}\n  \t\t\tcase &#39;2&#39;:\n  \t\t\t{\n  \t\t\t\tnum = 222;\n  \t\t\t\tbreak;\n  \t\t\t}\n  \t\t\tcase &#39;3&#39;: \n  \t\t\t{\n  \t\t\t\tnum = 333;\n  \t\t\t\tbreak;\n  \t\t\t}\n  \t\t\tcase &#39;4&#39;: \n  \t\t\t{\n  \t\t\t\tnum = 444;\n  \t\t\t\tbreak;\n        }\n  \t\t\tcase &#39;5&#39;:\n  \t\t\t{\n  \t\t\t\tnum = 555;\n  \t\t\t\tbreak;\n  \t\t\t}\n  \t\t\tcase &#39;6&#39;:\n  \t\t\t{\n  \t\t\t\tnum = 666;\n  \t\t\t\tbreak;\n  \t\t\t}\n  \t\t\tcase &#39;7&#39;:\n  \t\t\t{\n  \t\t\t\tnum = 777;\n  \t\t\t\tbreak;\n  \t\t\t}\n  \t\t\tcase &#39;8&#39;:\n  \t\t\t{\n  \t\t\t\tnum = 888;\n  \t\t\t\tbreak;\n  \t\t\t}\n  \t\t\tcase &#39;9&#39;:\n  \t\t\t{\n  \t\t\t\tnum = 999;\n  \t\t\t\tbreak;\n  \t\t\t}\n  \t\t\tcase &#39;0&#39;:\n  \t\t\t{\n  \t\t\t\tnum = 0;\n  \t\t\t\tbreak;\n\t\t\t\tcase &#39;+&#39;:\n\t\t\t\t{\n\t\t\t\t\tnum +=10;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase&#39;-&#39;:\n\t\t\t\t{\n\t\t\t\t\tnum-=10;\n\t\t\t\t\tbreak;\n  \t\t\t}\n\t\t\t}\n\t\t}\n\t}else\n\t\t\t{\n\t\t\t\tuint32_t time;\n\t\t\t\ttime = getchar();\n\t\t\t\twhile(time--)\n\t\t\t\t{\n      \t\tTIM_SetCompare2(TIM3,250);\n      \t\tDelay(0x4ffff);\n      \t\tTIM_SetCompare2(TIM3,1250);\n      \t\tDelay(0x4ffff);\n\t\t\t\t}\n\t\t\t}\n\t\tTIM_SetCompare2(TIM3,250 + num);     \/\/TIM_SetCompare2(TIM3,X); \u5f97\u5230\u5360\u7a7a\u6bd4\u4e3a(X\/100)%\u7684pwm\u6ce2\u5f62\n\t\t}\n}\n<\/code><\/pre>\n<p>&nbsp;<\/p>\n<p><u>PWM \u914d\u7f6e\u7684\u5927\u81f4\u6d41\u7a0b\uff1a<\/u><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><a href='http:\/\/blog.lickoo.fun\/usr\/uploads\/2021\/03\/149360896.pdf' target='_blank' rel=\"noopener\">STM32_PWM\u8f93\u51fa.pdf<\/a><\/p>\n<hr>\n\u603b\u7528\u65f6\uff1a<i>\u300c2\u5929\u300d<\/i>\n<p>\u5de5\u7a0b\u4e0b\u8f7d\uff1a\n<a href='http:\/\/blog.lickoo.fun\/usr\/uploads\/2021\/03\/2662724956.zip' target='_blank' rel=\"noopener\">\u8235\u673aDemo.zip<\/a><\/p>\n<\/body>\n<\/html>\n","protected":false},"excerpt":{"rendered":"<p>\u64cd\u4f5c\u6d41\u7a0b\uff1a \u7b80\u5355\u5730\u7f1d\u5408\u4e86\u4e00\u4e0b\u4ee3\u7801\u3002 \u96be\u5ea6\uff1a\u6709\u624b\u5c31\u884c \u53c2\u8003\uff1ahttp:\/\/news.eeworld.com.cn [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[4],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.lickoo.fun\/index.php?rest_route=\/wp\/v2\/posts\/110"}],"collection":[{"href":"https:\/\/blog.lickoo.fun\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.lickoo.fun\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.lickoo.fun\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.lickoo.fun\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=110"}],"version-history":[{"count":1,"href":"https:\/\/blog.lickoo.fun\/index.php?rest_route=\/wp\/v2\/posts\/110\/revisions"}],"predecessor-version":[{"id":111,"href":"https:\/\/blog.lickoo.fun\/index.php?rest_route=\/wp\/v2\/posts\/110\/revisions\/111"}],"wp:attachment":[{"href":"https:\/\/blog.lickoo.fun\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=110"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.lickoo.fun\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=110"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.lickoo.fun\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=110"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}