|
編碼器計(jì)數(shù)主要是對(duì)單片機(jī)的定時(shí)器經(jīng)行配置,然后是讀取得到的值對(duì)其進(jìn)行轉(zhuǎn)換為速度等
屏幕截圖 2021-08-11 092140.png (74.34 KB, 下載次數(shù): 39)
下載附件
2021-8-11 09:24 上傳
- #include "sys.h"
- #include "delay.h"
- #include "usart.h"
- #include "encoder.h"
- #include "timer.h"
- #include "pwm.h"
- #include "motor.h"
- #include "led.h"
- #include "key.h"
- int Encoder_Left=0 ,Encoder_Right=0; //左右編碼器的脈沖計(jì)數(shù)
- float speed_Left=0 ,speed_Right=0;
-
- int main(void)
- {
- delay_init(); //延時(shí)函數(shù)初始化
- uart_init(9600); //串口初始化為9600
- Encoder_Init_TIM3();
- Encoder_Init_TIM4();
- AIN_Init();
- KEY_Init();
- LED_Init();
- TIM1_PWM_Init(899,8);
- TIM5_Int_Init(99,7199); // 0.01S ((arr+1)(psc+1))/72000000
- while(1)
- {
- TIM_SetCompare1(TIM1,850);
- TIM_SetCompare4(TIM1,500);
- zuozhuan();
- /* 轉(zhuǎn)速(1秒鐘轉(zhuǎn)多少圈)=單位時(shí)間內(nèi)的計(jì)數(shù)值/總分辨率*時(shí)間系數(shù) */
- speed_Left=Encoder_Left/0.01*0.000181245;
- speed_Right=Encoder_Right/0.01*0.000181245;
- printf("左輪編碼器脈沖數(shù)為: %d\r\n",Encoder_Left);
- printf("右輪編碼器脈沖數(shù)為: %d\r\n",Encoder_Right);
- printf("speed_Left: %f\r\n",speed_Left);
- printf("speed_Right: %f\r\n",speed_Right);
-
- }
-
- }
-
-
復(fù)制代碼
代碼:
編碼器.7z
(194.87 KB, 下載次數(shù): 41)
2021-8-11 15:57 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
|
評(píng)分
-
查看全部評(píng)分
|