TA的每日心情 | 无聊 2018-11-16 10:48 |
---|
签到天数: 2 天 连续签到: 1 天 [LV.1]初来乍到
|
电机测速仪组成:ST188红外传感器+555施密特触发器+STM32开发板+LCD1602液晶显示屏
基本原理就是用定时器捕获功能测量测速脉冲的周期,然后转化为频率和转速。
主程序:
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration----------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* Configure the system clock */
SystemClock_Config();
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_USART2_UART_Init();
MX_TIM2_Init();
/* USER CODE BEGIN 2 */
LCDCOM(0x38);
LCDCOM(0x0c);
LCDCOM(0x06);
LCDCOM(0x01);
HAL_TIM_Base_Start_IT(&htim2);
HAL_TIM_IC_Start_IT(&htim2, TIM_CHANNEL_1);
__HAL_TIM_ENABLE_IT(&htim2, TIM_IT_TRIGGER);
if(HAL_TIM_IC_Start_IT(&htim2, TIM_CHANNEL_1) != HAL_OK)
{
/* Starting Error */
Error_Handler();
}
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
HAL_Delay(1200);
LCDCOM(0x01);
HAL_Delay(10);
LCDCOM(0x80);
if(status)
{
status = 0;
printf(" %6.0f RPM\n",8000000.0/uwIC2Value2*60);
LCDCOM(0xc0);
printf(" RUN \n");
if(uwIC2Value2<2)
{
LCDCOM(0xc0);
printf(" HIGH \n");
}
}
else
{
LCDCOM(0x80);
printf(" 0 RPM \n");
LCDCOM(0xc0);
printf(" STOP \n");
}
// LCDCOM(0x18);
}
/* USER CODE END 3 */
}
定时器触发捕获回调函数 :
void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim)
{
// HAL_GPIO_TogglePin(LD2_GPIO_Port, LD2_Pin);
uwIC2Value2= HAL_TIM_ReadCapturedValue(htim, TIM_CHANNEL_1);
status = 1;
}
|
IMAG1859_1.jpg (1.31 MB, 下载次数: 17)
2
|
|