5 changed files with 1090 additions and 93 deletions
21
MDK-ARM/LWIP.uvguix.29643
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
1088
MDK-ARM/LWIP.uvprojx
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
@ -1,27 +1,37 @@ |
|||||
#include "encoder.h" |
#include "encoder.h" |
||||
|
|
||||
|
#include "zboard.h" |
||||
#include <stdio.h> |
#include <stdio.h> |
||||
|
|
||||
static int Direction; |
static int Direction; |
||||
static int CaptureNumber; |
static int CaptureNumber; |
||||
|
|
||||
|
static encoder_t m_uarts[] = { |
||||
|
{&camera_encoder, TIM_CHANNEL_1 | TIM_CHANNEL_2}, // 相机编码器 |
||||
|
{&driven_encoder_gear, TIM_CHANNEL_1 | TIM_CHANNEL_2} // 从动编码器 |
||||
|
}; |
||||
|
|
||||
void encoder_start(void) |
void encoder_start(void) |
||||
{ |
{ |
||||
/* 不开启会导致程序无法启动,原因未知 */ |
/* 不开启会导致程序无法启动,原因未知 */ |
||||
HAL_TIM_Encoder_Start(&htim4, TIM_CHANNEL_1 | TIM_CHANNEL_2); |
|
||||
|
HAL_TIM_Encoder_Start(&camera_encoder, TIM_CHANNEL_1 | TIM_CHANNEL_2); |
||||
|
HAL_TIM_Encoder_Start(&driven_encoder_gear, TIM_CHANNEL_1 | TIM_CHANNEL_2); |
||||
} |
} |
||||
void encoder_stop(void) |
void encoder_stop(void) |
||||
{ |
{ |
||||
HAL_TIM_Encoder_Stop(&htim4, TIM_CHANNEL_1 | TIM_CHANNEL_2); |
|
||||
|
HAL_TIM_Encoder_Stop(&camera_encoder, TIM_CHANNEL_1 | TIM_CHANNEL_2); |
||||
|
HAL_TIM_Encoder_Stop(&driven_encoder_gear, TIM_CHANNEL_1 | TIM_CHANNEL_2); |
||||
} |
} |
||||
|
|
||||
void encoder_read_printf(void) |
void encoder_read_printf(void) |
||||
{ |
{ |
||||
Direction = __HAL_TIM_IS_TIM_COUNTING_DOWN(&htim4); // 读取电机转动方向 |
|
||||
CaptureNumber = (short)__HAL_TIM_GET_COUNTER(&htim4); // 读取编码器数据 |
|
||||
__HAL_TIM_GET_COUNTER(&htim4) = 0; // 计数器值重新置位 |
|
||||
if (CaptureNumber != 0) |
|
||||
|
for (uint8_t i = 0; i < (sizeof(m_uarts) / sizeof(encoder_t)); i++) |
||||
{ |
{ |
||||
printf("Direction is %d,CaptureNumber is %d\r\n", Direction, CaptureNumber); |
|
||||
|
Direction = __HAL_TIM_IS_TIM_COUNTING_DOWN(m_uarts[i].tim_handler); // 读取电机转动方向 |
||||
|
CaptureNumber = (short)__HAL_TIM_GET_COUNTER(m_uarts[i].tim_handler); // 读取编码器数据 |
||||
|
__HAL_TIM_GET_COUNTER(m_uarts[i].tim_handler) = 0; // 计数器值重新置位 |
||||
|
if (CaptureNumber != 0) |
||||
|
{ |
||||
|
printf("Encoder number:%d,Direction is %d,CaptureNumber is %d\r\n", i, Direction, CaptureNumber); |
||||
|
} |
||||
} |
} |
||||
} |
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue