{"id":680,"date":"2024-07-22T16:33:38","date_gmt":"2024-07-22T08:33:38","guid":{"rendered":"https:\/\/aoofoo.com\/?p=680"},"modified":"2024-07-22T19:51:31","modified_gmt":"2024-07-22T11:51:31","slug":"2-19-%e7%bc%96%e7%a0%81%e5%99%a8%e6%8e%a5%e5%8f%a3%e6%b5%8b%e9%80%9f%e4%bb%a3%e7%a0%81","status":"publish","type":"post","link":"https:\/\/aoofoo.com\/index.php\/2024\/07\/22\/2-19-%e7%bc%96%e7%a0%81%e5%99%a8%e6%8e%a5%e5%8f%a3%e6%b5%8b%e9%80%9f%e4%bb%a3%e7%a0%81\/","title":{"rendered":"2.19 \u7f16\u7801\u5668\u63a5\u53e3\u6d4b\u901f\u4ee3\u7801"},"content":{"rendered":"<h2>\u7f16\u7801\u5668\u63a5\u53e3\u6d4b\u901f\u63a5\u7ebf\u56fe<\/h2>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-682\" src=\"https:\/\/aoofoo.com\/wp-content\/uploads\/2024\/07\/1-152.png\" alt=\"\" width=\"1007\" height=\"302\" \/><\/p>\n<p>\u53c2\u8003\u5f15\u811a\u5b9a\u4e49\u8868\uff0cPA6\u548cPA7\u662fTIM3\u7684\u901a\u90531\u548c\u901a\u90532\uff0c\u6211\u4eec\u8ba1\u5212\u7528TIM3\u63a5\u7f16\u7801\u5668\u3002<\/p>\n<h2>\u7f16\u7801\u5668\u8ba1\u6570\u4ee3\u7801<\/h2>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-685\" src=\"https:\/\/aoofoo.com\/wp-content\/uploads\/2024\/07\/1-153.png\" alt=\"\" width=\"894\" height=\"403\" \/><\/p>\n<p>\u7b2c\u4e00\u6b65\uff0cRCC\u5f00\u542f\u65f6\u949f\uff0c\u5f00\u542fGPIO\u548c\u5b9a\u65f6\u5668\u7684\u65f6\u949f\u3002<\/p>\n<p>\u7b2c\u4e8c\u6b65\uff0c\u914d\u7f6eGPIO\uff0c\u8fd9\u91cc\u9700\u8981\u628aPA6\u548cPA7\u914d\u7f6e\u6210\u8f93\u5165\u6a21\u5f0f\u3002<\/p>\n<p>\u7b2c\u4e09\u6b65\uff0c\u914d\u7f6e\u65f6\u57fa\u5355\u5143\uff0c\u8fd9\u91cc\u9884\u5206\u9891\u5668\u6211\u4eec\u4e00\u822c\u9009\u62e9\u4e0d\u5206\u9891\u3002\u81ea\u52a8\u91cd\u88c5\u5668\u4e00\u822c\u7ed9\u6700\u592765535\uff0c\u53ea\u9700\u8981CNT\u6267\u884c\u8ba1\u6570\u5c31\u884c\u4e86\u3002<\/p>\n<p>\u7b2c\u56db\u6b65\uff0c\u914d\u7f6e\u8f93\u5165\u6355\u83b7\u5355\u5143\u3002\u4e0d\u8fc7\u8fd9\u91cc\u8f93\u5165\u6355\u83b7\u5355\u5143\u53ea\u6709\u6ee4\u6ce2\u5668\u548c\u6781\u6027\u8fd9\u4e24\u4e2a\u53c2\u6570\u6709\u7528\u3002\u540e\u9762\u7684\u53c2\u6570\u6ca1\u6709\u7528\u5230\uff0c\u4e0e\u7f16\u7801\u5668\u65e0\u5173\u3002<\/p>\n<p>\u7b2c\u4e94\u6b65\uff0c\u914d\u7f6e\u7f16\u7801\u5668\u63a5\u53e3\u6a21\u5f0f\u3002\u8fd9\u4e2a\u76f4\u63a5\u8c03\u7528\u4e00\u4e2a\u5e93\u51fd\u6570\u5c31\u53ef\u4ee5\u4e86\u3002<\/p>\n<p>\u7b2c\u516d\u6b65\uff0c\u8c03\u7528TIM_Cmd()\u51fd\u6570\uff0c\u542f\u52a8\u5b9a\u65f6\u5668\u3002<\/p>\n<p>\u7535\u8def\u521d\u59cb\u5316\u5b8c\u6210\u4e4b\u540e\uff0cCNT\u5c31\u4f1a\u968f\u7740\u7f16\u7801\u5668\u7684\u65cb\u8f6c\u800c\u81ea\u589e\u81ea\u51cf\u4e86\u3002\u5982\u679c\u60f3\u8981\u6d4b\u91cf\u7f16\u7801\u5668\u7684\u4f4d\u7f6e\uff0c\u76f4\u63a5\u8bfb\u51faCNT\u7684\u503c\u5c31\u884c\u4e86\uff0c\u5982\u679c\u60f3\u8981\u6d4b\u91cf\u7f16\u7801\u5668\u7684\u901f\u5ea6\u548c\u65b9\u5411\uff0c\u90a3\u5c31\u9700\u8981\u6bcf\u9694\u4e00\u6bb5\u56fa\u5b9a\u7684\u95f8\u95e8\u65f6\u95f4\u53d6\u51fa\u4e00\u6b21CNT\uff0c\u7136\u540e\u518d\u628aCNT\u6e05\u96f6\u3002\u8fd9\u6837\u5c31\u662f\u6d4b\u9891\u6cd5\u6d4b\u91cf\u901f\u5ea6\u4e86\u3002<\/p>\n<p>\u6d41\u7a0b\u770b\u5b8c\u4e86\uff0c\u6211\u4eec\u518d\u770b\u4e00\u4e0b\u5e93\u51fd\u6570\uff1a<\/p>\n<div class=\"sc-collapse\"><div class=\"sc-collapse__header\"><svg class=\"sc-collapse__arrow\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\"><polyline points=\"6 9 12 15 18 9\"\/><\/svg>\u5b9a\u65f6\u5668\u7f16\u7801\u5668\u63a5\u53e3\u914d\u7f6e<\/div><div class=\"sc-collapse__body\"><div class=\"sc-collapse__content\"><\/p>\n<p>TIM_EncoderInterfaceConfig(TIM_TypeDef* TIMx, uint16_t TIM_EncoderMode,uint16_t TIM_IC1Polarity, uint16_t TIM_IC2Polarity);<\/p>\n<p>\u7b2c\u4e00\u4e2a\u53c2\u6570\u662f\u9009\u62e9\u5b9a\u65f6\u5668\u3002<\/p>\n<p>\u7b2c\u4e8c\u4e2a\u53c2\u6570\u9009\u62e9\u7f16\u7801\u5668\u6a21\u5f0f\u3002<\/p>\n<p>\u540e\u9762\u4e24\u4e2a\u53c2\u6570\uff0c\u5206\u522b\u9009\u62e9\u901a\u90531\u548c\u901a\u90532\u7684\u7535\u5e73\u6781\u6027\u3002<\/p>\n<p><\/div><\/div><\/div>\n<pre class=\"corepress-code-pre\"><code>void Encoder_Init()\r\n{\r\n\t\/\/\u5f00\u542fTIM3\u3001GPIOA\u7684\u65f6\u949f\u3002\r\n\tRCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3,ENABLE);\r\n\tRCC_APB1PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);\r\n\t\/\/\u914d\u7f6eGPIO\uff0cPA6\/PA7\u6539\u6210\u4e0a\u62c9\u8f93\u5165\u3002\r\n\tGPIO_InitTypeDef GPIO_InitStruture;\r\n\tGPIO_InitStruture.GPIO_Mode=GPIO_Mode_IPU;\r\n\tGPIO_InitStruture.GPIO_Pin=GPIO_Pin_6|GPIO_Pin_6;\r\n\tGPIO_Init(GPIOA,&amp;GPIO_InitStruture);\r\n\t\r\n\t\/\/\u4e0d\u9700\u8981\u9009\u62e9\u65f6\u57fa\u5355\u5143\u65f6\u949f\uff0c\u56e0\u4e3a\u7f16\u7801\u5668\u63a5\u53e3\u4f1a\u6258\u7ba1\u65f6\u949f\u3002\r\n\t\/\/\u7f16\u7801\u5668\u63a5\u53e3\u672c\u8eab\u5c31\u662f\u4e00\u4e2a\u5e26\u65b9\u5411\u63a7\u5236\u7684\u5916\u90e8\u65f6\u949f\u3002\r\n\t\/\/TIM_InternalClockConfig(TIM3);\r\n\t\r\n\t\/\/\u914d\u7f6e\u65f6\u57fa\u5355\u5143\u3002\r\n\tTIM_TimeBaseInitTypeDef TIM_TimeBaseStruture;\r\n\tTIM_TimeBaseStruture.TIM_ClockDivision=TIM_CKD_DIV1;\r\n\t\/\/\u8ba1\u6570\u5668\u6a21\u5f0f\u76ee\u524d\u6ca1\u6709\u4f5c\u7528\uff0c\u56e0\u4e3a\u8ba1\u6570\u65b9\u5411\u4e5f\u662f\u88ab\u7f16\u7801\u5668\u63a5\u53e3\u6258\u7ba1\u4e86\u3002\r\n\tTIM_TimeBaseStruture.TIM_CounterMode=TIM_CounterMode_Up;\r\n\t\/\/\u8fd9\u91cc\u7ed9\u6700\u5927\u503c65536-1\uff0c\u8fd9\u6837\u8ba1\u6570\u8303\u56f4\u662f\u6700\u5927\u7684\uff0c\u800c\u4e14\u65b9\u4fbf\u6362\u7b97\u4e3a\u8d1f\u6570\u3002\r\n\tTIM_TimeBaseStruture.TIM_Period=65536 -1; \r\n\t\/\/\u9884\u5206\u9891\u5668\u7ed90\uff0c\u4e0d\u5206\u9891\u3002\r\n\tTIM_TimeBaseStruture.TIM_Prescaler=1-1;\r\n\tTIM_TimeBaseStruture.TIM_RepetitionCounter=0;\r\n\tTIM_TimeBaseInit(TIM3,&amp;TIM_TimeBaseStruture);\r\n\t\r\n\t\/\/\u521d\u59cb\u5316\u8f93\u5165\u6355\u83b7\u5355\u5143\u3002\r\n\t\/\/\u7f16\u7801\u5668\u63a5\u53e3\u53ea\u7528\u5230\u4e86\u6ee4\u6ce2\u5668\u548c\u6781\u6027\u9009\u62e9\uff0c\u5269\u4e0b\u7684\u4e0d\u7528\u5199\u3002\r\n\tTIM_ICInitTypeDef TIM_ICInitStruture;\r\n\t\/* \u56e0\u4e3a\u7ed3\u6784\u4f53\u662f\u4e0d\u5b8c\u6574\u7684\uff0c\u4e3a\u4e86\u9632\u6b62\u7ed3\u6784\u4f53\u51fa\u73b0\u4e0d\u786e\u5b9a\u7684\u503c\u53ef\u80fd\u4f1a\u9020\u6210\u7684\u95ee\u9898\uff0c\r\n\t\u6211\u4eec\u6700\u597d\u4f7f\u7528StrucInit\u7ed9\u7ed3\u6784\u4f53\u8d4b\u4e00\u4e2a\u521d\u59cb\u503c\u3002*\/\r\n\tTIM_ICStructInit(&amp;TIM_ICInitStruture);\r\n\t\/\/\u9009\u62e9\u901a\u9053\uff0c\u9009\u62e9TIM3\u7684\u901a\u90531.\r\n\tTIM_ICInitStruture.TIM_Channel=TIM_Channel_1;\r\n\t\/\/\u914d\u7f6e\u8f93\u5165\u6355\u83b7\u7684\u6ee4\u6ce2\u5668\uff0c\u8303\u56f4\u662f0X0~0XF\u3002\u8d8a\u5927\u6ee4\u6ce2\u6548\u679c\u8d8a\u597d\u3002\r\n\tTIM_ICInitStruture.TIM_ICFilter=0XF;\r\n\t\/*\u8fb9\u6cbf\u68c0\u6d4b\u3001\u6781\u6027\u9009\u62e9\u3002\u6211\u4eec\u9009\u62e9\u4e0a\u5347\u6cbf\u89e6\u53d1\u3002\r\n\t\u6211\u4eec\u8bf4\u8fc7\uff0c\u8fd9\u91cc\u7684\u4e0a\u5347\u6cbf\u5e76\u4e0d\u4ee3\u8868\u4e0a\u5347\u6cbf\u6709\u6548\uff0c\u56e0\u4e3a\u7f16\u7801\u5668\u63a5\u53e3\u59cb\u7ec8\u90fd\u662f\u4e0a\u5347\u6cbf\u3001\u4e0b\u964d\u6cbf\u90fd\u6709\u6548\u7684\u3002\r\n\t\u8fd9\u91cc\u7684\u4e0a\u5347\u6cbf\u53c2\u6570\u4ee3\u8868\u7684\u662f\u9ad8\u4f4e\u7535\u5e73\u6781\u6027\u4e0d\u53cd\u8f6c\u3002\u5176\u5b9e\u8fd9\u91cc\u7684\u6781\u6027\u53c2\u6570\u7b49\u4f1a\u6211\u4eec\u914d\u7f6e\u7f16\u7801\u5668\u63a5\u53e3\u7684\r\n\t\u65f6\u5019\u4e5f\u6709\uff0c\u5c5e\u4e8e\u91cd\u590d\u914d\u7f6e\u4e86\uff0c\u8fd9\u91cc\u8fd9\u4e2a\u5176\u5b9e\u4e5f\u53ef\u4ee5\u5220\u6389\u3002*\/\r\n\tTIM_ICInitStruture.TIM_ICPolarity=TIM_ICPolarity_Rising;\r\n\tTIM_ICInit(TIM3,&amp;TIM_ICInitStruture);\/\/\u8fd9\u6837\u901a\u90531\u5c31\u914d\u7f6e\u597d\u4e86\r\n\t\/\/\u6211\u4eec\u63a5\u7740\u914d\u7f6e\u901a\u90532\uff0c\u548c\u901a\u90531\u7684\u903b\u8f91\u4e00\u6837\u3002\r\n\tTIM_ICInitStruture.TIM_Channel=TIM_Channel_2;\r\n\tTIM_ICInitStruture.TIM_ICFilter=0XF;\r\n\tTIM_ICInitStruture.TIM_ICPolarity=TIM_ICPolarity_Rising;\r\n\tTIM_ICInit(TIM3,&amp;TIM_ICInitStruture);\r\n\t\r\n\t\/\/\u914d\u7f6e\u7f16\u7801\u5668\u63a5\u53e3\r\n\tTIM_EncoderInterfaceConfig(TIM3,TIM_EncoderMode_TI12,TIM_ICPolarity_Rising,TIM_ICPolarity_Rising);\r\n\r\n\t\r\n\t\/\/\u4f7f\u80fd\u5b9a\u65f6\u5668\r\n\tTIM_Cmd(TIM3,ENABLE);\r\n\r\n}\r\n\r\n\/\/\u8fd4\u56deTIM3\u8ba1\u6570\u5668\u7684\u503c\r\nuint16_t Encoder_Get()\r\n{\r\n\treturn TIM_GetCounter(TIM3);\r\n}<\/code><\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>\u672c\u5957\u4ef6\u4f7f\u7528\u7684\u7f16\u7801\u5668\u662f\u6709\u8fd9\u4e2a\u6bb5\u843d\u611f\u7684\uff0c\u6bcf\u8f6c\u4e00\u683c\uff0c\u5b83\u8f93\u51fa\u7684\u6ce2\u5f62\u5b9e\u9645\u4e0a\u662f\u8fd9\u6837\u7684\uff1a<img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-687\" src=\"https:\/\/aoofoo.com\/wp-content\/uploads\/2024\/07\/1-154.png\" alt=\"\" width=\"197\" height=\"119\" \/>\uff0cA\u3001B\u76f8\u5404\u51fa\u73b0\u4e00\u4e2a\u4e0b\u964d\u6cbf\u548c\u4e0a\u5347\u6cbf\uff0c\u6240\u4ee5\u8ba1\u6b21\u603b\u5171\u52a0\u4e864\u6b21\uff0c\u5f53\u7136\u5982\u679c\u4f60\u662f\u7535\u673a\u7684\u7f16\u7801\u5668\uff0c\u90a3\u5c31\u4e0d\u4f1a\u6709\u8fd9\u4e2a\u6bb5\u843d\u611f\u4e86\u3002<\/p>\n<p>\u4e0a\u8ff0\u4ee3\u7801\u6211\u4eec\u4ee3\u5165\u5230\u5b9e\u7269\u4e2d\uff0c\u4f1a\u53d1\u73b0\u65cb\u8f6c\u7f16\u7801\u5668\u6b63\u8f6c\uff0cCNT\u7684\u503c\u6b63\u5e38\u589e\u52a0\uff0c\u4f46\u53cd\u8f6c\uff0c\u4f1a\u51fa\u73b065535\uff0c\u8fd9\u65f6\u6211\u4eec\u5c31\u9700\u8981\u7528\u5230\u4e4b\u524d\u6240\u8bf4\u7684\u8865\u7801\u5c0f\u6280\u5de7\uff0c\u628auint16_t\u7684\u7c7b\u578b\u5f3a\u8f6c\u6210int16_t\uff0c\u8fd9\u6837\u5c31\u628a65535\u5f3a\u8f6c\u6210-1\u4e86\u3002\uff08STM32\u662f16\u4f4d\u7cfb\u7edf\uff0c\u6240\u4ee5-1\u7684\u8865\u7801\u6b63\u597d\u662f65535\uff09<\/p>\n<p>\u8868\u73b0\u5728\u4ee3\u7801\u4e0a\u5c31\u662f\uff1a<\/p>\n<pre class=\"corepress-code-pre\"><code>\/\/\u8fd4\u56deTIM3\u8ba1\u6570\u5668\u7684\u503c\r\nint16_t Encoder_Get()\r\n{\r\n\treturn TIM_GetCounter(TIM3);\r\n}<\/code><\/pre>\n<p>\u628a\u8fd4\u56de\u503c\u5f3a\u8f6c\u6210\u4e86int16_t\u7c7b\u578b\u7684\u6709\u7b26\u53f7\u6570\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>\u63a5\u4e0b\u6765\u6211\u4eec\u53ef\u4ee5\u518d\u6765\u7814\u7a76\u4e00\u4e0b\u6781\u6027\u7684\u95ee\u9898\uff0c\u5982\u679c\u8fd9\u4e2a\u65b9\u5411\u548c\u4f60\u60f3\u8981\u7684\u4e0d\u4e00\u81f4\u7684\u8bdd\uff0c\u53ef\u4ee5\u4fee\u6539\u4e00\u4e0b\u6781\u6027\u3002<\/p>\n<p>\u5728\u786c\u4ef6\u5c42\u9762\u4e0a\uff0c\u6211\u4eec\u53ef\u4ee5\u76f4\u63a5\u628aA\u3001B\u76f8\u7684\u5f15\u811a\u6362\u4e00\u4e0b\u4f4d\u7f6e\u3002<\/p>\n<p>\u5728\u8f6f\u4ef6\u5c42\u9762\u4e0a\uff0c\u6211\u4eec\u53ef\u4ee5\u628a\u4efb\u610f\u4e00\u4e2a\u6781\u6027\u53cd\u8f6c\u4e00\u4e0b\uff0c\u65b9\u5411\u5c31\u4f1a\u53cd\u8fc7\u6765\u3002\u5982\u679c\u4e24\u4e2a\u6781\u6027\u90fd\u53cd\u8f6c\uff0c\u90a3\u6781\u6027\u8fd8\u662f\u4f1a\u4fdd\u6301\u4e0d\u53d8\u3002<\/p>\n<pre class=\"corepress-code-pre\"><code>TIM_EncoderInterfaceConfig(TIM3,TIM_EncoderMode_TI12,TIM_ICPolarity_Rising,TIM_ICPolarity_Falling);<\/code><\/pre>\n<p>&nbsp;<\/p>\n<h2>\u7f16\u7801\u5668\u6d4b\u901f\u4ee3\u7801<\/h2>\n<p>\u5982\u679c\u6211\u4eec\u60f3\u7528\u8fd9\u4e2a\u7f16\u7801\u5668\u6765\u6d4b\u901f\u7684\u8bdd\uff0c\u5c31\u53ef\u4ee5\u5728\u56fa\u5b9a\u7684\u95f8\u95e8\u65f6\u95f4\uff0c\u8bfb\u4e00\u6b21CNT\uff0c\u7136\u540e\u628aCNT\u6e05\u96f6\u3002<\/p>\n<pre class=\"corepress-code-pre\"><code>\/\/\u8bfb\u53d6CNT\uff0c\u6e05\u96f6CNT\u3002\r\nint16_t Encoder_Get()\r\n{\r\n\tint16_t Temp;\r\n\tTemp = TIM_GetCounter(TIM3);\r\n\tTIM_SetCounter(TIM3,0);\r\n\treturn Temp;\r\n}<\/code><\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7f16\u7801\u5668\u63a5\u53e3\u6d4b\u901f\u63a5\u7ebf\u56fe \u53c2\u8003\u5f15\u811a\u5b9a\u4e49\u8868\uff0cPA6\u548cPA7\u662fTIM3\u7684\u901a\u90531\u548c\u901a\u90532\uff0c\u6211\u4eec\u8ba1\u5212\u7528TIM3\u63a5\u7f16\u7801\u5668\u3002  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-680","post","type-post","status-publish","format-standard","hentry","category-stm32"],"_links":{"self":[{"href":"https:\/\/aoofoo.com\/index.php\/wp-json\/wp\/v2\/posts\/680","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/aoofoo.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/aoofoo.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/aoofoo.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/aoofoo.com\/index.php\/wp-json\/wp\/v2\/comments?post=680"}],"version-history":[{"count":8,"href":"https:\/\/aoofoo.com\/index.php\/wp-json\/wp\/v2\/posts\/680\/revisions"}],"predecessor-version":[{"id":691,"href":"https:\/\/aoofoo.com\/index.php\/wp-json\/wp\/v2\/posts\/680\/revisions\/691"}],"wp:attachment":[{"href":"https:\/\/aoofoo.com\/index.php\/wp-json\/wp\/v2\/media?parent=680"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/aoofoo.com\/index.php\/wp-json\/wp\/v2\/categories?post=680"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/aoofoo.com\/index.php\/wp-json\/wp\/v2\/tags?post=680"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}