void STM32FrequencyChannel::Enable (bool enable)
{
    if (enable)
    {
        __HAL_TIM_SET_COMPARE (timer.handle, channel,
                               __HAL_TIM_GetCompare (timer.handle, channel) +
                               reloadValue);

        HAL_TIM_OC_Start_IT (timer.handle, channel);
    }
    else
    {
        HAL_TIM_OC_Stop_IT (timer.handle, channel);
    }
}
예제 #2
0
// 输出比较 回调函数
void HAL_TIM_OC_DelayElapsedCallback(TIM_HandleTypeDef *htim)
{
  uint16_t delay_new = 0;
  // TIM4
  if (htim->Instance == TIM4) {
    // 1
    // 排烟风机 通道
    if(htim->Channel == HAL_TIM_ACTIVE_CHANNEL_1) {
      // 排烟风机 delay_on, 打开输出
      // 输出:On
      HAL_GPIO_WritePin(PORT_SCR, SCR0_smoke, GPIO_PIN_RESET);
      HAL_TIM_OC_Stop_IT( &htim4, TIM_CHANNEL_1);

      // 启动波峰
      if (is_lower_blow) {
        is_lower_blow = false;
        delay_new = __HAL_TIM_GET_COMPARE(&htim4, TIM_CHANNEL_1);
        __HAL_TIM_SET_COMPARE(&htim4, TIM_CHANNEL_1, delay_new + 10000 - 1);
        HAL_TIM_OC_Start_IT( &htim4, TIM_CHANNEL_1); 
      }
      
      //设置停止时间
      delay_new = __HAL_TIM_GET_COMPARE(&htim1, TIM_CHANNEL_1);
      __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, delay_new + uS_DELAY_OFF);
      
      // 启动定时器
      HAL_TIM_OC_Start_IT( &htim1, TIM_CHANNEL_1); 
    }
    
    // 2
    // 循环风机通道
    if(htim->Channel == HAL_TIM_ACTIVE_CHANNEL_2) {      
      // 循环风机 delay_on, 打开输出
      // 输出:On
      HAL_GPIO_WritePin(PORT_SCR, SCR1_exchange, GPIO_PIN_RESET);
      HAL_TIM_OC_Stop_IT( &htim4, TIM_CHANNEL_2);
      
      // 启动波峰
      if (is_lower_exchange) {
        is_lower_exchange = false;
        delay_new = __HAL_TIM_GET_COMPARE(&htim4, TIM_CHANNEL_2);
        __HAL_TIM_SET_COMPARE(&htim4, TIM_CHANNEL_2, delay_new + 10000 - 1);
        HAL_TIM_OC_Start_IT( &htim4, TIM_CHANNEL_2); 
        
      }
      //设置停止时间
      uint16_t delay_new = __HAL_TIM_GET_COMPARE(&htim1, TIM_CHANNEL_2);
      __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_2, delay_new + uS_DELAY_OFF);
      // 启动定时器
      HAL_TIM_OC_Start_IT( &htim1, TIM_CHANNEL_2);      
    }
    
    // 3
    // 送料电机 通道
    if(htim->Channel == HAL_TIM_ACTIVE_CHANNEL_3) {
      HAL_GPIO_WritePin(PORT_SCR, SCR2_feed, GPIO_PIN_RESET);      
      HAL_TIM_OC_Stop_IT( &htim4, TIM_CHANNEL_3);
      
      // 启动波峰
      if (is_lower_feed) {
        is_lower_feed = false;
        uint16_t delay_new = __HAL_TIM_GET_COMPARE(&htim4, TIM_CHANNEL_3);
        __HAL_TIM_SET_COMPARE(&htim4, TIM_CHANNEL_3, delay_new + 10000 - 1);
        HAL_TIM_OC_Start_IT( &htim4, TIM_CHANNEL_3); 
        
      }
      //设置停止时间
      uint16_t delay_new = __HAL_TIM_GET_COMPARE(&htim1, TIM_CHANNEL_3);
      __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_3, delay_new + uS_DELAY_OFF);
      
    }
    
  }  
  // TIM1  
  // 延时1ms关闭触发
  if (htim->Instance == TIM1) {
    // 1
    if(htim->Channel == HAL_TIM_ACTIVE_CHANNEL_1) {
      HAL_GPIO_WritePin(PORT_SCR, SCR0_smoke, GPIO_PIN_SET);
      HAL_TIM_OC_Stop_IT( &htim1, TIM_CHANNEL_1);
    }
    
    // 2
    if(htim->Channel == HAL_TIM_ACTIVE_CHANNEL_2) {
      // 输出 循环:Off
      HAL_GPIO_WritePin(PORT_SCR, SCR1_exchange, GPIO_PIN_SET);
      HAL_TIM_OC_Stop_IT( &htim1, TIM_CHANNEL_2);
    }
    
    // 3
    if(htim->Channel == HAL_TIM_ACTIVE_CHANNEL_3) {
      // 输出 送料: Off
      HAL_GPIO_WritePin(PORT_SCR, SCR2_feed, GPIO_PIN_SET);
      HAL_TIM_OC_Stop_IT( &htim1, TIM_CHANNEL_3);
    }
    
  }  // TIM1
 //
  
}
예제 #3
0
void stopsyncpulse(void){
	//Stops pulsing for VD_IN
	HAL_TIM_Base_Stop_IT(&htim8);
	HAL_TIM_OC_Stop_IT(&htim8,TIM_CHANNEL_1);
	
}