{"id":43055,"date":"2025-06-11T08:54:20","date_gmt":"2025-06-11T00:54:20","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/43055.html"},"modified":"2025-06-11T08:54:20","modified_gmt":"2025-06-11T00:54:20","slug":"stm32%e4%b9%8bsg90%e8%88%b5%e6%9c%ba%e6%8e%a7%e5%88%b6%ef%bc%88%e9%99%84%e8%a7%86%e9%a2%91%e8%ae%b2%e8%a7%a3%ef%bc%89","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/43055.html","title":{"rendered":"STM32\u4e4bSG90\u8235\u673a\u63a7\u5236\uff08\u9644\u89c6\u9891\u8bb2\u89e3\uff09"},"content":{"rendered":"<p id=\"main-toc\">\u76ee\u5f55<\/p>\n<p id=\"%E5%89%8D%E8%A8%80%EF%BC%9A-toc\" style=\"margin-left:0px\">\u524d\u8a00&#xff1a;<\/p>\n<p id=\"%E4%B8%80%E3%80%81%E7%A1%AC%E4%BB%B6%E5%87%86%E5%A4%87%E4%B8%8E%E6%8E%A5%E7%BA%BF-toc\" style=\"margin-left:0px\">\u4e00\u3001\u786c\u4ef6\u51c6\u5907\u4e0e\u63a5\u7ebf<\/p>\n<p id=\"1.1%20%E7%A1%AC%E4%BB%B6%E6%B8%85%E5%8D%95-toc\" style=\"margin-left:40px\">1.1 \u786c\u4ef6\u6e05\u5355<\/p>\n<p id=\"1.2%20%E6%8E%A5%E7%BA%BF-toc\" style=\"margin-left:40px\">1.2 \u63a5\u7ebf<\/p>\n<p id=\"%E4%BA%8C%E3%80%81%20SG90%E8%88%B5%E6%9C%BA%E7%AE%80%E4%BB%8B-toc\" style=\"margin-left:0px\">\u4e8c\u3001 SG90\u8235\u673a\u7b80\u4ecb<\/p>\n<p id=\"1.1%20%E5%A4%96%E8%A7%82-toc\" style=\"margin-left:40px\">1.1 \u5916\u89c2<\/p>\n<p id=\"%C2%A01.2%20%E5%9F%BA%E6%9C%AC%E5%8F%82%E6%95%B0-toc\" style=\"margin-left:40px\">\u00a01.2 \u57fa\u672c\u53c2\u6570<\/p>\n<p id=\"1.3%20%E5%BC%95%E8%84%9A%E8%AF%B4%E6%98%8E%C2%A0-toc\" style=\"margin-left:40px\">1.3 \u5f15\u811a\u8bf4\u660e\u00a0<\/p>\n<p id=\"1.4%20%E6%8E%A7%E5%88%B6%E5%8E%9F%E7%90%86-toc\" style=\"margin-left:40px\">1.4 \u63a7\u5236\u539f\u7406<\/p>\n<p id=\"1.5%20%E7%89%B9%E7%82%B9-toc\" style=\"margin-left:40px\">1.5 \u7279\u70b9<\/p>\n<p id=\"1.6%20%E5%B8%B8%E8%A7%81%E9%97%AE%E9%A2%98-toc\" style=\"margin-left:40px\">1.6 \u5e38\u89c1\u95ee\u9898<\/p>\n<p id=\"%E4%B8%89%E3%80%81%20%E5%8D%95%E7%89%87%E6%9C%BA%E7%AE%80%E4%BB%8B-toc\" style=\"margin-left:0px\">\u4e09\u3001 \u5355\u7247\u673a\u7b80\u4ecb<\/p>\n<p id=\"%E5%9B%9B%E3%80%81%20%E7%A8%8B%E5%BA%8F%E8%AE%BE%E8%AE%A1%C2%A0-toc\" style=\"margin-left:0px\">\u56db\u3001 \u7a0b\u5e8f\u8bbe\u8ba1\u00a0<\/p>\n<p id=\"4.1%20%E5%AE%9A%E6%97%B6%E5%99%A8%E9%85%8D%E7%BD%AE-toc\" style=\"margin-left:40px\">4.1 \u5b9a\u65f6\u5668\u914d\u7f6e<\/p>\n<p id=\"4.2%20%E8%A7%92%E5%BA%A6%E6%8E%A7%E5%88%B6%E5%87%BD%E6%95%B0-toc\" style=\"margin-left:40px\">4.2 \u89d2\u5ea6\u63a7\u5236\u51fd\u6570<\/p>\n<p id=\"4.3%20%E4%B8%BB%E5%87%BD%E6%95%B0%E8%B0%83%E7%94%A8-toc\" style=\"margin-left:40px\">4.3 \u4e3b\u51fd\u6570\u8c03\u7528<\/p>\n<p id=\"%E4%BA%94%E3%80%81%20%E6%80%BB%E7%BB%93-toc\" style=\"margin-left:0px\">\u4e94\u3001 \u603b\u7ed3<\/p>\n<hr id=\"hr-toc\" \/>\n<h2>\u524d\u8a00&#xff1a;<\/h2>\n<p>STM32F103C8T6\u00a0\u662f\u4e00\u6b3e\u6027\u4ef7\u6bd4\u6781\u9ad8\u7684ARM Cortex-M3\u5185\u6838\u5fae\u63a7\u5236\u5668&#xff0c;\u5e7f\u6cdb\u5e94\u7528\u4e8e\u5d4c\u5165\u5f0f\u5f00\u53d1\u3002SG90\u8235\u673a\u00a0\u5219\u662f\u5c0f\u578b\u8235\u673a\u7684\u4ee3\u8868&#xff0c;\u5e38\u7528\u4e8e\u673a\u5668\u4eba\u3001\u667a\u80fd\u5bb6\u5c45\u7b49\u573a\u666f\u3002\u672c\u6587\u5c06\u901a\u8fc7\u786c\u4ef6\u8fde\u63a5\u3001PWM\u4fe1\u53f7\u914d\u7f6e\u3001\u4ee3\u7801\u5b9e\u73b0\u7b49\u6b65\u9aa4&#xff0c;\u8be6\u7ec6\u8bb2\u89e3\u5982\u4f55\u7528STM32F103C8T6\u63a7\u5236SG90\u8235\u673a\u3002<\/p>\n<p><span style=\"color:#fe2c24\">\u89c6\u9891\u8bb2\u89e3\u94fe\u63a5&#xff1a;<\/span><\/p>\n<p>STM32\u4e4bSG90\u8235\u673a\u6559\u5b66&#xff08;\u9644\u6e90\u7801&#xff09;<\/p>\n<\/p>\n<h2 id=\"%E4%B8%80%E3%80%81%E7%A1%AC%E4%BB%B6%E5%87%86%E5%A4%87%E4%B8%8E%E6%8E%A5%E7%BA%BF\">\u4e00\u3001\u786c\u4ef6\u51c6\u5907\u4e0e\u63a5\u7ebf<\/h2>\n<h3 id=\"1.1%20%E7%A1%AC%E4%BB%B6%E6%B8%85%E5%8D%95\">1.1 \u786c\u4ef6\u6e05\u5355<\/h3>\n<table>\n<tr>\u5668\u4ef6\u6570\u91cf\u5907\u6ce8<\/tr>\n<tbody>\n<tr>\n<td>STM32F103C8T6\u6700\u5c0f\u7cfb\u7edf\u677f<\/td>\n<td>1<\/td>\n<td>\u6838\u5fc3\u63a7\u5236\u5668<\/td>\n<\/tr>\n<tr>\n<td>SG90\u8235\u673a<\/td>\n<td>1<\/td>\n<td>\u5de5\u4f5c\u7535\u538b4.8-6V&#xff0c;\u4fe1\u53f7\u7ebf\u9700PWM<\/td>\n<\/tr>\n<tr>\n<td>5V\u7535\u6e90\u6a21\u5757<\/td>\n<td>1<\/td>\n<td>\u72ec\u7acb\u4f9b\u7535&#xff0c;\u907f\u514d\u677f\u8f7d\u7535\u6d41\u4e0d\u8db3<\/td>\n<\/tr>\n<tr>\n<td>\u675c\u90a6\u7ebf<\/td>\n<td>\u82e5\u5e72<\/td>\n<td>\u8fde\u63a5\u7535\u8def<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3 id=\"1.2%20%E6%8E%A5%E7%BA%BF\">1.2 \u63a5\u7ebf<\/h3>\n<p>SG90\u8235\u673a\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 STM32F103C8T6\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u5916\u90e8\u7535\u6e90  \u68d5\u8272\u7ebf&#xff08;GND&#xff09;\u00a0 \u2192\u00a0\u00a0\u00a0 GND\u5f15\u811a\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u2192\u00a0 GND \u7ea2\u8272\u7ebf&#xff08;VCC&#xff09;\u00a0 \u2192\u00a0 \u00a0 \u8fde\u5916\u90e85V\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u2192\u00a0 5V \u6a59\u8272\u7ebf&#xff08;\u4fe1\u53f7&#xff09;\u00a0\u00a0\u00a0\u2192\u00a0\u00a0\u00a0 PB0&#xff08;TIM3_CH3&#xff09;  \u6ce8\u610f&#xff1a;\u82e5\u9700\u9a71\u52a8\u591a\u4e2a\u8235\u673a&#xff0c;\u5efa\u8bae\u4f7f\u7528\u72ec\u7acb\u7535\u6e90\u4f9b\u7535&#xff0c;\u907f\u514dSTM32\u677f\u8f7d\u7535\u6e90\u8fc7\u8f7d\u3002<\/p>\n<h2 id=\"%E4%BA%8C%E3%80%81%20SG90%E8%88%B5%E6%9C%BA%E7%AE%80%E4%BB%8B\">\u4e8c\u3001 SG90\u8235\u673a\u7b80\u4ecb<\/h2>\n<h3 id=\"1.1%20%E5%A4%96%E8%A7%82\">1.1 \u5916\u89c2<\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"768\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/06\/20250611005419-6848d3bb413dd.png\" width=\"1024\" \/><\/p>\n<h3 id=\"%C2%A01.2%20%E5%9F%BA%E6%9C%AC%E5%8F%82%E6%95%B0\">\u00a01.2 \u57fa\u672c\u53c2\u6570<\/h3>\n<table>\n<tr>\u53c2\u6570\u6570\u503c<\/tr>\n<tbody>\n<tr>\n<td>\u5de5\u4f5c\u7535\u538b<\/td>\n<td>4.8V &#8211; 6V&#xff08;\u5178\u578b5V&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>\u7535\u6d41\u6d88\u8017<\/td>\n<td>100mA&#xff08;\u7a7a\u95f2&#xff09;&#xff0c;250mA&#xff08;\u8fd0\u884c&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>\u626d\u77e9<\/td>\n<td>1.2kg\u00b7cm&#xff08;4.8V&#xff09;&#xff0c;1.6kg\u00b7cm&#xff08;6V&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>\u8f6c\u901f<\/td>\n<td>0.12\u79d2\/60\u00b0&#xff08;4.8V&#xff09;&#xff0c;0.10\u79d2\/60\u00b0&#xff08;6V&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>\u91cd\u91cf<\/td>\n<td>9\u514b<\/td>\n<\/tr>\n<tr>\n<td>\u5c3a\u5bf8<\/td>\n<td>22.2mm \u00d7 11.8mm \u00d7 31mm<\/td>\n<\/tr>\n<tr>\n<td>\u8f6c\u52a8\u89d2\u5ea6<\/td>\n<td>180\u00b0&#xff08;\u90e8\u5206\u578b\u53f7\u652f\u6301360\u00b0&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>\u9f7f\u8f6e\u6750\u8d28<\/td>\n<td>\u5851\u6599&#xff08;\u90e8\u5206\u578b\u53f7\u4e3a\u91d1\u5c5e\u9f7f\u8f6e&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>\u63a5\u53e3\u7c7b\u578b<\/td>\n<td>3\u9488&#xff08;\u4fe1\u53f7\u3001\u7535\u6e90\u3001\u5730&#xff09;<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3 id=\"1.3%20%E5%BC%95%E8%84%9A%E8%AF%B4%E6%98%8E%C2%A0\">1.3 \u5f15\u811a\u8bf4\u660e\u00a0<\/h3>\n<p>SG90\u8235\u673a\u901a\u5e38\u67093\u6839\u7ebf<\/p>\n<p>\u68d5\u8272\u7ebf&#xff08;GND&#xff09;&#xff1a;\u63a5\u5730\u3002<\/p>\n<p>\u7ea2\u8272\u7ebf&#xff08;VCC&#xff09;&#xff1a;\u63a5\u7535\u6e90&#xff08;4.8V-6V&#xff09;\u3002<\/p>\n<p>\u6a59\u8272\u7ebf&#xff08;\u4fe1\u53f7\u7ebf&#xff09;&#xff1a;\u63a5\u6536PWM\u4fe1\u53f7\u63a7\u5236\u89d2\u5ea6\u3002<\/p>\n<h3 id=\"1.4%20%E6%8E%A7%E5%88%B6%E5%8E%9F%E7%90%86\">1.4 \u63a7\u5236\u539f\u7406<\/h3>\n<p>PWM\u4fe1\u53f7\u63a7\u5236&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u4fe1\u53f7\u5468\u671f&#xff1a;20ms&#xff08;50Hz&#xff09;\u3002<\/p>\n<\/li>\n<li>\n<p>\u8109\u51b2\u5bbd\u5ea6&#xff1a;0.5ms &#8211; 2.5ms&#xff0c;\u5bf9\u5e94\u89d2\u5ea60\u00b0 &#8211; 180\u00b0\u3002<\/p>\n<\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"506\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/06\/20250611005419-6848d3bb79c59.png\" width=\"548\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"508\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/06\/20250611005419-6848d3bb8e5c7.png\" width=\"937\" \/><\/p>\n<h3 id=\"1.5%20%E7%89%B9%E7%82%B9\">1.5 \u7279\u70b9<\/h3>\n<p>\u4f18\u70b9&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u4f53\u79ef\u5c0f\u3001\u91cd\u91cf\u8f7b&#xff1a;\u9002\u5408\u7a7a\u95f4\u53d7\u9650\u7684\u9879\u76ee\u3002<\/p>\n<\/li>\n<li>\n<p>\u4ef7\u683c\u4f4e\u5ec9&#xff1a;\u6210\u672c\u4f4e&#xff0c;\u9002\u5408\u6279\u91cf\u4f7f\u7528\u3002<\/p>\n<\/li>\n<li>\n<p>\u6613\u4e8e\u63a7\u5236&#xff1a;\u6807\u51c6PWM\u4fe1\u53f7\u63a5\u53e3&#xff0c;\u517c\u5bb9\u6027\u5f3a\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u7f3a\u70b9&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u626d\u77e9\u8f83\u5c0f&#xff1a;\u4ec5\u9002\u5408\u8f7b\u8d1f\u8f7d\u573a\u666f\u3002<\/p>\n<\/li>\n<li>\n<p>\u5851\u6599\u9f7f\u8f6e\u6613\u78e8\u635f&#xff1a;\u957f\u65f6\u95f4\u9ad8\u8d1f\u8f7d\u5de5\u4f5c\u53ef\u80fd\u5bfc\u81f4\u635f\u574f\u3002<\/p>\n<\/li>\n<\/ul>\n<h3 id=\"1.6%20%E5%B8%B8%E8%A7%81%E9%97%AE%E9%A2%98\">1.6 \u5e38\u89c1\u95ee\u9898<\/h3>\n<p>1&#xff09;\u8235\u673a\u6296\u52a8\u6216\u4e0d\u8f6c\u52a8&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u68c0\u67e5\u7535\u6e90\u7535\u538b\u662f\u5426\u8db3\u591f\u3002<\/p>\n<\/li>\n<li>\n<p>\u68c0\u67e5PWM\u4fe1\u53f7\u662f\u5426\u6b63\u786e\u3002<\/p>\n<\/li>\n<\/ul>\n<p>2&#xff09;\u00a0\u8235\u673a\u53d1\u70ed\u4e25\u91cd&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u68c0\u67e5\u662f\u5426\u8d85\u8d1f\u8377\u8fd0\u884c\u3002<\/p>\n<\/li>\n<li>\n<p>\u786e\u4fdd\u8f6c\u52a8\u8303\u56f4\u5185\u65e0\u673a\u68b0\u5361\u963b\u3002<\/p>\n<\/li>\n<\/ul>\n<p>3&#xff09;\u00a0\u89d2\u5ea6\u4e0d\u51c6\u786e&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u6821\u51c6PWM\u4fe1\u53f7\u8109\u51b2\u5bbd\u5ea6\u3002<\/p>\n<\/li>\n<li>\n<p>\u68c0\u67e5\u8235\u673a\u9f7f\u8f6e\u662f\u5426\u78e8\u635f\u3002<\/p>\n<\/li>\n<\/ul>\n<h2 id=\"%E4%B8%89%E3%80%81%20%E5%8D%95%E7%89%87%E6%9C%BA%E7%AE%80%E4%BB%8B\">\u4e09\u3001 \u5355\u7247\u673a\u7b80\u4ecb<\/h2>\n<p>STM32F103C8T6\u6700\u5c0f\u7cfb\u7edf\u677f&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"477\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/06\/20250611005419-6848d3bbbd680.png\" width=\"910\" \/><\/p>\n<p>\u672c\u6587\u4f7f\u7528\u7684\u5f00\u53d1\u677f\u4e3aSTM32F103C8T6\u6700\u5c0f\u7cfb\u7edf\u677f&#xff0c;SG90\u8235\u673a\u4f7f\u7528\u5230\u7684\u5f15\u811a\u4e3aPB0\u5f15\u811a\u3002\u00a0<\/p>\n<h2 id=\"%E5%9B%9B%E3%80%81%20%E7%A8%8B%E5%BA%8F%E8%AE%BE%E8%AE%A1%C2%A0\">\u56db\u3001 \u7a0b\u5e8f\u8bbe\u8ba1\u00a0<\/h2>\n<h3 id=\"4.1%20%E5%AE%9A%E6%97%B6%E5%99%A8%E9%85%8D%E7%BD%AE\">4.1 \u5b9a\u65f6\u5668\u914d\u7f6e<\/h3>\n<p>\u4f7f\u7528\u00a0TIM3\u7684\u901a\u90533&#xff08;PB0&#xff09;\u751f\u6210PWM&#xff0c;\u6b65\u9aa4\u5982\u4e0b&#xff1a;<\/p>\n<p>1)\u00a0\u65f6\u949f\u914d\u7f6e&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u7cfb\u7edf\u65f6\u949f\u8bbe\u4e3a72MHz&#xff08;\u9ed8\u8ba4\u914d\u7f6e&#xff09;\u3002<\/p>\n<\/li>\n<li>\n<p>APB1\u603b\u7ebf\u9884\u5206\u9891\u7cfb\u6570\u4e3a2\u3002<\/p>\n<\/li>\n<li>\n<p>TIM3\u65f6\u949f\u6e90\u4e3aAPB1\u603b\u7ebf&#xff08;36*2&#061;72MHz&#xff09;\u3002<\/p>\n<\/li>\n<\/ul>\n<p>2)\u00a0\u5b9a\u65f6\u5668\u53c2\u6570\u8ba1\u7b97&#xff1a;<\/p>\n<ul>\n<li>\n<p>PWM\u9891\u7387&#xff1a;50Hz \u2192 \u5468\u671f20ms \u3002<\/p>\n<\/li>\n<li>\n<p>\u9884\u5206\u9891\u503c&#xff08;PSC&#xff09;&#xff1a;72MHz \/ (719 &#043; 1) &#061; 1MHz \u2192 \u6bcf\u4e2a\u8ba1\u6570\u5468\u671f10\u03bcs\u3002<\/p>\n<\/li>\n<li>\n<p>\u81ea\u52a8\u91cd\u88c5\u8f7d\u503c&#xff08;ARR&#xff09;&#xff1a;20,000\u03bcs \/ 10\u03bcs &#061; 2000 \u2192\u00a0ARR &#061; 1999&#xff08;\u4ece0\u8ba1\u6570&#xff09;\u3002<\/p>\n<\/li>\n<\/ul>\n<p>3)\u00a0\u8109\u51b2\u5bbd\u5ea6\u8ba1\u7b97&#xff08;\u4ee590\u00b0\u4e3a\u4f8b&#xff09;&#xff1a;<\/p>\n<ul>\n<li>\n<p>1.5ms &#061; 1500\u03bcs \u2192\u00a0\u5360\u7a7a\u6bd4\u00a0&#061; 1500 \/ 20000 &#061; 7.5%\u3002<\/p>\n<\/li>\n<li>\n<p>\u6bd4\u8f83\u5bc4\u5b58\u5668&#xff08;CCR&#xff09;&#xff1a;2000 * 7.5% &#061; 150 \u2192\u00a0CCR &#061; 150 &#8211; 1 &#061; 149\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u5b9a\u65f6\u5668\u521d\u59cb\u5316\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p>void SG90_PWM_Init(u16 arr, u16 psc)<br \/>\n{<br \/>\n      GPIO_InitTypeDef GPIO_InitStructure;<br \/>\n      TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;<br \/>\n      TIM_OCInitTypeDef TIM_OCInitStructure;<\/p>\n<p>      \/\/ \u4f7f\u80fd\u5b9a\u65f6\u5668TIM3\u65f6\u949f&#xff0c;\u6ce8\u610fTIM3\u65f6\u949f\u4e3aAPB1&#xff0c;\u800c\u975eAPB2<br \/>\n      RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);<\/p>\n<p>      \/\/ \u4f7f\u80fdPWM\u8f93\u51faGPIO\u53e3\u65f6\u949f<br \/>\n      RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);<br \/>\n      GPIO_InitStructure.GPIO_Pin &#061; GPIO_Pin_0;       \/\/ \u5b9a\u65f6\u5668TIM3\u7684PWM\u8f93\u51fa\u901a\u90533&#xff0c;TIM3_CH3<br \/>\n      GPIO_InitStructure.GPIO_Mode &#061; GPIO_Mode_AF_PP; \/\/ \u590d\u7528\u63a8\u633d\u8f93\u51fa<br \/>\n      GPIO_InitStructure.GPIO_Speed &#061; GPIO_Speed_50MHz;<br \/>\n      GPIO_Init(GPIOB, &amp;GPIO_InitStructure); \/\/ \u521d\u59cb\u5316GPIO<\/p>\n<p>      TIM_TimeBaseStructure.TIM_Period &#061; arr;\/\/\u81ea\u52a8\u91cd\u88c5\u503c<br \/>\n      TIM_TimeBaseStructure.TIM_Prescaler &#061;psc; \/\/\u65f6\u949f\u9884\u5206\u9891\u6570<br \/>\n      TIM_TimeBaseStructure.TIM_ClockDivision &#061; 0;<br \/>\n      TIM_TimeBaseStructure.TIM_CounterMode &#061; TIM_CounterMode_Up;\/\/TIM\u5411\u4e0a\u8ba1\u6570\u6a21\u5f0f<br \/>\n      TIM_TimeBaseInit(TIM3, &amp;TIM_TimeBaseStructure); \/\/\u521d\u59cb\u5316TIM3<\/p>\n<p>      \/\/\u521d\u59cb\u5316TIM3_CH3\u7684PWM\u6a21\u5f0f<br \/>\n      TIM_OCInitStructure.TIM_OCMode &#061; TIM_OCMode_PWM1;<br \/>\n      TIM_OCInitStructure.TIM_OutputState &#061; TIM_OutputState_Enable;<br \/>\n      TIM_OCInitStructure.TIM_Pulse &#061; 0;<br \/>\n      TIM_OCInitStructure.TIM_OCPolarity &#061; TIM_OCPolarity_High;<\/p>\n<p>      TIM_OC3Init(TIM3, &amp;TIM_OCInitStructure);<br \/>\n      TIM_OC3PreloadConfig(TIM3, TIM_OCPreload_Enable);\/\/\u4f7f\u80fd\u901a\u9053\u7684\u9884\u88c5\u8f7d\u5bc4\u5b58\u5668<\/p>\n<p>      TIM_ARRPreloadConfig(TIM3, ENABLE); \/\/\u4f7f\u80fd\u91cd\u88c5\u5bc4\u5b58\u5668<br \/>\n      TIM_Cmd(TIM3, ENABLE);\/\/\u4f7f\u80fd\u5b9a\u65f6\u5668TIM3&#xff0c;\u51c6\u5907\u5de5\u4f5c<br \/>\n}<\/p>\n<p>\u521d\u59cb\u5316\u53c2\u6570\u5982\u4e0b&#xff1a;\u00a0<\/p>\n<p>SG90_PWM_Init(1999,719);  \/\/\u521d\u59cb\u5316\u8235\u673a <\/p>\n<h3 id=\"4.2%20%E8%A7%92%E5%BA%A6%E6%8E%A7%E5%88%B6%E5%87%BD%E6%95%B0\">4.2 \u89d2\u5ea6\u63a7\u5236\u51fd\u6570<\/h3>\n<p>\u5c06\u89d2\u5ea6\u8f6c\u6362\u4e3a\u5bf9\u5e94\u7684\u5360\u7a7a\u6bd4&#xff0c;\u89d2\u5ea6\u6700\u5927\u4e3a180\u00b0 \u3002<\/p>\n<p>void SG90_Set_Angle(uint8_t angle)<br \/>\n{<br \/>\n    if (angle &gt; 180)<br \/>\n        angle &#061; 180;<br \/>\n    uint16_t duty &#061; 10 * (angle &#043; 45) \/ 9; \/\/ \u89d2\u5ea6\u8f6c\u5316\u4e3a\u5360\u7a7a\u6bd4<\/p>\n<p>    TIM_SetCompare3(TIM3, duty); \/\/ \u8bbe\u7f6e\u5360\u7a7a\u6bd4<br \/>\n}   <\/p>\n<h3 id=\"4.3%20%E4%B8%BB%E5%87%BD%E6%95%B0%E8%B0%83%E7%94%A8\">4.3 \u4e3b\u51fd\u6570\u8c03\u7528<\/h3>\n<p>SG90_Set_Angle(0);  \/\/\u5360\u7a7a\u6bd42.5%&#xff0c;0\u5ea6<br \/>\ndelay_ms(1000);<br \/>\nSG90_Set_Angle(90);  \/\/\u5360\u7a7a\u6bd47.5%&#xff0c;90\u5ea6<br \/>\ndelay_ms(1000); <\/p>\n<h2 id=\"%E4%BA%94%E3%80%81%20%E6%80%BB%E7%BB%93\">\u4e94\u3001 \u603b\u7ed3<\/h2>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u901a\u8fc7STM32F103C8T6\u7684\u5b9a\u65f6\u5668PWM\u529f\u80fd&#xff0c;\u53ef\u7cbe\u51c6\u63a7\u5236SG90\u8235\u673a\u89d2\u5ea6\u3002\u5173\u952e\u5728\u4e8e\u6b63\u786e\u914d\u7f6e\u5b9a\u65f6\u5668\u7684\u9884\u5206\u9891\u503c\u548c\u81ea\u52a8\u91cd\u88c5\u8f7d\u503c&#xff0c;\u5e76\u5408\u7406\u6620\u5c04\u89d2\u5ea6\u5230\u8109\u5bbd\u3002\u672c\u65b9\u6848\u6210\u672c\u4f4e\u3001\u53ef\u9760\u6027\u9ad8&#xff0c;\u9002\u5408\u673a\u5668\u4eba\u3001\u667a\u80fd\u5bb6\u5c45\u7b49\u5e94\u7528\u573a\u666f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb7.6k\u6b21\uff0c\u70b9\u8d5e43\u6b21\uff0c\u6536\u85cf95\u6b21\u3002\u53c2\u6570\u6570\u503c\u5de5\u4f5c\u7535\u538b4.8V &#8211; 6V\uff08\u5178\u578b5V\uff09\u7535\u6d41\u6d88\u8017100mA\uff08\u7a7a\u95f2\uff09\uff0c250mA\uff08\u8fd0\u884c\uff09\u626d\u77e9\u8f6c\u901f0.12\u79d2\/60\u00b0\uff084.8V\uff09\uff0c0.10\u79d2\/60\u00b0\uff086V\uff09\u91cd\u91cf9\u514b\u5c3a\u5bf8\u8f6c\u52a8\u89d2\u5ea6180\u00b0\uff08\u90e8\u5206\u578b\u53f7\u652f\u6301360\u00b0\uff09\u9f7f\u8f6e\u6750\u8d28\u5851\u6599\uff08\u90e8\u5206\u578b\u53f7\u4e3a\u91d1\u5c5e\u9f7f\u8f6e\uff09\u63a5\u53e3\u7c7b\u578b3\u9488\uff08\u4fe1\u53f7\u3001\u7535\u6e90\u3001\u5730\uff09STM32F103C8T6\u6700\u5c0f\u7cfb\u7edf\u677f\uff1a\u672c\u6587\u4f7f\u7528\u7684\u5f00\u53d1\u677f\u4e3aSTM32F103C8T6\u6700\u5c0f\u7cfb\u7edf\u677f\uff0cSG90\u8235\u673a\u4f7f\u7528\u5230\u7684\u5f15\u811a\u4e3aPB0\u5f15\u811a\u3002_sg90\u8235\u673a<\/p>\n","protected":false},"author":2,"featured_media":43051,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[217,270,269,3992],"topic":[],"class_list":["post-43055","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-stm32","tag-270","tag-269","tag-3992"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>STM32\u4e4bSG90\u8235\u673a\u63a7\u5236\uff08\u9644\u89c6\u9891\u8bb2\u89e3\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/43055.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"STM32\u4e4bSG90\u8235\u673a\u63a7\u5236\uff08\u9644\u89c6\u9891\u8bb2\u89e3\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb7.6k\u6b21\uff0c\u70b9\u8d5e43\u6b21\uff0c\u6536\u85cf95\u6b21\u3002\u53c2\u6570\u6570\u503c\u5de5\u4f5c\u7535\u538b4.8V - 6V\uff08\u5178\u578b5V\uff09\u7535\u6d41\u6d88\u8017100mA\uff08\u7a7a\u95f2\uff09\uff0c250mA\uff08\u8fd0\u884c\uff09\u626d\u77e9\u8f6c\u901f0.12\u79d2\/60\u00b0\uff084.8V\uff09\uff0c0.10\u79d2\/60\u00b0\uff086V\uff09\u91cd\u91cf9\u514b\u5c3a\u5bf8\u8f6c\u52a8\u89d2\u5ea6180\u00b0\uff08\u90e8\u5206\u578b\u53f7\u652f\u6301360\u00b0\uff09\u9f7f\u8f6e\u6750\u8d28\u5851\u6599\uff08\u90e8\u5206\u578b\u53f7\u4e3a\u91d1\u5c5e\u9f7f\u8f6e\uff09\u63a5\u53e3\u7c7b\u578b3\u9488\uff08\u4fe1\u53f7\u3001\u7535\u6e90\u3001\u5730\uff09STM32F103C8T6\u6700\u5c0f\u7cfb\u7edf\u677f\uff1a\u672c\u6587\u4f7f\u7528\u7684\u5f00\u53d1\u677f\u4e3aSTM32F103C8T6\u6700\u5c0f\u7cfb\u7edf\u677f\uff0cSG90\u8235\u673a\u4f7f\u7528\u5230\u7684\u5f15\u811a\u4e3aPB0\u5f15\u811a\u3002_sg90\u8235\u673a\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/43055.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-06-11T00:54:20+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/06\/20250611005419-6848d3bb413dd.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/43055.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/43055.html\",\"name\":\"STM32\u4e4bSG90\u8235\u673a\u63a7\u5236\uff08\u9644\u89c6\u9891\u8bb2\u89e3\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-06-11T00:54:20+00:00\",\"dateModified\":\"2025-06-11T00:54:20+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/43055.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/43055.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/43055.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"STM32\u4e4bSG90\u8235\u673a\u63a7\u5236\uff08\u9644\u89c6\u9891\u8bb2\u89e3\uff09\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"STM32\u4e4bSG90\u8235\u673a\u63a7\u5236\uff08\u9644\u89c6\u9891\u8bb2\u89e3\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/43055.html","og_locale":"zh_CN","og_type":"article","og_title":"STM32\u4e4bSG90\u8235\u673a\u63a7\u5236\uff08\u9644\u89c6\u9891\u8bb2\u89e3\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb7.6k\u6b21\uff0c\u70b9\u8d5e43\u6b21\uff0c\u6536\u85cf95\u6b21\u3002\u53c2\u6570\u6570\u503c\u5de5\u4f5c\u7535\u538b4.8V - 6V\uff08\u5178\u578b5V\uff09\u7535\u6d41\u6d88\u8017100mA\uff08\u7a7a\u95f2\uff09\uff0c250mA\uff08\u8fd0\u884c\uff09\u626d\u77e9\u8f6c\u901f0.12\u79d2\/60\u00b0\uff084.8V\uff09\uff0c0.10\u79d2\/60\u00b0\uff086V\uff09\u91cd\u91cf9\u514b\u5c3a\u5bf8\u8f6c\u52a8\u89d2\u5ea6180\u00b0\uff08\u90e8\u5206\u578b\u53f7\u652f\u6301360\u00b0\uff09\u9f7f\u8f6e\u6750\u8d28\u5851\u6599\uff08\u90e8\u5206\u578b\u53f7\u4e3a\u91d1\u5c5e\u9f7f\u8f6e\uff09\u63a5\u53e3\u7c7b\u578b3\u9488\uff08\u4fe1\u53f7\u3001\u7535\u6e90\u3001\u5730\uff09STM32F103C8T6\u6700\u5c0f\u7cfb\u7edf\u677f\uff1a\u672c\u6587\u4f7f\u7528\u7684\u5f00\u53d1\u677f\u4e3aSTM32F103C8T6\u6700\u5c0f\u7cfb\u7edf\u677f\uff0cSG90\u8235\u673a\u4f7f\u7528\u5230\u7684\u5f15\u811a\u4e3aPB0\u5f15\u811a\u3002_sg90\u8235\u673a","og_url":"https:\/\/www.wsisp.com\/helps\/43055.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-06-11T00:54:20+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/06\/20250611005419-6848d3bb413dd.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"2 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/43055.html","url":"https:\/\/www.wsisp.com\/helps\/43055.html","name":"STM32\u4e4bSG90\u8235\u673a\u63a7\u5236\uff08\u9644\u89c6\u9891\u8bb2\u89e3\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-06-11T00:54:20+00:00","dateModified":"2025-06-11T00:54:20+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/43055.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/43055.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/43055.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"STM32\u4e4bSG90\u8235\u673a\u63a7\u5236\uff08\u9644\u89c6\u9891\u8bb2\u89e3\uff09"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/43055","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=43055"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/43055\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/43051"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=43055"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=43055"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=43055"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=43055"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}