标签:tar ESS 图片 概述 star free ++ nta 白炽灯
软件程序使用FreeRTOS,硬件中断(上升沿下降沿)接收220V过零检测信号。
过零检测中断处理
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
switch(GPIO_Pin)
{
case GPIO_PIN_8:
if(control_task_run)
{
if(DevInfo.LedSta == Adjust)
{
if(DevInfo.AdjustMessage.Adjust == 0)
{
HAL_GPIO_WritePin(GPIOA, OUT_Pin, GPIO_PIN_SET);
}
else
{
if(PAin(8) == 0)
{
TIM3->ARR = DevInfo.AdjustMessage.Adjust * 100 + 2;
HAL_TIM_Base_Start_IT(&htim3);
}
else
{
HAL_GPIO_WritePin(GPIOA, OUT_Pin, GPIO_PIN_SET);
}
}
}
}
break;
default:
break;
}
}
因BL0937返回的是脉冲信号,所以开个定时器采集,部分程序如下:
void Tim2Callback(TIM_HandleTypeDef *htim)
{
TIM2Ch3Cnt++;
TIM2Ch4Cnt++;
}
void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim)
{
static uint32_t TIM2CH3CapturedValue[2] = {0};
static uint32_t TIM2CH4CapturedValue[2] = {0};
static uint8_t TIM2CH3Sta = 0;
static uint8_t TIM2CH4Sta = 0;
if(TIM2 == htim->Instance)
{
if(htim->Channel == HAL_TIM_ACTIVE_CHANNEL_3)
{
if(TIM2CH3Sta == 0)
{
TIM2Ch3Cnt = 0;
TIM2CH3CapturedValue[0] = HAL_TIM_ReadCapturedValue(&htim2,TIM_CHANNEL_3);
TIM2CH3Sta++;
}
else
{
TIM2CH3CapturedValue[1] = HAL_TIM_ReadCapturedValue(&htim2,TIM_CHANNEL_3);
TIM2CH3Sta = 0;
CF_CNT = 0xFFFF * TIM2Ch3Cnt + TIM2CH3CapturedValue[1] - TIM2CH3CapturedValue[0];
}
}
else if(htim->Channel == HAL_TIM_ACTIVE_CHANNEL_4)
{
if(TIM2CH4Sta == 0)
{
TIM2Ch4Cnt = 0;
TIM2CH4CapturedValue[0] = HAL_TIM_ReadCapturedValue(&htim2,TIM_CHANNEL_4);
TIM2CH4Sta++;
}
else
{
TIM2CH4CapturedValue[1] = HAL_TIM_ReadCapturedValue(&htim2,TIM_CHANNEL_4);
TIM2CH4Sta = 0;
CF1_CNT = 0xFFFF * TIM2Ch4Cnt + TIM2CH4CapturedValue[1] - TIM2CH4CapturedValue[0];
}
}
}
}
标签:tar ESS 图片 概述 star free ++ nta 白炽灯
原文地址:https://www.cnblogs.com/c951/p/12785682.html