⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 motor_state_check.c

📁 这是一个在电动机运行状态的逻辑运算中常用的状态检测原理的例程。它根据电动机负载的大小和外部开关状态共同判断当前电动机的状态。
💻 C
📖 第 1 页 / 共 3 页
字号:
                      startcount_permit=0;
                      start_counter=0;
                      reset_change=1;                   //复位标志置1
                      start_fail=0x00;                  //启动失败清零
                      jitter_counter=0;                 //去抖定时器
                      run_count_permit=0x00;            //运行计数器屏蔽
                      return;
                  }

				  //正转位置无效&&Imax>=0.25In=停止错误态
				  if((motor_positive_posit==0x00)&&(i_over>=YX*In)){
                     motor_state=0x88;  //停止错误态
                     start_counter=0;
                     start_fail=0x00;      //启动失败清零
                     jitter_counter=0;     //去抖定时器
                     run_count_permit=0x00;//运行计数器屏蔽
				  }

				  //正转位置无效&&Imax<0.25In=停止态
                  if((motor_positive_posit==0x00)&&(i_over<YX*In)) 
                    {
                      motor_state=0x00;
                      start_counter=0;
                      start_fail=0x00;                  //启动失败清零
                      jitter_counter=0;                 //去抖定时器
                      run_count_permit=0x00;            //运行计数器屏蔽
                      return;
                    }
				}
				break;
      case(0x01):  //正启动
                {
                  //如果启动失败,不进行以下程序处理,知道启动失败的处理完成(start_fail==0x00)
                  if(start_fail==0xff)   //启动失败,出口返回
                    {
                      motor_state=0x00;
                      start_counter=0;
                      startcount_permit=0;    
                      return;            //返回
                    }

                  if(i_over<YX*In) //如果Imax<=0.25In
                    {
                      jitter_counter=jitter_counter+0.000833; //去抖定时器
                      if(jitter_counter>=start_time) //如果一直小于0.25In,进入停止态
                        {
                          motor_state=0x00;    //回到停止态
                          start_counter=0;
                          jitter_counter=0;                 //去抖定时器
                          startcount_permit=0;
                          start_fail=0xff;   //启动失败,出口返回
                          return;
                        }
                    }
                  else   //如果Imax>0.25In,去抖时间置零
                    {
                      jitter_counter=0;                 //去抖定时器
                    }

                  start_counter=start_counter+0.000833; //延时833us
                  if(start_counter>=start_time)
                    {
                      motor_state=0x02;                 //正运行态
                      start_fail=0x00;                  //启动失败清零
                      start_counter=0;
                      jitter_counter=0;                 //去抖定时器
                      startcount_permit=0;
                    }
                }break;
      case(0x02):  //正运行态
                {
                  //正转位置有效&&Imax>=0.25In=电机正常运行
				  if((motor_positive_posit==0xff)&&(i_over>YX*In)){
                      motor_state=0x02;  //正运行状态
                      start_counter=0;
                      startcount_permit=0;
                      if(err_counter>240) {err_state=0x00; err_counter=0x00;}//电机从异常运行态返回
                      else                {err_state=0xaa; err_counter=0x00;}//电机一直处于正常运行态,计数器清零
                      return;
				  }
				  
				  //正转位置无效&&Imax<0.25In=进入停车态
                  if((motor_positive_posit==0x00)&&(i_over<YX*In))
                    {
                      motor_state=0x03;  //正停车态
                      start_counter=0;
                      startcount_permit=0;
                      err_state=0x00;  //清报警继电器RL3
                      err_counter=0x00;
                      return;
                    }

                  //======================================================================
                  //在以上状态以外的状态,电机异常运行
                  err_counter++;
                  if(err_counter>=240) //如果连续10个周波均出现辅助触点失灵的问题
                    {
                      err_state=0xff;  //运行界面RUN to ERR,发告警信号,RL3
                      err_counter=241; //防止err_counter溢出,保持电机运行错误的标志,当电机进入正常态时返回
                    }
                  else
                    {
                      err_state=0xaa;  //电机处于正常运行态
                    }
                }break;
      case(0x03):  //正停车态
                {
                  start_counter=start_counter+0.000833;
                  if(start_counter>=stop_time){   //延时时间到,进入停止态
					  //正转位置无效&&Imax<0.1In=停止态
                      if((motor_positive_posit==0x00)&&(i_over<TC*In)){
                          //如果正常停车进入停车态
                          motor_state=0x00;   //停止态
                          start_counter=0;
                          startcount_permit=0;
                      }
					  //正转位置无效&&0.1In<=Imax<0.25In=停车失败
                      else if((motor_positive_posit==0x00)&&(i_over>TC*In)&&(i_over<=YX*In)){  //否则进入停车错误态
                          motor_state=0x88;   //停车错误态
                          start_counter=0;
                          start_fail=0x00;                  //启动失败清零
                          jitter_counter=0;                 //去抖定时器
                      }
					  else{//返回运行态
                          motor_state=0x02;                 //正运行态
                          start_fail=0x00;                  //启动失败清零
                          start_counter=0;
                          jitter_counter=0;                 //去抖定时器
                          startcount_permit=0;
					  }
                  }
                }break;
      case(0x88):  //停车错误态
                {
                  err_state=0xff;   //报警继电器动作
                  //正转继电器无效&&Imax<0.1In=停止态
                  if((motor_positive_posit==0x00)&&(i_over<TC*In))
                    {
                      motor_state=0x00;   //停止态
                      err_state=0x00;     //返回告警继电器
                      start_counter=0;
                      startcount_permit=0;
                    }
                }break;
      default:  //如果不是以上集中状态,则重新判断电机所处的状态
                {
                  Judge_MotorState_Single();
                }
    }

}


//=====================================
//该部分未改写
//该部分要根据状态对应表改写
//motor_state
//0x00=停止,0x88=停车错误态(停车错误态的处理未写)
//0x01=正启动,0x02=正运行,0x03=正停车
//0xff=反启动,0xfe=反运行,0xfd=反停车
//=====================================
void Judge_MotorState_Double(void)    //电机工作在双向方式时判断电机状态,在上电时候和程序平跑飞时用
{
  unsigned char temp_chr=0x00;

  if(motor_positive_posit==0xff) temp_chr=0x04;                //正转位置有效
  if(motor_negative_posit==0xff) temp_chr=temp_chr|0x02;       //反转位置有效
  if(i_over>=YX*In)             temp_chr=temp_chr|0x01;        //电流大于等于1/4额定

  switch(temp_chr)
    {
      case(0x00):  //正转位置无效&&反转位置无效&&Imax<0.25In:停止态
          {
            motor_state=0x00;
            motor_oper=0xaa;
            startcount_permit=0;
            start_counter=0;
          }break;
      case(0x01):  //正转位置无效&&反转位置无效&&Imax>0.25In:停止态
          {
            motor_state=0x00;
            motor_oper=0xaa;
            startcount_permit=0;
            start_counter=0;
          }break;
      case(0x02): //正转位置无效&&反转位置有效&&Imax<=0.25In:反向运行
          {
            motor_state=0xfe;
            motor_oper=0xaa;
            startcount_permit=0;
            start_counter=0;
          }break;
      case(0x03): //正转位置无效&&反转位置有效&&Imax>0.25In:反向运行
          {
            motor_state=0xfe;
            motor_oper=0xaa;
            startcount_permit=0;
            start_counter=0;
          }break;
      case(0x04): //正转位置有效&&反转位置无效&&Imax<=0.25In:正向运行
          {
            motor_state=0x02;
            motor_oper=0xaa;
            startcount_permit=0;
            start_counter=0;
          }break;
      case(0x05): //正转位置有效&&反转位置无效&&Imax>0.25In:正向运行
          {
            motor_state=0x02;
            motor_oper=0xaa;
            startcount_permit=0;
            start_counter=0;
          }break;
      case(0x06): //正转位置有效&&反转位置有效&&Imax<=0.25In:停止态错误态
          {
            motor_state=0x88;  //???
            motor_oper=0xaa;
            startcount_permit=0;
            start_counter=0;
          }break;
      case(0x07): //正转位置有效&&反转位置有效&&Imax>0.25In:停止错误态
          {
            motor_state=0x88;  //???
            motor_oper=0xaa;
            startcount_permit=0;
            start_counter=0;
          }break;
      default: break;
   }
}

void Judge_MotorState_Single(void)    //电机工作在单向方式时判断电机状态,在上电时候和程序平跑飞时用
{
  unsigned char temp_chr=0x00;

  if(motor_positive_posit==0xff) temp_chr=0x02;             //正转位置有效
  if(i_over>=YX*In)             temp_chr=temp_chr|0x01;     //电流大于等于1/4额定

  switch(temp_chr)
    {
      case(0x00):  //正转位置无效&&Imax<0.25In:停止态
          {
            motor_state=0x00;
            motor_oper=0xaa;
            startcount_permit=0;
            start_counter=0;
          }break;
      case(0x01):  //正转位置无效&&Imax>=0.25In:停止态
          {
            motor_state=0x00;
            motor_oper=0xaa;
            startcount_permit=0;
            start_counter=0;
          }break;
      case(0x02):  //正转位置有效&&Imax<0.25In:正运行态
          {
            motor_state=0x02;
            motor_oper=0xaa;
            startcount_permit=0;
            start_counter=0;
          }break;
      case(0x03): //正转位置有效&&Imax>=0.25In:正运行态
          {
            motor_state=0x02;
            motor_oper=0xaa;
            startcount_permit=0;
            start_counter=0;
          }break;
      default: break;
   }
}

void RESET_ADD(void)  //复位次数加1
{
  if(reset_change==1)
    {
      reset_sum++;                      //复位次数(启动次数)加1
      if(reset_sum==9999) reset_sum=0;  //如果启动次数大于9999置0
      Write_FRAM_SUM();                 //修改铁电数据
      reset_change=0;
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -