{"id":142,"date":"2021-01-22T21:59:00","date_gmt":"2021-01-22T21:59:00","guid":{"rendered":"https:\/\/zhewana.cn\/?p=142"},"modified":"2021-01-22T21:59:00","modified_gmt":"2021-01-22T21:59:00","slug":"142","status":"publish","type":"post","link":"https:\/\/zhewana.cn\/?p=142","title":{"rendered":"\u8bb0\u7f16\u7801\u5668\u7684\u5b66\u4e60\u5386\u7a0b"},"content":{"rendered":"<h2>\u7f16\u7801\u5668\u4ee5\u53ca\u5176\u539f\u7406<\/h2>\n<p>\u9996\u5148\u5173\u4e8e\u7f16\u7801\u5668\u6982\u8ff0\u4e0d\u7528\u8bf4\u592a\u591a\uff0c\u7f51\u4e0a\u4e00\u641c\u4e00\u5927\u628a\uff08\u4ee5\u4e0b\u4ecb\u7ecd\u4e3a\u590d\u5236\u5185\u5bb9\uff09\uff1a<\/p>\n<p>\u7f16\u7801\u5668\u5206\u4e3a\u5149\u7535\u548c\u970d\u5c14\u7f16\u7801\u5668\u662f\u4e00\u79cd\u5c06\u89d2\u4f4d\u79fb\u6216\u8005\u89d2\u901f\u5ea6\u8f6c\u6362\u6210\u4e00\u8fde\u4e32\u7535\u6570\u5b57\u8109\u51b2\u7684\u65cb\u8f6c\u5f0f\u4f20\u611f\u5668\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u7f16\u7801\u5668\u6d4b\u91cf\u5230\u4f4d\u79fb\u6216\u8005\u901f\u5ea6\u4fe1\u606f\u3002\u7f16\u7801\u5668\u4ece\u8f93\u51fa\u6570\u636e\u7c7b\u578b\u4e0a\u5206\uff0c\u53ef\u4ee5\u5206\u4e3a\u589e\u91cf\u5f0f\u7f16\u7801\u5668\u548c\u7edd\u5bf9\u5f0f\u7f16\u7801\u5668\u3002<\/p>\n<p>\u4ece\u7f16\u7801\u5668\u68c0\u6d4b\u539f\u7406\u4e0a\u6765\u5206\uff0c\u8fd8\u53ef\u4ee5\u5206\u4e3a\u5149\u5b66\u5f0f\u3001\u78c1\u5f0f\u3001\u611f\u5e94\u5f0f\u3001\u7535\u5bb9\u5f0f\u3002\u5e38\u89c1\u7684\u662f\u5149\u7535\u7f16\u7801\u5668\uff08\u5149\u5b66\u5f0f\uff09\u548c\u970d\u5c14\u7f16\u7801\u5668\uff08\u78c1\u5f0f\uff09\u3002\u4e24\u79cd\uff08\u4ee5\u4e0b\u4ecb\u7ecd\u4e3a\u590d\u5236\u5185\u5bb9\uff09\uff1a<\/p>\n<p>\u5149\u7535\u7f16\u7801\u5668\u662f\u4e00\u79cd\u901a\u8fc7\u5149\u7535\u8f6c\u6362\u5c06\u8f93\u51fa\u8f74\u4e0a\u7684\u673a\u68b0\u51e0\u4f55\u4f4d\u79fb\u91cf\u8f6c\u6362\u6210\u8109\u51b2\u6216\u6570\u5b57\u91cf\u7684\u4f20\u611f\u5668\u3002\u5149\u7535\u7f16\u7801\u5668\u662f\u7531\u5149\u7801\u76d8\u548c\u5149\u7535\u68c0\u6d4b\u88c5\u7f6e\u7ec4\u6210\u3002\u5149\u7801\u76d8\u662f\u5728\u4e00 \u5b9a\u76f4\u5f84\u7684\u5706\u677f\u4e0a\u7b49\u5206\u5730\u5f00\u901a\u82e5\u5e72\u4e2a\u957f\u65b9\u5f62\u5b54\u3002\u7531\u4e8e\u5149\u7535\u7801\u76d8\u4e0e\u7535\u52a8\u673a\u540c\u8f74\uff0c\u7535\u52a8\u673a\u65cb\u8f6c\u65f6\uff0c\u68c0\u6d4b\u88c5\u7f6e\u68c0\u6d4b\u8f93\u51fa\u82e5\u5e72\u8109\u51b2\u4fe1\u53f7\uff0c\u4e3a\u5224\u65ad\u8f6c\u5411\uff0c\u4e00\u822c\u8f93\u51fa\u4e24\u7ec4\u5b58\u5728\u4e00 \u5b9a\u76f8\u4f4d\u5dee\u7684\u65b9\u6ce2\u4fe1\u53f7\u3002<\/p>\n<p>\u970d\u5c14\u7f16\u7801\u5668\u662f\u4e00\u79cd\u901a\u8fc7\u78c1\u7535\u8f6c\u6362\u5c06\u8f93\u51fa\u8f74\u4e0a\u7684\u673a\u68b0\u51e0\u4f55\u4f4d\u79fb\u91cf\u8f6c\u6362\u6210\u8109\u51b2\u6216\u6570\u5b57\u91cf\u7684\u4f20\u611f\u5668\u3002\u970d\u5c14\u7f16\u7801\u5668\u662f\u7531\u970d\u5c14\u7801\u76d8\u548c\u970d\u5c14\u5143\u4ef6\u7ec4\u6210\u3002\u970d\u5c14\u7801\u76d8\u662f\u5728\u4e00 \u5b9a\u76f4\u5f84\u7684\u5706\u677f\u4e0a\u7b49\u5206\u5730\u5e03\u7f6e\u6709\u4e0d\u540c\u7684\u78c1\u6781\u3002\u970d\u5c14\u7801\u76d8\u4e0e\u7535\u52a8\u673a\u540c\u8f74\uff0c\u7535\u52a8\u673a\u65cb\u8f6c\u65f6\uff0c\u970d\u5c14\u5143\u4ef6\u68c0\u6d4b\u8f93\u51fa\u82e5\u5e72\u8109\u51b2\u4fe1\u53f7\uff0c\u4e3a\u5224\u65ad\u8f6c\u5411\uff0c\u4e00\u822c\u8f93\u51fa\u4e24\u7ec4\u5b58\u5728\u4e00\u5b9a\u76f8\u4f4d\u5dee\u7684\u65b9\u6ce2\u4fe1\u53f7\u3002<\/p>\n<p>\u4e0b\u56fe\u4e3a\u6b63\u4ea4\u7f16\u7801\u5668\u7684\u8f93\u51fa\u6ce2\u5f62\u56fe\uff1a  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/zhewana.cn\/wp-content\/uploads\/2022\/02\/1083938687.png\" alt=\"1620478338406.png\" title=\"1620478338406.png\"><\/p>\n<p>\u9664\u4e86\u8fd9\u4e9b\u8fd8\u6709\u4e00\u4e2a\u53c2\u6570\u5bf9\u6211\u4eec\u5f88\u6709\u7528\uff0c\u90a3\u5c31\u662f\u7f16\u7801\u5668\u7684\u7ebf\u6570\u3002  <\/p>\n<p>\u7ebf\u6570\u662f\u4ec0\u4e48\u5462\uff1f  <\/p>\n<p>\u6211\u4eec\u53ef\u4ee5\u7b80\u5355\u7684\u7406\u89e3\u4e3a\u7ebf\u6570\u662f\u591a\u5c11\uff0c\u90a3\u4e48\u7f16\u7801\u5668\u6bcf\u8f6c\u52a8\u4e00\u5708\u5c31\u4f1a\u4ea7\u751f\u591a\u5c11\u4e2a\u8109\u51b2\u4fe1\u53f7\u3002<\/p>\n<hr>\n<h2>\u7a0b\u5e8f\u5b9e\u73b0\uff08\u5e9f\u8bdd\u4e0d\u8bf4\u7eaf\u4eab\u7248\uff09<\/h2>\n<p>\u5b9e\u4f8b\u73af\u5883\uff1a<strong>STM32F401CCU6+CubeMX+HAL\u5e93<\/strong><\/p>\n<p>\u9996\u5148\u968f\u4fbf\u6253\u5f00\u4e00\u4e2a\u5b9a\u65f6\u5668\uff0c\u6253\u5f00\u7f16\u7801\u5668\u6a21\u5f0f\uff1a  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/zhewana.cn\/wp-content\/uploads\/2022\/02\/3821292015.png\" alt=\"1620478445392.png\" title=\"1620478445392.png\"><\/p>\n<p>\u8bbe\u7f6e\u4e3aTI1\u548cTI2\u5171\u540c\u89e6\u53d1\uff1a  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/zhewana.cn\/wp-content\/uploads\/2022\/02\/257635764.png\" alt=\"1620478459280.png\" title=\"1620478459280.png\"><\/p>\n<p>\u6253\u5f00\u4e32\u53e3\u4e00\u4ee5\u4fbf\u63a5\u6536\u6570\u636e<del>\uff08\u771f\u7684\u4e0d\u662f\u61d2\u5f97\u914d\u7f6e\u5c4f\u5e55\u663e\u793a\uff09<\/del><\/p>\n<p>\u63a5\u4e0b\u6765\u6211\u4eec\u9700\u8981\u989d\u5916\u6253\u5f00\u4e00\u4e2a\u5b9a\u65f6\u5668\u6765\u6d4b\u51fa\u5355\u4f4d\u65f6\u95f4\u4ea7\u751f\u4e86\u591a\u5c11\u8109\u51b2,\u6211\u7528\u4e86TIM4\u6765\u8fdb\u884c\u5b9a\u65f6:  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/zhewana.cn\/wp-content\/uploads\/2022\/02\/3796707681.png\" alt=\"1620478474987.png\" title=\"1620478474987.png\"><\/p>\n<p>\u5e76\u4e14\u6253\u5f00\u5b9a\u65f6\u5668\u4e2d\u65ad\uff1a  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/zhewana.cn\/wp-content\/uploads\/2022\/02\/191457721.png\" alt=\"1620478513729.png\" title=\"1620478513729.png\"><\/p>\n<p>\u518d\u6253\u5f00\u4e00\u4e2a\u5b9a\u65f6\u5668\u7528\u4e8e\u4ea7\u751fPWM\u6ce2\uff0820kHz\u5360\u7a7a\u6bd450%\uff09\u8fdb\u800c\u63a7\u5236\u7535\u673a\u8f6c\u52a8\u3002  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/zhewana.cn\/wp-content\/uploads\/2022\/02\/613375798.png\" alt=\"1620478530063.png\" title=\"1620478530063.png\"><\/p>\n<p>\u7535\u673a\u9a71\u52a8\u4e3aTB6612\uff0c\u4f7f\u7528\u5e76\u4e0d\u9ebb\u70e6\uff0c\u6b64\u5904\u4e0d\u518d\u8d58\u8ff0\u3002<\/p>\n<p>\u4e3a\u4e86\u65b9\u4fbf\u8c03\u8bd5\uff0c\u6211\u4eec\u518d\u6253\u5f00\u4e24\u4e2a\u8fde\u63a5\u7740\u5f00\u5173\u7684IO\u53e3\u7528\u4e8e\u63a7\u5236PWM\u7684\u8f93\u51fa\uff08\u4e00\u4e2a\u7528\u4e8e\u63a7\u5236\u7535\u673a\u8f6c\u52a8\u4e0e\u505c\u6b62\uff0c\u53e6\u4e00\u4e2a\u8c03\u8282\u5360\u7a7a\u6bd4\uff09\uff0c\u63a5\u7740\u751f\u6210\u5de5\u7a0b\u3002<\/p>\n<p>\u6572\u4ee3\u7801\uff1a<\/p>\n<pre><code class=\"lang-C\">\/\/\u53d8\u91cf\u5b9a\u4e49\n\/* USER CODE BEGIN PV *\/\nfloat freq=0\uff0cCNT_prevalue=0\uff0cperiod=0\uff0cvelocity=0\uff0cposition=0\uff1b\n\/* USER CODE END PV *\/\n\n\/* USER CODE BEGIN 0 *\/\n\/\/\u5305\u542b\u5934\u6587\u4ef6\n#include &quot;stdio.h&quot;\n#include &quot;math.h&quot;\n\/\/\u4e32\u53e3\u91cd\u5b9a\u5411\n#ifdef __GNUC__\n#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)\n#else\n#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)\n#endif\nPUTCHAR_PROTOTYPE{\n    HAL_UART_Transmit(&amp;huart1, (uint8_t *)&amp;ch, 1 , 0xffff);\n    return ch;\n}\n\/\/\u5b9a\u65f6\u5668\u4e2d\u65ad\u56de\u8c03\u51fd\u6570\nvoid HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim){\n    velocity=(TIM1-&gt;CNT*1.0f-CNT_prevalue)*1.0f*1000\/(13*4);\n    \/\/\u516c\u5f0f\u5e94\u8be5\u662f\uff1a\n    \/\/ \uff08CNT2-CNT1\uff09*\u8ba1\u6570\u5668\u6ea2\u51fa\u9891\u7387\/\uff08\u7f16\u7801\u5668\u7ebf\u6570*\u91c7\u96c6\u8fb9\u6cbf\u6570\uff09\n    \/\/PS\uff1a\u56e0\u4e3a\u8bbe\u7f6e\u4e86TI1\u548cTI2\u5171\u540c\u91c7\u6837\uff0c\u6240\u4ee5\u91c7\u96c6\u8fb9\u6cbf\u4e3a4\u4e2a\u3002\n    period = fabs( velocity * 360 );\n    position = (int)period % 360;\n    value = TIM1 -&gt; CNT;\n}\n\/* USER CODE END 0 *\/\n\n\/\/\u5faa\u73af\u524d\u540e\n\/* USER CODE BEGIN WHILE *\/\n    HAL_TIM_Base_Start_IT(&amp;htim4);\/\/\u5f00\u542f\u5b9a\u65f6\u56684\u4e2d\u65ad\n    HAL_TIM_PWM_Start(&amp;htim3,TIM_CHANNEL_1);\/\/\u5f00\u542fPWM\u901a\u9053\n    HAL_TIM_Encoder_Start(&amp;htim1,TIM_CHANNEL_2);\/\/\u5f00\u542f\u5b9a\u7f16\u7801\u5668\u63a5\u53e3\u901a\u9053\n    HAL_TIM_Encoder_Start(&amp;htim1,TIM_CHANNEL_1);\/\/\u540c\u4e0a\nwhile (1)\n{\n    \/\/\u63a7\u5236\u7535\u673a\n    if(!HAL_GPIO_ReadPin(GPIOA,GPIO_PIN_1))\n        HAL_GPIO_WritePin(GPIOA,GPIO_PIN_2,1);\n    else\n        HAL_GPIO_WritePin(GPIOA,GPIO_PIN_2,0);\n    \/\/\u8f93\u51fa\u8ba1\u7b97\u7ed3\u679c\n    printf(&quot; v=%.1f r\/s\\n period=%.1f degrees\/s\\n position=%.0f degrees\\n&quot;,velocity,period,position);\n    \/\/\u8c03\u8282\u65b9\u6ce2\u5360\u7a7a\u6bd4\n    if(!HAL_GPIO_ReadPin(GPIOA,GPIO_PIN_0))\n    {\n        TIM3-&gt;CCR1+210&gt;4200?TIM3-&gt;CCR1=0:TIM3-&gt;CCR1+=210;\n    }\n    HAL_Delay(200);\n\/* USER CODE END WHILE *\/\n\/* USER CODE BEGIN 3 *\/\n}\n\/* USER CODE END 3 *\/<\/code><\/pre>\n<p>\u70e7\u5f55\uff0c\u6d4b\u8bd5\uff0c\u7ed3\u679c\u5982\u56fe\uff1a  <\/p>\n<p>1620478729839.png<\/p>\n<p>\u6559\u7a0b\u7ed3\u675f\u3002<\/p>\n<hr>\n<h2>\u7a0b\u5e8f\u5b9e\u73b0\uff08\u58a8\u8ff9\u58a8\u8ff9\u89e3\u8bfb\u7248\uff09<\/h2>\n<p>\u65b9\u6cd5\u5176\u5b9e\u5f88\u597d\u7406\u89e3\uff0c\u53ea\u8981\u6d4b\u91cf\u5355\u4f4d\u65f6\u95f4\u5185\u8f93\u51fa\u7684\u8109\u51b2\u4e2a\u6570\u5373\u53ef\u95f4\u63a5\u5f97\u77e5\u8f6c\u901f\u3002<\/p>\n<p>\u90a3\u4e48\u5982\u679c\u60f3\u6d4b\u5f97\u8109\u51b2\u4e2a\u6570\uff0c\u76f8\u4fe1\u5927\u5bb6\u4e00\u5b9a\u4f1a\u5f88\u5bb9\u6613\u60f3\u5230\u8f93\u5165\u6355\u83b7\u3002<\/p>\n<p><del>\u8f93\u5165\u6355\u83b7\u5927\u5bb6\u5e94\u8be5\u90fd\u4f1a\uff0c\u597d\u7684\u6559\u7a0b\u7ed3\u675f\uff0c\u5927\u5bb6\u52a0\u6cb9\uff01<\/del><\/p>\n<p>\u6211\u4e5f\u662f\u7b2c\u4e00\u4e2a\u60f3\u5230\u4e86\u8f93\u5165\u6355\u83b7\uff0c\u4e0d\u8fc7\u51fa\u73b0\u8fd9\u4e2a\u60f3\u6cd5\u7684\u65f6\u5019\u5c31\u6709\u4e00\u4e2a\u95ee\u9898\u4e00\u76f4\u96be\u4ee5\u89e3\u51b3\uff1a<\/p>\n<p>\u5982\u4f55\u5224\u65ad\u7535\u673a\u7684\u8f6c\u5411\u5462\uff1f\u8fd9\u662f\u4e2a\u503c\u5f97\u601d\u8003\u7684\u95ee\u9898\uff0c\u56e0\u4e3a\u6211\u4eec\u540e\u9762\u60f3\u8981\u5b9e\u73b0\u5f88\u591a\u529f\u80fd\u90fd\u9700\u8981\u77e5\u9053\u7535\u673a\u7684\u8f6c\u5411\uff0c\u7136\u800c\u4ec5\u4ec5\u4f7f\u7528\u8f93\u5165\u6355\u83b7\u53ea\u80fd\u6d4b\u51fa\u8109\u51b2\u7684\u4e2a\u6570\u8fdb\u800c\u6d4b\u51fa\u901f\u5ea6\uff0c\u786e\u5b9e\u6ca1\u529e\u6cd5\u77e5\u9053\u7535\u673a\u7684\u8f6c\u5411\u3002\u6b64\u8def\u4e0d\u901a\u7684\u60c5\u51b5\u4e0b\uff0c\u5c31\u8981\u5f00\u59cb\u601d\u8003\u5176\u4ed6\u7684\u65b9\u6cd5\u4e86\u3002<\/p>\n<p>\u597d\u5728\u7ecf\u8fc7\u597d\u5fc3\u4eba\u7684\u63d0\u9192\u6211\u5f97\u77e5\uff1aSTM32\u5177\u6709\u4e13\u95e8\u7684\u786c\u4ef6\u7f16\u7801\u5668\u63a5\u53e3\uff0c\u4e8e\u662f\u7acb\u523b\u8dd1\u53bb\u7ffb\u624b\u518c\u3002\u90a3\u4e48\u8ba9\u6211\u4eec\u5148\u6765\u770b\u770bSTM32\u7684\u786c\u4ef6\u7f16\u7801\u5668\u63a5\u53e3\u662f\u600e\u4e48\u56de\u4e8b\uff1a<\/p>\n<p>\uff08PS\uff1a\u5982\u679c\u5176\u4ed6\u7684\u5355\u7247\u673a\u6ca1\u6709\u5982\u679c\u6ca1\u6709\u7f16\u7801\u5668\u5916\u8bbe\u7684\u8bdd\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528GPIO\u4e2d\u65ad\u8fdb\u884c\uff0c\u5728\u4e2d\u65ad\u91cc\u9762\u5224\u65ad\u53e6\u4e00\u76f8\u7684\u7535\u5e73\u6765\u5224\u65ad\u65b9\u5411\uff0c\u8be5\u65b9\u6cd5\u611f\u5174\u8da3\u7684\u8bfb\u8005\u53ef\u4ee5\u81ea\u5df1\u5c1d\u8bd5  \uff09<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/zhewana.cn\/wp-content\/uploads\/2022\/02\/2692600680.png\" alt=\"1620478834327.png\" title=\"1620478834327.png\"><\/p>\n<p>\u597d\u5bb6\u4f19\uff0c\u9009\u62e9\u63a5\u53e3\u6a21\u5f0f\u4e4b\u540e\u76f4\u63a5\u5c31\u9009\u62e9\u8ba1\u6570\u8fb9\u6cbf\uff0c<del>\u6709\u8f93\u5165\u6355\u83b7\u5185\u5473\u4e86\u55f7<\/del>\uff08\u53ef\u662f\u4e3a\u4ec0\u4e48\u53ea\u9009\u62e9TI1\u548cTI2\u7684\u8fb9\u6cbf\u5374\u4e0d\u662f\u9009\u62e9TI3\u3001TI4\u5462\uff1f\uff09\u3002<\/p>\n<p>\u6211\u4eec\u6253\u5f00CubeMX\u8bd5\u7740\u914d\u7f6e\u4e00\u4e0b\uff1a  <\/p>\n<p>\u9996\u5148\u968f\u4fbf\u6253\u5f00\u4e00\u4e2a\u5b9a\u65f6\u5668\uff08\u6b64\u5904\u5176\u5b9e\u5efa\u8bae\u4f7f\u7528\u7247\u518532\u4f4d\u5b9a\u65f6\u5668\uff09\uff0c\u6253\u5f00\u7f16\u7801\u5668\u6a21\u5f0f\uff1a  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/zhewana.cn\/wp-content\/uploads\/2022\/02\/3249497105.png\" alt=\"1620478949658.png\" title=\"1620478949658.png\"><\/p>\n<p>\u53ef\u4ee5\u770b\u5230\u9009\u4e0b\u7f16\u7801\u5668\u6a21\u5f0f\u4e4b\u540e\u4e0a\u9762\u4e94\u4e2a\u914d\u7f6e\u9009\u9879\u5c31\u9501\u5b9a\u4e86\u3002\u4e5f\u5c31\u662f\u8bf4\u7f16\u7801\u5668\u6a21\u5f0f\u7684\u8bbe\u7f6e\u4ee5\u53ca\u9891\u9053\u7684\u4f7f\u7528\u5176\u5b9e\u662f\u65e9\u5c31\u5185\u5b9a\u597d\u7684\uff0c\u5e76\u4e0d\u50cf\u5176\u4ed6\u7684\u6a21\u5f0f\u4e00\u6837\u53ef\u4ee5\u81ea\u5df1\u9009\u62e9\u901a\u9053\u3002<\/p>\n<p>\u8fd9\u4ef6\u4e8b\u60c5\u5176\u5b9e\u5728\u53c2\u8003\u624b\u518c\u7684\u901a\u7528\u5b9a\u65f6\u5668\u6846\u56fe\u91cc\u9762\u4e5f\u5f97\u5230\u4e86\u9a8c\u8bc1\uff1a  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/zhewana.cn\/wp-content\/uploads\/2022\/02\/1408191992.png\" alt=\"1620479003499.png\" title=\"1620479003499.png\"><\/p>\n<p>\u81f3\u4e8e\u624b\u518c\u8bf4\u7684\u8fb9\u6cbf\u9009\u62e9\u8fd9\u53e5\u8bdd  \uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/zhewana.cn\/wp-content\/uploads\/2022\/02\/980521472.png\" alt=\"1620479026932.png\" title=\"1620479026932.png\"><\/p>\n<p>\u662f\u5728\u8fd9\u91cc\u8bbe\u7f6e\u7684\uff1a  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/zhewana.cn\/wp-content\/uploads\/2022\/02\/4253478052.png\" alt=\"1620479037219.png\" title=\"1620479037219.png\"><\/p>\n<p>\u6b63\u5982\u624b\u518c\u6240\u8bf4\uff0c\u53ef\u4ee5\u9009\u62e9\u4ec5TI1\u3001\u4ec5TI2\u548cTI\u4e0eTI2\u5171\u540c\u4f7f\u7528\u4e09\u79cd\u65b9\u5f0f\u3002<\/p>\n<p>\u7ee7\u7eed\u9605\u8bfb\u624b\u518c\uff1a  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/zhewana.cn\/wp-content\/uploads\/2022\/02\/1271250115.png\" alt=\"1620479059771.png\" title=\"1620479059771.png\"><\/p>\n<p>\u6781\u6027\uff1f\u6211\u4eec\u56de\u5fc6\u4e00\u4e0bPWM\u6ce2\u4e2d\u7684\u6781\u6027\uff0c\u8868\u793a\u7684\u662fOCxREF\u548c\u5b9e\u9645\u8f93\u51faOCx\u4e4b\u95f4\u7684\u5173\u7cfb\uff08\u5373\u6781\u6027\u76f8\u540c\u6216\u76f8\u53cd\uff09\u3002\u597d\u7684\uff0c\u6b64\u5904\u62d3\u5c55\u60f3\u4e00\u4e0b\uff0c\u8fd9\u91cc\u7684\u6781\u6027\u5e94\u8be5\u4e5f\u662f\u9009\u62e9\u4e00\u4e2a\u4e8c\u503c\u7684\u91cf\uff0c\u5f88\u660e\u663e\u5c31\u662f\u68c0\u6d4b\u8fb9\u6cbf\u3002  <\/p>\n<p>\u5bf9\u5e94\u5230CubeMX\u91cc\u9762\uff1a  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/zhewana.cn\/wp-content\/uploads\/2022\/02\/3423432639.png\" alt=\"1620479200390.png\" title=\"1620479200390.png\"><\/p>\n<p>CubeMX\u91cc\u9762\u63a5\u4e0b\u6765\u7684IC Selection\u9009\u9879\u91cc\u9762\u53ea\u6709\u76f4\u63a5\u9009\u9879\uff0c\u4ece\u56fe\u91cc\u9762\u5c31\u53ef\u4ee5\u660e\u786e\u7684\u770b\u51fa\u6765\u3002\u7ee7\u7eed\u770b\u624b\u518c\uff1a  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/zhewana.cn\/wp-content\/uploads\/2022\/02\/102496602.png\" alt=\"1620479223708.png\" title=\"1620479223708.png\"><\/p>\n<p>\u8f93\u5165\u6ee4\u6ce2\u5668\u7684\u7f16\u7a0b\u5bf9\u5e94\u7684\u5e94\u8be5\u5c31\u662f\u8fd9\u91cc\uff1a  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/zhewana.cn\/wp-content\/uploads\/2022\/02\/417803719.png\" alt=\"1620479251663.png\" title=\"1620479251663.png\"><\/p>\n<p>\u81f3\u6b64\uff0cCubeMX\u91cc\u9762\u7684\u53ef\u8bbe\u7f6e\u9879\u5c31\u770b\u5b8c\u4e86\uff0c\u6211\u4eec\u7ee7\u7eed\u770b\u770b\u624b\u518c\u91cc\u9762\u8fd8\u8bf4\u4e86\u4ec0\u4e48\uff1a  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/zhewana.cn\/wp-content\/uploads\/2022\/02\/3331454080.png\" alt=\"1620479273239.png\" title=\"1620479273239.png\"><\/p>\n<p>\u4e0a\u9762\u7684\u5185\u5bb9\u633a\u8ba9\u4eba\u5934\u5927\u7684\uff0c\u4e0d\u8fc7\u597d\u5728\u91cd\u70b9\u5c31\u4e24\u53e5\u3002\u7b2c\u4e00\u53e5\u7684\u610f\u601d\u5176\u5b9e\u5c31\u662f\u8bf4<strong>\u53ea\u6709\u5f53\u7f16\u7801\u5668\u4ea7\u751f\u8109\u51b2\u7684\u65f6\u5019\uff0cCNT\u7684\u503c\u624d\u4f1a\u6539\u53d8<\/strong>\u3002\u7b2c\u4e8c\u53e5\u7684\u610f\u601d\u5c31\u662f\u8bf4\u8f93\u5165\u6539\u53d8\u7684\u65f6\u5019\u4f1a\u66f4\u6539\u8ba1\u6570\u5668\u7684\u8ba1\u6570\u65b9\u5411\u3002  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/zhewana.cn\/wp-content\/uploads\/2022\/02\/2662959669.png\" alt=\"1620479305031.png\" title=\"1620479305031.png\"><\/p>\n<p>\u770b\u5230\u8fd9\u91cc\u6211\u4eec\u5c31\u61c2\u4e86\uff0c\u8fd9\u6a21\u5f0f\u4e0d\u4f46\u80fd\u8ba1\u6570\uff0c\u8fd8\u80fd\u8fa8\u522b\u8f6c\u52a8\u65b9\u5411\u3002<\/p>\n<p>\u540e\u9762\u7ed9\u51fa\u4e86\u4e00\u4e2a\u5b9e\u4f8b\u6211\u4eec\u6765\u770b\u4e00\u4e0b\uff1a  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/zhewana.cn\/wp-content\/uploads\/2022\/02\/1772335756.png\" alt=\"1620479327782.png\" title=\"1620479327782.png\"><\/p>\n<p>\u4e0a\u9762\u7ed9\u51fa\u7684\u6ce2\u5f62\u5c31\u662f\u7f16\u7801\u5668\u7684\u6ce2\u5f62\uff0c\u5f88\u5bb9\u6613\u770b\u51fa\u7f16\u7801\u5668\u6b63\u8f6c\u65f6CNT\u9012\u589e\uff0c\u53cd\u4e4b\u9012\u51cf\u3002<\/p>\n<p>\u56e0\u6b64\uff0c\u6211\u4eec\u53ea\u9700\u8981\u5728\u4e2d\u65ad\u91cc\u9762\u8fde\u7eed\u8fdb\u884c\u4e24\u6b21\u91c7\u6837\uff0c\u5bf9\u4e24\u6b21\u91c7\u6837\u7684CNT\u503c\u505a\u5dee\uff0c\u5982\u679c\u7ed3\u679c\u4e3a\u6b63\u8bf4\u660eCNT\u6b63\u5411\u8ba1\u6570\uff0c\u5373\u7535\u673a\u6b63\u5411\u65cb\u8f6c\uff0c\u53cd\u4e4b\u53cd\u5411\u3002\u9664\u6b64\u4e4b\u5916\uff0c\u6211\u4eec\u8fd8\u53ef\u4ee5\u901a\u8fc7\u8bfb\u53d6TIMx_CR1\u5bc4\u5b58\u5668\u7684DIR\u4f4d\u6765\u83b7\u5f97\u8ba1\u6570\u65b9\u5411\u8fdb\u800c\u5f97\u77e5\u7535\u673a\u8f6c\u5411\uff1a  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/zhewana.cn\/wp-content\/uploads\/2022\/02\/260660160.png\" alt=\"1620479372193.png\" title=\"1620479372193.png\"><\/p>\n<p>\u5b9e\u73b0\u4ee3\u7801\u524d\u9762\u7ed9\u8fc7\u4e86\uff0c\u5c31\u4e0d\u8d58\u8ff0\u4e86\u3002<\/p>\n<hr>\n<h2>\u8865\u5145\u8bf4\u660e<\/h2>\n<p>2021.5.17\u8865\u5145\uff1a<\/p>\n<p>\u5173\u4e8e\u5229\u7528GPIO\u4e2d\u65ad\u5199\u51fa\u8f6f\u4ef6\u7f16\u7801\u5668\u7684\u5b9e\u73b0\u65b9\u6cd5\uff1a<\/p>\n<p>\u7531\u4e8e\u6700\u8fd1\u5728\u5b66MSP432\uff0c\u5176\u4e0a\u5e76\u6ca1\u6709\u786c\u4ef6\u7f16\u7801\u5668\u63a5\u53e3\uff0c\u56e0\u6b64\u53ea\u80fd\u81ea\u5df1\u5199\u8f6f\u4ef6\u7f16\u7801\u5668\uff0c\u5b9e\u73b0\u4e86\u4e00\u4e0b\u53d1\u73b0\u5176\u5b9e\u5e76\u4e0d\u96be\uff0c\u5199\u5728\u6b64\u4f5c\u4e3a\u4e4b\u524d\u5185\u5bb9\u7684\u8865\u5145\u3002<\/p>\n<p>PS\uff1a\u4ee5\u4e0b\u5b9e\u73b0\u4ee3\u7801\u4e3a\u4f7f\u7528MSP432\u7684\u51fd\u6570\u5b9e\u73b0\u7684\uff0cSTM32\u7248\u672c\u5982\u679c\u6709\u673a\u4f1a\u5199\u7684\u8bdd<del>\u5176\u5b9e\u5c31\u662f\u6ca1\u673a\u4f1a\u4e86<\/del>\u4f1a\u5199\u7684\u3002<\/p>\n<p>\u9996\u5148\u662f\u5206\u6790\uff1a<\/p>\n<p><img decoding=\"async\" src=\"\/images\/%E8%AE%B0%E7%BC%96%E7%A0%81%E5%99%A8%E7%9A%84%E5%AD%A6%E4%B9%A0%E5%8E%86%E7%A8%8B\/1621253575694.png\" alt=\"1621253575694\" title=\"1621253575694\"><\/p>\n<p>\u89c2\u5bdf\u7f16\u7801\u5668AB\u76f8\u7684\u8f93\u51fa\u4e0d\u96be\u770b\u51fa\uff0c\u5f53\u7535\u673a\u6b63\u5411\u65cb\u8f6c\u65f6\uff0c\u4e0b\u65b9\u76f8\u4f4d\u9886\u5148\u4e0a\u65b990\u00b0\uff0c\u53cd\u8f6c\u53cd\u4e4b\u3002<\/p>\n<p>\u56e0\u6b64\uff0c\u8981\u5224\u65ad\u65cb\u8f6c\u65b9\u5411\u5176\u5b9e\u5c31\u662f\u5224\u65ad\u4e24\u4fa7\u8f93\u5165\u7684\u76f8\u4f4d\u5dee\uff0c\u4f46\u662f\u5355\u7247\u673a\u5e76\u4e0d\u662f\u793a\u6ce2\u5668\uff0c\u5b83\u6ca1\u6cd5\u770b\u51fa\u4e24\u4e2a\u6ce2\u5f62\u7684\u5168\u8c8c\uff0c\u53ea\u80fd\u770b\u5230\u67d0\u4e00\u77ac\u95f4\u4e24\u4e2a\u6ce2\u5f62\u7684\u9ad8\u4f4e\u7535\u5e73\u72b6\u51b5\u3002\u90a3\u4e48\u6709\u6ca1\u6709\u597d\u7684\u65b9\u6cd5\u53ef\u4ee5<strong>\u5229\u7528\u77ac\u95f4\u7684\u7535\u5e73\u72b6\u6001<\/strong>\u5224\u65ad\u51fa\u4e24\u4e2a\u6ce2\u5f62\u7684\u76f8\u4f4d\u5dee\u5462\uff1f\u7b54\u6848\u662f\u6709\u7684\u3002<\/p>\n<p>\u5176\u5b9e\u5f88\u7b80\u5355\uff0c\u6211\u4eec\u89c2\u5bdf\u4e0b<strong>\u5f53\u4e0a\u65b9\u6ce2\u5f62\u51fa\u73b0\u4e0a\u5347\u6cbf\u7684\u65f6\u5019\uff0c\u5bf9\u5e94\u4e0b\u65b9\u6ce2\u5f62\u7684\u7535\u5e73<\/strong>\u5c31\u4f1a\u53d1\u73b0\uff1a<\/p>\n<p><strong>\u6b63\u5411\u65cb\u8f6c\u7684\u65f6\u5019\u5bf9\u5e94\u4e3a\u4f4e\u7535\u5e73\uff1b<\/strong><\/p>\n<p><strong>\u53cd\u5411\u65cb\u8f6c\u7684\u65f6\u5019\u5bf9\u5e94\u4f4d\u9ad8\u7535\u5e73\u3002<\/strong><\/p>\n<p>\u5982\u6b64\u6211\u4eec\u4fbf\u5b9e\u73b0\u4e86\u5bf9\u65b9\u5411\u7684\u5224\u65ad\u3002<\/p>\n<p>\u4e0e\u6b64\u540c\u65f6\uff0c\u4e0a\u5347\u6cbf\u7684\u4e2a\u6570\u5176\u5b9e\u4e5f\u5bf9\u5e94\u7740\u6ce2\u5f62\u4e2d\u51fa\u73b0\u7684\u9ad8\u7535\u5e73\u4e2a\u6570\uff0c\u56e0\u6b64\u53ef\u4ee5\u5229\u7528\u8ba1\u6570\u4e0a\u5347\u6cbf\u4e2a\u6570\u7684\u65b9\u6cd5\u6765\u5b9e\u73b0\u5bf9\u901f\u5ea6\u7684\u6d4b\u91cf\u3002<\/p>\n<p>MSP432\u5b9e\u73b0\u4ee3\u7801\u5982\u4e0b(IDE:Clion):<\/p>\n<pre><code class=\"lang-C\">\/\/\n\/\/ Created by ZheWana on 2021\/5\/17.\n\/\/\n\n#include &quot;ti\/devices\/msp432p4xx\/driverlib\/driverlib.h&quot;\n#include &quot;UARTRetarget.h&quot;\n\/* Standard Includes *\/\n#include &lt;stdint.h&gt;\n#include &lt;stdbool.h&gt;\n\n\/\/\u5b9a\u4e49\u6280\u672f\u8109\u51b2\u4e2a\u6570\u7684\u8ba1\u6570\u53d8\u91cfCNT\nint32_t CNT;\n\n\/\/GPIO\u4e2d\u65ad\u5904\u7406\u51fd\u6570\nvoid GPIO_IRQHandler(void) {\n    uint8_t temp = GPIO_getInputPinValue(GPIO_PORT_P3, GPIO_PIN2);\n    uint32_t status;\n    status = MAP_GPIO_getEnabledInterruptStatus(GPIO_PORT_P3);\n    MAP_GPIO_clearInterruptFlag(GPIO_PORT_P3, status);\n    if (status &amp; GPIO_PIN3) {\n        MAP_GPIO_toggleOutputOnPin(GPIO_PORT_P1, GPIO_PIN0);\n        if (temp == GPIO_INPUT_PIN_HIGH) {\n            CNT++;\n        } else if (temp == GPIO_INPUT_PIN_LOW) {\n            CNT--;\n        }\n    }\n}\n\n\nint main(void) {\n    WDT_A_holdTimer();\n\n    GPIO_setAsOutputPin(GPIO_PORT_P1, GPIO_PIN0);\n\n    \/\/\u4f7f\u7528P3.3\u548cP3.2\u4f5c\u4e3aAB\u76f8\u8f93\u5165\n    GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P3, GPIO_PIN3);\n    GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P3, GPIO_PIN2);\n    \n    \/\/\u5c06P3.3\u4f5c\u4e3a\u4e2d\u65ad\u5f15\u811a\n    GPIO_clearInterruptFlag(GPIO_PORT_P3, GPIO_PIN3);\n    GPIO_enableInterrupt(GPIO_PORT_P3, GPIO_PIN3);\n    GPIO_interruptEdgeSelect(GPIO_PORT_P3, GPIO_PIN3, GPIO_LOW_TO_HIGH_TRANSITION);\n\n    Interrupt_enableInterrupt(INT_PORT3);\n    Interrupt_enableMaster();\n    Interrupt_registerInterrupt(INT_PORT3, GPIO_IRQHandler);\n\n    while (1) {\n\n    }\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u7f16\u7801\u5668\u4ee5\u53ca\u5176\u539f\u7406 \u9996\u5148\u5173\u4e8e\u7f16\u7801\u5668\u6982\u8ff0\u4e0d\u7528\u8bf4\u592a\u591a\uff0c\u7f51\u4e0a\u4e00\u641c\u4e00\u5927\u628a\uff08\u4ee5\u4e0b\u4ecb\u7ecd\u4e3a\u590d\u5236\u5185\u5bb9\uff09\uff1a \u7f16\u7801\u5668\u5206\u4e3a\u5149\u7535\u548c\u970d\u5c14\u7f16 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[18,14,17],"class_list":["post-142","post","type-post","status-publish","format-standard","hentry","category-embedded","tag-stm32","tag-14","tag-17"],"_links":{"self":[{"href":"https:\/\/zhewana.cn\/index.php?rest_route=\/wp\/v2\/posts\/142","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zhewana.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zhewana.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zhewana.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/zhewana.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=142"}],"version-history":[{"count":0,"href":"https:\/\/zhewana.cn\/index.php?rest_route=\/wp\/v2\/posts\/142\/revisions"}],"wp:attachment":[{"href":"https:\/\/zhewana.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=142"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zhewana.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=142"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zhewana.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=142"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}