{"id":10020504,"date":"2024-12-18T12:32:50","date_gmt":"2024-12-18T04:32:50","guid":{"rendered":"https:\/\/itmax.cn\/?p=10020504"},"modified":"2024-12-18T12:32:50","modified_gmt":"2024-12-18T04:32:50","slug":"%e8%88%b5%e6%9c%basg90%e8%af%a6%e8%a7%a3","status":"publish","type":"post","link":"https:\/\/itmax.cn\/?p=10020504","title":{"rendered":"\u8235\u673aSG90\u8be6\u89e3"},"content":{"rendered":"<p>\u8235\u673a\uff0c\u4e5f\u53eb\u4f3a\u670d\u7535\u673a\uff0c\u5728\u5d4c\u5165\u5f0f\u5f00\u53d1\u4e2d\uff0c\u8235\u673a\u4f5c\u4e3a\u4e00\u79cd\u5e38\u89c1\u7684\u8fd0\u52a8\u63a7\u5236\u7ec4\u4ef6\uff0c\u5177\u6709\u5e7f\u6cdb\u7684\u5e94\u7528\u3002\u5176\u4e2d\uff0cSG90 \u8235\u673a\u4ee5\u5176\u9ad8\u6548\u3001\u7a33\u5b9a\u7684\u6027\u80fd\u7279\u70b9\uff0c\u6210\u4e3a\u4e86\u8bb8\u591a\u5de5\u7a0b\u5e08\u548c\u7231\u597d\u8005\u7684\u9996\u9009\uff0c\u65e0\u8bba\u662f\u822a\u6a21\u3001\u4e91\u53f0\u3001\u673a\u5668\u4eba\u3001\u667a\u80fd\u5c0f\u8f66\u4e2d\u90fd\u6709\u5b83\u7684\u8eab\u5f71\u3002<\/p>\n<p>\u672c\u6587\u5c06\u6df1\u5165\u63a2\u8ba8SG90\u8235\u673a\u7684\u6280\u672f\u89c4\u683c\u3001\u5de5\u4f5c\u539f\u7406\u548c\u4f7f\u7528\u65b9\u6cd5\uff0c\u4e3a\u60a8\u5c55\u73b0 SG90 \u8235\u673a\u7684\u529f\u80fd\u548c\u65e0\u9650\u53ef\u80fd\u3002<\/p>\n<h2>1. \u6e90\u7801\u4e0b\u8f7d\u53ca\u524d\u7f6e\u9605\u8bfb<\/h2>\n<p>\u672c\u6587\u9996\u53d1\u826f\u8bb8\u5d4c\u5165\u5f0f\u7f51\uff1a<a href=\"https:\/\/link.segmentfault.com\/?enc=4o%2Fci%2F7ISe2RDIldP6uijQ%3D%3D.nrTC0rvgBZFXq%2By8%2BtGZeYNfCRogZu6mudYwoXbCSO4%3D\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">https:\/\/www.lxlinux.net\/e\/<\/a> \uff0c\u6b22\u8fce\u5173\u6ce8\uff01<\/p>\n<p>\u672c\u6587\u6240\u6d89\u53ca\u7684\u6e90\u7801\u53ca\u5b89\u88c5\u5305\u5982\u4e0b\uff08\u7531\u4e8e\u5e73\u53f0\u9650\u5236\uff0c\u8bf7\u70b9\u51fb\u4ee5\u4e0b\u94fe\u63a5\u9605\u8bfb\u539f\u6587\u4e0b\u8f7d\uff09\uff1a<\/p>\n<p><a href=\"https:\/\/link.segmentfault.com\/?enc=OnQ1JgdhTivqPH1sIXhFRQ%3D%3D.jDxaiYeIsVxMGraNyhzqasozGprWl6cfWfo0eDnFmlXu9n7Qu1buoPUVDs3uRNs67PrSZtJQJ0nlg0WwPtZbJw%3D%3D\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">https:\/\/www.lxlinux.net\/e\/stm32\/sg90-tutorial.html<\/a><\/p>\n<p>\u5982\u679c\u4f60\u662f\u5d4c\u5165\u5f0f\u5f00\u53d1\u5c0f\u767d\uff0c\u90a3\u4e48\u5efa\u8bae\u4f60\u5148\u8bfb\u8bfb\u4e0b\u9762\u51e0\u7bc7\u6587\u7ae0\u3002<\/p>\n<ul>\n<li>\u4e86\u89e3\u4e0d\u540c\u7684\u4e0b\u8f7d\u7a0b\u5e8f\u65b9\u6cd5\uff0c\u4e3a\u4f60\u7684\u5d4c\u5165\u5f0f\u5f00\u53d1\u63d0\u4f9b\u66f4\u591a\u9009\u62e9\uff1a<a href=\"https:\/\/segmentfault.com\/a\/https\uff1a\/\/www.lxlinux.net\/e\/stm32\/five-ways-to-flash-program-to-stm32.html\" target=\"_blank\" rel=\"noopener noreferrer\">STM32\u4e0b\u8f7d\u7a0b\u5e8f\u7684\u4e94\u79cd\u65b9\u6cd5<\/a><\/li>\n<li>\u624b\u628a\u624b\u8ba9\u4f60\u638c\u63e1MDK\u7684\u4f7f\u7528\u65b9\u5f0f\u548c\u6280\u5de7\uff0c\u52a9\u4f60\u66f4\u9ad8\u6548\u5730\u8fdb\u884c\u5f00\u53d1\uff1a<a href=\"https:\/\/segmentfault.com\/a\/https\uff1a\/\/www.lxlinux.net\/e\/stm32\/mdk-development-tool-tutorial.html\" target=\"_blank\" rel=\"noopener noreferrer\">\u4e00\u6587\u6559\u4f60\u4f7f\u7528MDK\u5f00\u53d1\u5de5\u5177<\/a><\/li>\n<li>\u4ece\u96f6\u5f00\u59cb\u8f7b\u677e\u638c\u63e1STM32\u5f00\u53d1\u7684\u5fc5\u5907\u6307\u5357\uff1a<a href=\"https:\/\/segmentfault.com\/a\/https\uff1a\/\/www.lxlinux.net\/e\/stm32\/stm32-quick-start-for-beginner.html\" target=\"_blank\" rel=\"noopener noreferrer\">\u96f6\u57fa\u7840\u5feb\u901f\u4e0a\u624bSTM32\u5f00\u53d1\uff08\u624b\u628a\u624b\u4fdd\u59c6\u7ea7\u6559\u7a0b\uff09<\/a><\/li>\n<\/ul>\n<p>\u5f80\u671f\u7cbe\u5f69\u6559\u7a0b\uff0c\u6709\u5174\u8da3\u7684\u5c0f\u4f19\u4f34\u53ef\u4ee5\u770b\u770b\u3002<\/p>\n<ul>\n<li>\u4ece\u96f6\u5f00\u59cb\u8f7b\u677e\u638c\u63e1STM32\u5f00\u53d1\u7684\u5fc5\u5907\u6307\u5357\uff1a<a href=\"https:\/\/segmentfault.com\/a\/https\uff1a\/\/www.lxlinux.net\/e\/stm32\/stm32-quick-start-for-beginner.html\" target=\"_blank\" rel=\"noopener noreferrer\">\u96f6\u57fa\u7840\u5feb\u901f\u4e0a\u624bSTM32\u5f00\u53d1\uff08\u624b\u628a\u624b\u4fdd\u59c6\u7ea7\u6559\u7a0b\uff09<\/a><\/li>\n<li>\u6df1\u5165\u6d45\u51fa\uff0c\u5e2e\u52a9\u60a8\u7406\u89e3\u548c\u5e94\u7528MQTT\u534f\u8bae\uff1a<a href=\"https:\/\/segmentfault.com\/a\/https\uff1a\/\/www.lxlinux.net\/e\/stm32\/mqtt-turorial.html\" target=\"_blank\" rel=\"noopener noreferrer\">\u4e07\u5b57\u731b\u6587\uff1aMQTT\u539f\u7406\u53ca\u6848\u4f8b<\/a><\/li>\n<li>\u901a\u4fd7\u6613\u61c2\u7684 GPIO \u4ecb\u7ecd\u4e0e\u5b9e\u8df5\uff1a<a href=\"https:\/\/segmentfault.com\/a\/https\uff1a\/\/www.lxlinux.net\/e\/stm32\/stm32-gpio-hal.html\" target=\"_blank\" rel=\"noopener noreferrer\">\u5982\u4f55\u5feb\u901f\u6210\u4e3a\u70b9\u706f\u5927\u5e08\uff1f<\/a><\/li>\n<\/ul>\n<table>\n<thead>\n<tr>\n<th align=\"left\">\u4f5c\u8005\u7b80\u4ecb<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td align=\"left\">\u5927\u5bb6\u597d\uff0c\u6211\u662f\u826f\u8bb8\uff0c\u535a\u5ba2\u91cc\u6240\u6709\u7684\u6587\u7ae0\u7686\u4e3a\u6211\u7684\u539f\u521b\u3002<br \/>\u4e0b\u9762\u662f\u6211\u7684\u4e00\u4e9b\u4e2a\u4eba\u4ecb\u7ecd\uff0c\u6b22\u8fce\u4ea4\u4e2a\u670b\u53cb\uff1a<br \/>\u00b7 211\u5de5\u79d1\u7855\u58eb\uff0c\u56fd\u5bb6\u5956\u5b66\u91d1\u83b7\u5f97\u8005\uff1b<br \/>\u00b7 \u6df1\u8015\u5d4c\u5165\u5f0f11\u5e74\uff0c\u524d\u4e16\u754c500\u5f3a\u5916\u4f01\u9ad8\u7ea7\u5d4c\u5165\u5f0f\u5de5\u7a0b\u5e08\uff1b<br \/>\u00b7 \u4e66\u7c4d\u300a\u901f\u5b66Linux\u4f5c\u8005\u300b\uff0c\u673a\u68b0\u5de5\u4e1a\u51fa\u7248\u793e\u4e13\u5bb6\u59d4\u5458\u4f1a\u6210\u5458\uff1b<br \/>\u00b7 \u5168\u7f5160W\u7c89\u4e1d\uff0c\u535a\u5ba2\u5206\u4eab\u5927\u91cf\u539f\u521b\u6210\u4f53\u7cfb\u6587\u7ae0\uff0c\u5168\u7f51\u9605\u8bfb\u91cf\u7d2f\u8ba1\u8d854000\u4e07\uff1b<br \/>\u00b7 \u9760\u81ea\u5a92\u4f53\u8fde\u7eed\u5e74\u5165\u767e\u4e07\uff0c\u9760\u81ea\u5df1\u4e70\u623f\u4e70\u8f66\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u6211\u672c\u79d1\u53ca\u7855\u58eb\u90fd\u662f\u5b66\u673a\u68b0\uff0c\u901a\u8fc7\u81ea\u5b66\u6210\u529f\u8fdb\u5165\u4e16\u754c500\u5f3a\u5916\u4f01\u3002\u6211\u5df2\u7ecf\u5c06\u81ea\u5df1\u7684\u5b66\u4e60\u7ecf\u9a8c\u5199\u6210\u4e86\u4e00\u672c\u7535\u5b50\u4e66\uff0c\u8d85\u5343\u4eba\u901a\u8fc7\u6b64\u4e66\u5b66\u4e60\u5e76\u8f6c\u884c\u6210\u529f\u3002\u73b0\u5728\u5c06\u8fd9\u672c\u7535\u5b50\u4e66\u514d\u8d39\u5206\u4eab\u7ed9\u5927\u5bb6\uff0c\u5e0c\u671b\u5bf9\u4f60\u4eec\u6709\u5e2e\u52a9\uff1a<\/p>\n<p>\u7535\u5b50\u4e66\u94fe\u63a5\uff1a<a href=\"https:\/\/link.segmentfault.com\/?enc=3xys8VBLT08qE15avU7upg%3D%3D.Pa%2BtPKYcw3%2F4uTP%2BkZQv26zMDkabS4PGklZz1gNiPV8%2F45G3JM8PlV9eolQ7oLwr\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">https:\/\/www.lxlinux.net\/1024.html<\/a><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"392\" height=\"836\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/bVdfebd\" alt=\"\" title=\"\"><\/p>\n<h2>2. SG90\u4ecb\u7ecd<\/h2>\n<h3>2.1 \u578b\u53f7\u4ecb\u7ecd<\/h3>\n<p>\u5e02\u9762\u4e0a\u5e38\u89c1\u7684\u8235\u673a\u578b\u53f7\u6709 SG90\u3001MG90S\u3001MG995\u3001MG996R \u7b49\u7b49\uff0c\u4e3b\u8981\u662f\u626d\u77e9\u5927\u5c0f\u3001\u5de5\u4f5c\u7535\u538b\u5927\u5c0f\u3001\u9f7f\u8f6e\u6750\u8d28\u5851\u6599\u6216\u91d1\u5c5e\u7684\u4e0d\u540c\u3002<\/p>\n<p>\u4e00\u822c\u5206\u4e3a180\u5ea6\u548c360\u5ea6\uff1a<\/p>\n<ul>\n<li>180\u5ea6\uff1a\u53ef\u4ee5\u63a7\u5236\u65cb\u8f6c\u89d2\u5ea6\u3001\u6709\u89d2\u5ea6\u5b9a\u4f4d\u3002\u4e0a\u7535\u540e\u8235\u673a\u81ea\u52a8\u590d\u4f4d\u52300\u5ea6\uff0c\u901a\u8fc7\u4e00\u5b9a\u53c2\u6570\u7684\u8109\u51b2\u4fe1\u53f7\u63a7\u5236\u5b83\u7684\u89d2\u5ea6\u3002<\/li>\n<li>360\u00b0\u8235\u673a\u7248\u672c\u4e0d\u53ef\u63a7\u5236\u89d2\u5ea6\uff0c\u53ea\u80fd\u63a7\u5236\u987a\u65f6\u9488\u65cb\u8f6c\u3001\u9006\u65f6\u9488\u65cb\u8f6c\u3001\u505c\u6b62\u548c\u8c03\u8282\u8f6c\u901f\u3002<\/li>\n<\/ul>\n<p>\u6211\u4eec\u4eca\u5929\u7684\u4e3b\u89d2\u662f SG90\uff0c180\u5ea6\u7248\u3002<\/p>\n<p><img decoding=\"async\" width=\"723\" height=\"445\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/bVdfIed\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<h3>2.2 \u5de5\u4f5c\u53c2\u6570\u53ca\u5f15\u811a\u4ecb\u7ecd<\/h3>\n<p>\u5de5\u4f5c\u53c2\u6570\u5982\u4e0b\uff1a<\/p>\n<ul>\n<li>\u5de5\u4f5c\u626d\u77e9\uff1a1.6kg\/cm<\/li>\n<li>\u53cd\u5e94\u901f\u5ea6\uff1a0.12 &#8211; 0.13\u79d2\/60\u00b0<\/li>\n<li>\u6b7b\u533a\u8bbe\u5b9a\uff1a5us<\/li>\n<li>\u8f6c\u52a8\u89d2\u5ea6\uff1a\u5e38\u89c10\u00b0\u300190\u00b0\u3001180\u00b0\u3001360\u00b0<\/li>\n<li>\u9f7f\u8f6e\u6750\u8d28\uff1a\u5c3c\u9f99\u5851\u6599\u9f7f<\/li>\n<li>\u5de5\u4f5c\u7535\u538b\uff1a3V &#8211; 6V<\/li>\n<li>\u6e29\u5ea6\u8303\u56f4\uff1a-30\u00b0 ~ +60\u00b0<\/li>\n<\/ul>\n<p>\u5f15\u811a\u63a5\u7ebf\u53c2\u8003\u5982\u4e0b\uff1a<\/p>\n<table>\n<thead>\n<tr>\n<th align=\"center\">SG90<\/th>\n<th align=\"center\">STM32<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td align=\"center\">PWM \u4fe1\u53f7\u7ebf\uff08\u6a59\u8272\u7ebf\uff09<\/td>\n<td align=\"center\">\u4efb\u610fGPIO<\/td>\n<\/tr>\n<tr>\n<td align=\"center\">VCC\uff08\u7ea2\u7ebf\uff09<\/td>\n<td align=\"center\">3.3\/5V<\/td>\n<\/tr>\n<tr>\n<td align=\"center\">GND\uff08\u68d5\u8272\u7ebf\uff09<\/td>\n<td align=\"center\">GND<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>3. SG90\u539f\u7406<\/h2>\n<p>\u8235\u673a\u7684\u63a7\u5236\u4fe1\u53f7\u662f\u901a\u8fc7\u8109\u51b2\u5bbd\u5ea6\u8c03\u5236\uff08PWM\uff09\u6765\u5b9e\u73b0\u7684\u3002PWM \u4fe1\u53f7\u7684\u5468\u671f\u901a\u5e38\u4e3a20ms\uff0c\u800c\u8109\u51b2\u5bbd\u5ea6\u5219\u5728 0.5ms \u81f3 2.5ms \u4e4b\u95f4\u53d8\u5316\u3002\u8fd9\u4e2a\u8109\u51b2\u5bbd\u5ea6\u4e0e\u8235\u76d8\u7684\u4f4d\u7f6e\u5448\u7ebf\u6027\u5173\u7cfb\uff0c\u8303\u56f4\u4ece0\u5ea6\u5230180\u5ea6\u3002<\/p>\n<p>\u5f53\u7ed9\u8235\u673a\u63d0\u4f9b\u7279\u5b9a\u5bbd\u5ea6\u7684\u8109\u51b2\u4fe1\u53f7\u65f6\uff0c\u8f93\u51fa\u8f74\u4f1a\u4fdd\u6301\u5728\u76f8\u5e94\u7684\u89d2\u5ea6\u4e0a\uff0c\u4e0d\u53d7\u5916\u754c\u8f6c\u77e9\u7684\u5f71\u54cd\uff0c\u76f4\u5230\u63a5\u6536\u5230\u4e0d\u540c\u5bbd\u5ea6\u7684\u8109\u51b2\u4fe1\u53f7\u624d\u4f1a\u6539\u53d8\u8f93\u51fa\u89d2\u5ea6\uff0c\u4f7f\u8235\u76d8\u79fb\u52a8\u5230\u65b0\u7684\u4f4d\u7f6e\u3002\u8235\u673a\u5185\u90e8\u6709\u4e00\u4e2a\u57fa\u51c6\u7535\u8def\uff0c\u4ea7\u751f\u5468\u671f\u4e3a 20ms\u3001\u5bbd\u5ea6\u4e3a 1.5ms \u7684\u57fa\u51c6\u4fe1\u53f7\u3002\u540c\u65f6\uff0c\u8fd8\u6709\u4e00\u4e2a\u6bd4\u8f83\u5668\uff0c\u7528\u4e8e\u5c06\u5916\u90e8\u8f93\u5165\u4fe1\u53f7\u4e0e\u57fa\u51c6\u4fe1\u53f7\u8fdb\u884c\u6bd4\u8f83\uff0c\u4ee5\u786e\u5b9a\u8f6c\u52a8\u65b9\u5411\u548c\u5e45\u5ea6\uff0c\u5e76\u751f\u6210\u9a71\u52a8\u7535\u673a\u8f6c\u52a8\u7684\u4fe1\u53f7\u3002<\/p>\n<p>\u63a7\u5236\u7535\u8def\u677f\u63a5\u6536\u6765\u81ea\u4fe1\u53f7\u7ebf\u7684 PWM \u63a7\u5236\u4fe1\u53f7\uff0c\u7136\u540e\u63a7\u5236\u7535\u673a\u7684\u8f6c\u52a8\u3002\u7535\u673a\u5e26\u52a8\u4e00\u7cfb\u5217\u9f7f\u8f6e\u7ec4\uff0c\u5728\u7ecf\u8fc7\u51cf\u901f\u4f20\u52a8\u540e\uff0c\u5c06\u529b\u91cf\u4f20\u9012\u5230\u8f93\u51fa\u8235\u76d8\u4e0a\u3002\u8235\u673a\u7684\u8f93\u51fa\u8f74\u4e0e\u4f4d\u7f6e\u53cd\u9988\u7535\u4f4d\u8ba1\u76f8\u8fde\uff0c\u5f53\u8235\u76d8\u65cb\u8f6c\u65f6\uff0c\u4f4d\u7f6e\u53cd\u9988\u7535\u4f4d\u8ba1\u4e5f\u4f1a\u968f\u4e4b\u53d8\u5316\uff0c\u5411\u63a7\u5236\u7535\u8def\u677f\u8f93\u51fa\u7535\u538b\u4fe1\u53f7\u8fdb\u884c\u53cd\u9988\u3002\u63a7\u5236\u7535\u8def\u677f\u6839\u636e\u4f4d\u7f6e\u53cd\u9988\u4fe1\u53f7\u5224\u65ad\u5f53\u524d\u4f4d\u7f6e\uff0c\u5e76\u51b3\u5b9a\u7535\u673a\u7684\u8f6c\u52a8\u65b9\u5411\u548c\u901f\u5ea6\uff0c\u4ee5\u5b9e\u73b0\u76ee\u6807\u505c\u6b62\u3002<\/p>\n<p>\u4e3a\u4e86\u63a7\u5236\u8235\u673a\uff0c\u9700\u8981\u4f7f\u7528\u5355\u7247\u673a\u6765\u751f\u6210\u5468\u671f\u4e3a 20ms \u7684\u8109\u51b2\u4fe1\u53f7\uff0c\u5e76\u901a\u8fc7\u63a7\u5236\u8109\u51b2\u7684\u9ad8\u7535\u5e73\u65f6\u95f4\u5728 0.5ms \u81f3 2.5ms \u4e4b\u95f4\u6765\u63a7\u5236\u8235\u673a\u7684\u89d2\u5ea6\u3002\u8fd9\u6837\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u8c03\u6574 PWM \u4fe1\u53f7\u7684\u8109\u51b2\u5bbd\u5ea6\u6765\u7cbe\u786e\u63a7\u5236\u8235\u673a\u7684\u4f4d\u7f6e\u548c\u8fd0\u52a8\u3002<\/p>\n<p>\u4ee5 SG90\uff0c180\u5ea6\u7248\u4e3a\u4f8b\uff0c\u90a3\u4e48\u5bf9\u5e94\u7684\u63a7\u5236\u5173\u7cfb\u662f\u8fd9\u6837\u7684\uff1a<\/p>\n<table>\n<thead>\n<tr>\n<th align=\"center\">\u8109\u51b2\u9ad8\u7535\u5e73<\/th>\n<th align=\"center\">\u89d2\u5ea6<\/th>\n<th align=\"center\">\u5360\u7a7a\u6bd4<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td align=\"center\">0.5ms<\/td>\n<td align=\"center\">0\u00b0<\/td>\n<td align=\"center\">2.5%<\/td>\n<\/tr>\n<tr>\n<td align=\"center\">1.0ms<\/td>\n<td align=\"center\">45\u00b0<\/td>\n<td align=\"center\">5.0%<\/td>\n<\/tr>\n<tr>\n<td align=\"center\">1.5ms<\/td>\n<td align=\"center\">90\u00b0<\/td>\n<td align=\"center\">7.5%<\/td>\n<\/tr>\n<tr>\n<td align=\"center\">2.0ms<\/td>\n<td align=\"center\">135\u00b0<\/td>\n<td align=\"center\">10.0%<\/td>\n<\/tr>\n<tr>\n<td align=\"center\">2.5ms<\/td>\n<td align=\"center\">180\u00b0<\/td>\n<td align=\"center\">12.5%<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>4. \u7f16\u7a0b\u5b9e\u6218<\/h2>\n<p>\u73b0\u5728\u6211\u4eec\u5c31\u52a8\u624b\uff0c\u8ba9 SG90 \u6bcf\u79d2\u8f6c\u52a8\u4e00\u4e0b\uff0c0\u00b0 -&gt; 20\u00b0 -&gt; 40\u00b0 -&gt; 100\u00b0 -&gt; 180\u00b0 \u5982\u6b64\u5faa\u73af\u3002<\/p>\n<h3>4.1 \u786c\u4ef6\u63a5\u7ebf<\/h3>\n<p>\u672c\u6559\u7a0b\u4f7f\u7528\u7684\u786c\u4ef6\u5982\u4e0b\uff1a<\/p>\n<ul>\n<li>\u5355\u7247\u673a\uff1aSTM32F103C8T6<\/li>\n<li>\u8235\u673a\uff1aSG90<\/li>\n<li>\u70e7\u5f55\u5668\uff1aST-LINK V2<\/li>\n<\/ul>\n<p>\u63a5\u7ebf\u5982\u4e0b\uff1a<\/p>\n<table>\n<thead>\n<tr>\n<th align=\"center\">SG90<\/th>\n<th align=\"center\">STM32<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td align=\"center\">PWM \u4fe1\u53f7\u7ebf\uff08\u6a59\u8272\u7ebf\uff09<\/td>\n<td align=\"center\">A0<\/td>\n<\/tr>\n<tr>\n<td align=\"center\">VCC\uff08\u7ea2\u7ebf\uff09<\/td>\n<td align=\"center\">3.3\/5V<\/td>\n<\/tr>\n<tr>\n<td align=\"center\">GND\uff08\u68d5\u8272\u7ebf\uff09<\/td>\n<td align=\"center\">GND<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u70e7\u5f55\u7684\u65f6\u5019\u63a5\u7ebf\u5982\u4e0b\u8868\uff0c\u5982\u679c\u4e0d\u4f1a\u70e7\u5f55\u7684\u8bdd\u53ef\u4ee5\u770b\u6211\u4e4b\u524d\u7684\u6587\u7ae0\u3010<a href=\"https:\/\/segmentfault.com\/a\/https\uff1a\/\/www.lxlinux.net\/e\/stm32\/five-ways-to-flash-program-to-stm32.html\" target=\"_blank\" rel=\"noopener noreferrer\">STM32\u4e0b\u8f7d\u7a0b\u5e8f\u7684\u4e94\u79cd\u65b9\u6cd5<\/a>\u3011\u3002<\/p>\n<table>\n<thead>\n<tr>\n<th align=\"center\">ST-Link V2<\/th>\n<th align=\"center\">STM32<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td align=\"center\">SWCLK<\/td>\n<td align=\"center\">SWCLK<\/td>\n<\/tr>\n<tr>\n<td align=\"center\">SWDIO<\/td>\n<td align=\"center\">SWDIO<\/td>\n<\/tr>\n<tr>\n<td align=\"center\">GND<\/td>\n<td align=\"center\">GND<\/td>\n<\/tr>\n<tr>\n<td align=\"center\">3.3V<\/td>\n<td align=\"center\">3V3<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u63a5\u597d\u5982\u4e0b\u56fe\uff1a<\/p>\n<p>\u6211\u7528\u7684\u662f\u6211\u81ea\u5df1\u6253\u7684\u677f\u5b50\uff0c\u4e0a\u5b98\u4e8c\u53f7\u3002\u5927\u5bb6\u53ef\u4ee5\u7528\u81ea\u5df1\u7684\u677f\u5b50\uff0c\u662f STM32F103C8T6 \u5c31\u884c\u3002<\/p>\n<p><img decoding=\"async\" width=\"723\" height=\"620\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/bVdfIee\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<h3>4.2 \u8235\u673a\u521d\u59cb\u5316<\/h3>\n<p>\u5c06\u8235\u673a PWM \u5f15\u811a\u8fdb\u884c\u4e00\u4e2a\u521d\u59cb\u5316\u3002<\/p>\n<pre><code class=\"c\">void SG_Init(void)\n{\n    GPIO_InitTypeDef GPIO_InitStruct = {0};\n\n    __HAL_RCC_GPIOA_CLK_ENABLE();\n\n    GPIO_InitStruct.Pin = GPIO_PIN_0;                           \/* PWM\u5f15\u811a *\/\n    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;                     \/* \u590d\u7528\u63a8\u633d *\/\n    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;                \/* \u4f4e\u901f *\/\n    HAL_GPIO_Init(GPIOA, &amp;GPIO_InitStruct);                     \/* \u521d\u59cb\u5316PWM\u5f15\u811a *\/\n}<\/code><\/pre>\n<h3>4.3 \u5b9a\u65f6\u5668\u521d\u59cb\u5316<\/h3>\n<p>\u6211\u4eec PWM \u5f15\u811a\u63a5 A0\uff0c\u5bf9\u5e94\u7684\u662f\u5b9a\u65f6\u56682\u548c\u901a\u90531\uff0c\u4ee5\u4e0b\u662f\u521d\u59cb\u5316\u4ee3\u7801\u3002<\/p>\n<pre><code class=\"c\">void TIM2_Init(void)\n{\n    \/\/PA0     ------&gt; TIM2_CH1\n    TIM_ClockConfigTypeDef sClockSourceConfig = {0};            \/* \u5b9a\u65f6\u5668\u8bbe\u7f6e\u7ed3\u6784\u4f53 *\/\n    TIM_MasterConfigTypeDef sMasterConfig = {0};\n    TIM_OC_InitTypeDef sConfigOC = {0};\n\n    htim2.Instance = TIM2;                                      \/* \u901a\u7528\u5b9a\u65f6\u56682 *\/\n    htim2.Init.Prescaler = 7199;                                \/* \u9884\u5206\u9891\u7cfb\u6570 *\/\n    htim2.Init.CounterMode = TIM_COUNTERMODE_UP;                \/* \u9012\u589e\u8ba1\u6570\u6a21\u5f0f *\/\n    htim2.Init.Period = 199;                                    \/* \u81ea\u52a8\u88c5\u8f7d\u503c *\/\n    htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;          \/* \u65f6\u949f\u5206\u9891\u56e0\u5b50 *\/\n    htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE;\n    HAL_TIM_Base_Init(&amp;htim2);\n    sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;\n    HAL_TIM_ConfigClockSource(&amp;htim2, &amp;sClockSourceConfig);\n    HAL_TIM_PWM_Init(&amp;htim2);\n    sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;\n    sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;\n    HAL_TIMEx_MasterConfigSynchronization(&amp;htim2, &amp;sMasterConfig);\n    sConfigOC.OCMode = TIM_OCMODE_PWM1;\n    sConfigOC.Pulse = 0;\n    sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;\n    sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;\n    HAL_TIM_PWM_ConfigChannel(&amp;htim2, &amp;sConfigOC, TIM_CHANNEL_1);\n}\n\nvoid HAL_TIM_Base_MspInit(TIM_HandleTypeDef* tim_baseHandle)\n{\n    if(tim_baseHandle-&gt;Instance==TIM2)\n    {\n        \/* \u5b9a\u65f6\u56682\u65f6\u949f\u4f7f\u80fd *\/\n        __HAL_RCC_TIM2_CLK_ENABLE();\n    }\n}<\/code><\/pre>\n<h3>4.4 \u8235\u673a\u63a7\u5236<\/h3>\n<p>\u5df2\u77e5 PWM \u4fe1\u53f7\u7684\u5468\u671f\u4e3a20ms\uff1b\u9ad8\u7535\u5e73 0.5ms \u6307\u5411 0\u00b0 \u4f4d\u7f6e\uff0c2.5ms \u6307\u5411 180\u00b0 \u4f4d\u7f6e\u3002\u5982\u679c\u6211\u4eec\u8981\u6307\u5411 angle\u00b0\uff1a<\/p>\n<p>2.5-0.5=2ms\uff0c\u5bf9\u5e94\u4e8e180\u00b0<\/p>\n<p>CCRx \/ (199 + 1)  * 20 = 0.5 +\uff08angle \/ 180\uff09\u00d7 2<\/p>\n<p>\u4e8e\u662f CCRx =(1.0 \/ 9.0) * angle + 5.0<\/p>\n<pre><code class=\"c\">void SG_Control(uint16_t angle)\n{\n   float CCRx;\n   CCRx =(1.0 \/ 9.0) * angle + 5.0;                             \/\/\u5360\u7a7a\u6bd4\u503c = 1\/9 * \u89d2\u5ea6 + 5\n   __HAL_TIM_SET_COMPARE(&amp;htim2, TIM_CHANNEL_1, (uint16_t )CCRx);\n}<\/code><\/pre>\n<h3>4.5 \u4e3b\u51fd\u6570<\/h3>\n<p>\u4e3b\u51fd\u6570\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"c\">int main(void)\n{\n    HAL_Init();                         \/* \u521d\u59cb\u5316HAL\u5e93 *\/\n    sys_stm32_clock_init(RCC_PLL_MUL9); \/* \u8bbe\u7f6e\u65f6\u949f, 72Mhz *\/\n    delay_init(72);                     \/* \u5ef6\u65f6\u521d\u59cb\u5316 *\/\n    TIM2_Init();                        \/* \u5b9a\u65f6\u56684\u521d\u59cb\u5316 *\/\n    SG_Init();                          \/* \u8235\u673a\u521d\u59cb\u5316 *\/\n    HAL_TIM_PWM_Start(&amp;htim2,TIM_CHANNEL_1);\n\n    while(1)\n    {\n        SG_Control(0);                  \/\/\u8235\u673a\u65cb\u8f6c\u52300\u5ea6\n        HAL_Delay(1000);\n        SG_Control(20);                 \/\/\u8235\u673a\u65cb\u8f6c\u523020\u5ea6\n        HAL_Delay(1000);\n        SG_Control(40);                 \/\/\u8235\u673a\u65cb\u8f6c\u523040\u5ea6\n        HAL_Delay(1000);\n        SG_Control(100);                \/\/\u8235\u673a\u65cb\u8f6c\u5230100\u5ea6\n        HAL_Delay(1000);\n        SG_Control(180);                \/\/\u8235\u673a\u65cb\u8f6c\u5230180\u5ea6\n        HAL_Delay(1000);\n    }\n}<\/code><\/pre>\n<h3>4.6 \u8fd0\u884c\u6548\u679c<\/h3>\n<p>SG90 \u6bcf\u79d2\u8f6c\u52a8\u4e00\u4e0b\uff0c0\u00b0 -&gt; 20\u00b0 -&gt; 40\u00b0 -&gt; 100\u00b0 -&gt; 180\u00b0 \u5982\u6b64\u5faa\u73af\u3002<\/p>\n<p><img decoding=\"async\"   referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000045651618\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<h2>5. \u603b\u7ed3<\/h2>\n<p>\u901a\u8fc7\u4e86\u89e3 SG90 \u8235\u673a\u7684\u5de5\u4f5c\u539f\u7406\u548c\u7279\u70b9\uff0c\u6211\u4eec\u53ef\u4ee5\u66f4\u597d\u5730\u5229\u7528\u5b83\u7684\u6f5c\u529b\uff0c\u4e3a\u6211\u4eec\u7684\u9879\u76ee\u5e26\u6765\u66f4\u591a\u53ef\u80fd\u6027\u548c\u521b\u65b0\u3002\u65e0\u8bba\u662f\u521d\u5b66\u8005\u8fd8\u662f\u4e13\u4e1a\u5de5\u7a0b\u5e08\uff0cSG90 \u8235\u673a\u90fd\u662f\u4e00\u4e2a\u5f88\u4e0d\u9519\u7684\u6a21\u5757\uff0c\u5b83\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u5b9e\u73b0\u7cbe\u786e\u7684\u4f4d\u7f6e\u63a7\u5236\u548c\u7a33\u5b9a\u7684\u8fd0\u52a8\u6027\u80fd\u3002<\/p>\n<h2>\u5e0c\u671b\u672c\u6587\u80fd\u591f\u8ba9\u4f60\u5bf9 SG90 \u8235\u673a\u6709\u66f4\u6df1\u5165\u7684\u4e86\u89e3\uff0c\u5e76\u4e14\u80fd\u591f\u5728\u4f60\u7684\u9879\u76ee\u4e2d\u53d1\u6325\u51fa\u5b83\u7684\u4f18\u52bf\u3002\u611f\u8c22\u5404\u4f4d\u770b\u5b98\uff0cpeace and love\uff01<\/h2>\n<p><strong>\u53e6\u5916\uff0c\u60f3\u8fdb\u5927\u5382\u7684\u540c\u5b66\uff0c\u4e00\u5b9a\u8981\u597d\u597d\u5b66\u7b97\u6cd5\uff0c\u8fd9\u662f\u9762\u8bd5\u5fc5\u5907\u7684\u3002\u8fd9\u91cc\u51c6\u5907\u4e86\u4e00\u4efd BAT \u5927\u4f6c\u603b\u7ed3\u7684 LeetCode \u5237\u9898\u5b9d\u5178\uff0c\u5f88\u591a\u4eba\u9760\u5b83\u4eec\u8fdb\u4e86\u5927\u5382\u3002<\/strong><\/p>\n<p><img decoding=\"async\" width=\"286\" height=\"83\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/bVdaCCY\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p><a href=\"https:\/\/link.segmentfault.com\/?enc=6CgV3Xh4PyKbiv2zMJf%2FHg%3D%3D.hT%2Fh3S%2FYAJ2Jx%2F4yRSF9%2BZMNKhHsA7m5rUKKaLd07qmQ8cdPSvXfhSOtTwsWp4rG\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">\u5237\u9898 | LeetCode\u7b97\u6cd5\u5237\u9898\u795e\u5668\uff0c\u770b\u5b8c BAT \u968f\u4f60\u6311\uff01<\/a><\/p>\n<h3>\u6709\u6536\u83b7\uff1f\u5e0c\u671b\u8001\u94c1\u4eec\u6765\u4e2a\u4e09\u8fde\u51fb\uff0c\u7ed9\u66f4\u591a\u7684\u4eba\u770b\u5230\u8fd9\u7bc7\u6587\u7ae0<\/h3>\n<p><strong>\u63a8\u8350\u9605\u8bfb\uff1a<\/strong><\/p>\n<ul>\n<li><a href=\"https:\/\/link.segmentfault.com\/?enc=DraX9kniiCWtlZXuEjFLqA%3D%3D.lHB1xtJ1DVMqivXSBnOaoLIw%2FVSn0XBLvzduPs4b5EP7rGp0Duyd3a4LYaL%2BuUz5\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">\u7a0b\u5e8f\u5458\u5fc5\u5907\u7f16\u7a0b\u8d44\u6599\u5927\u5168<\/a><\/li>\n<li><a href=\"https:\/\/link.segmentfault.com\/?enc=C%2BCdKliMCWH%2BnZpgCud2xQ%3D%3D.n3xfiBI1lIxz%2B7Yo8aA1NS%2FXCg9VW%2BSm%2F96et9ANJDHwvH14TLEAGGyYFUh3dt8h\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">\u7a0b\u5e8f\u5458\u5fc5\u5907\u8f6f\u4ef6\u8d44\u6e90<\/a><\/li>\n<\/ul>\n<p>\u6b22\u8fce\u5173\u6ce8\u6211\u7684\u535a\u5ba2\uff1a<a href=\"https:\/\/link.segmentfault.com\/?enc=rWcOuie8MvXlVOS8dW70PQ%3D%3D.0t4wkm9TXhb1xIip05MFwJDjE9MIVDItRAFMRcg5nTs%3D\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">\u826f\u8bb8\u5d4c\u5165\u5f0f\u6559\u7a0b\u7f51<\/a>\uff0c\u6ee1\u6ee1\u90fd\u662f\u5e72\u8d27\uff01<\/p>\n<p><a href=\"https:\/\/segmentfault.com\/a\/1190000045651616\">https:\/\/segmentfault.com\/a\/1190000045651616<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8235\u673a\uff0c\u4e5f\u53eb\u4f3a\u670d\u7535\u673a\uff0c\u5728\u5d4c\u5165\u5f0f\u5f00\u53d1\u4e2d\uff0c\u8235\u673a\u4f5c\u4e3a\u4e00\u79cd\u5e38\u89c1\u7684\u8fd0\u52a8\u63a7\u5236\u7ec4\u4ef6\uff0c\u5177\u6709\u5e7f\u6cdb\u7684\u5e94\u7528\u3002\u5176\u4e2d\uff0cSG90 \u8235\u673a\u4ee5\u5176\u9ad8 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4],"tags":[],"class_list":["post-10020504","post","type-post","status-publish","format-standard","hentry","category-share"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10020504","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10020504"}],"version-history":[{"count":0,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10020504\/revisions"}],"wp:attachment":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10020504"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10020504"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10020504"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}