標題: STM32F429ZG-TIM編碼器正交解碼模式程序 [打印本頁]

作者: tiger08    時間: 2019-5-28 08:45
標題: STM32F429ZG-TIM編碼器正交解碼模式程序
STM32F429ZG芯片,TIM3 正交解碼編碼器,可讀取編碼器的值及其方向

單片機源程序如下:
  1. /**
  2.   ******************************************************************************
  3.   * @文件名     : main.c
  4.   * @作者       : strongerHuang
  5.   * @版本       : V1.0.0
  6.   * @摘要       : 主函數(shù) - Demo軟件工程
  7.   ******************************************************************************/
  8. /*----------------------------------------------------------------------------
  9.   更新日志:
  10.   2017-12-19 V1.0.0:初始版本
  11.   ----------------------------------------------------------------------------*/
  12. /* 包含的頭文件 --------------------------------------------------------------*/
  13. #include "bsp.h"
  14. #include "bsp_timer.h"
  15. #include "bsp_usart.h"


  16. /************************************************
  17. 函數(shù)名稱 : System_Initializes
  18. 功    能 : 系統(tǒng)初始化
  19. 參    數(shù) : 無
  20. 返 回 值 : 無
  21. 作    者 : strongerHuang
  22. *************************************************/
  23. void System_Initializes(void)
  24. {
  25.   BSP_Initializes();
  26.   TIMER_Initializes();
  27.   USART_Initializes();
  28. }

  29. /************************************************
  30. 函數(shù)名稱 : main
  31. 功    能 : 主函數(shù)入口
  32. 參    數(shù) : 無
  33. 返 回 值 : int
  34. 作    者 : strongerHuang
  35. *************************************************/
  36. extern  uint32_t circle_count;

  37. int main(void)
  38. {
  39.   static uint32_t dir;
  40.   static uint32_t cnt = 30000;

  41.   System_Initializes();

  42.   while(1)
  43.   {
  44.     ENCODER_Read(&dir, &cnt);                    //讀取編碼數(shù)值, 并打印
  45.     printf("Dir = %X; circle = %d; Cnt = %d;\n", dir, circle_count, cnt);

  46.     LED_TOGGLE();                                //LED變化
  47.     TIMDelay_Nms(1);                           //TIM延時

  48.   }
  49. }
復制代碼

所有資料51hei提供下載:
STM32F4_TIM編碼器正交解碼模式.7z (738.52 KB, 下載次數(shù): 81)


作者: sym_cool    時間: 2019-8-20 10:32
學習一下,謝謝分享
作者: mick32    時間: 2022-4-6 02:11
Nice to see 32bit encoder code
Thank you




歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1