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

📄 p_motor_con.c

📁 基于Cortex-M3的全自动焊接机
💻 C
字号:
#include "motor.h"
#include "pwm.h"
#include "globaltype.h"
#include  "hw_ints.h"
#include  <interrupt.h>
#include  <hw_timer.h>
#include  <timer.h>
#include  "hw_uart.h"
#include  "uart.h"
#include  "systick.h"
#include "define.h"
#include "pwm_init.h"
#include  "sys_tick.h"
#include "define.h"

extern struct placed_relate_parm palced_magor[];
extern unsigned long timerloadvalue;


extern unsigned char TxData[];

unsigned char new_data_flag;
unsigned char Dirflag_Mor0 = 2;
unsigned char Dirflag_Mor1 = 2;
unsigned char Dirflag_Mor2 = 2;

extern void TxFIFOFill(void);
//void uart_printf(unsigned char motor_number);

//void clear(unsigned char motor);

extern void PID_adjust_speed(unsigned long ulStatus, unsigned char motor);

void  GPIO_Port_C_ISR (void)//PC
{  
  
    unsigned long ulStatus;
  
    static unsigned int motor1_old_value ;
    static unsigned int motor1_new_value ;
    
#ifdef dir 
    static unsigned char  DirStep = 0;
    static unsigned int Dir_T1;
    static unsigned int Dir_T2;
#endif
     
    motor1_old_value = motor1_new_value;//获取上一次timer数据
    motor1_new_value = TimerValueGet(TIMER0_BASE , TIMER_A);//读取本次timer数据

    ulStatus  =  GPIOPinIntStatus(Motor_Enco_PORT1 , true);      //  读取中断状态
    GPIOPinIntClear(Motor_Enco_PORT1 , ulStatus);                //  清除中断状态
    
    //实际速度值,应该只有单相测量
    if(ulStatus & Motor1_Enco_A)
    {
        palced_magor[0].real_timerunit = (timerloadvalue+(motor1_old_value-motor1_new_value))%timerloadvalue;
        palced_magor[0].not_normlation_timerunit = palced_magor[0].real_timerunit;
    }
    
    
  #define absolute_code
  #ifdef absolute_code
    if ( ulStatus & Motor1_Enco_A) //A相B相可以都触发中断
    { 
          if(Dirflag_Mor0==2)
          {
              Dirflag_Mor0 = palced_magor[0].dir;
          }
          
          if(Dirflag_Mor0==palced_magor[0].dir)
            palced_magor[0].absulotely_code++;
          else if((Dirflag_Mor0!=palced_magor[0].dir) && (Dirflag_Mor0!=2))
            palced_magor[0].absulotely_code--;
    }
  #endif
    PID_adjust_speed(ulStatus,0);
}


void  GPIO_Port_A_ISR (void)
{  
  
    unsigned long  ulStatus;
    
    static unsigned int motor2_old_value ;
    static unsigned int motor2_new_value ;
    
    motor2_old_value = motor2_new_value;//获取上一次timer数据
    motor2_new_value = TimerValueGet(TIMER0_BASE , TIMER_A);//读取本次timer数据
    
        
    ulStatus  =  GPIOPinIntStatus(Motor_Enco_PORT2 , true);      //  读取中断状态
    GPIOPinIntClear(Motor_Enco_PORT2 , ulStatus);                //  清除中断状态,重要
    
    if(ulStatus & Motor2_Enco_A)
    {
        palced_magor[1].real_timerunit = (timerloadvalue+(motor2_old_value-motor2_new_value))%timerloadvalue;
        palced_magor[1].not_normlation_timerunit = palced_magor[1].real_timerunit;
    }
    
  #define absolute_code
  #ifdef absolute_code
    if ( ulStatus & Motor2_Enco_A ) //A相B相可以都触发中断
    {
          if(Dirflag_Mor1==2)
          {
              Dirflag_Mor1 = palced_magor[1].dir;
          }
          
          if(Dirflag_Mor1==palced_magor[1].dir)
            palced_magor[1].absulotely_code++;
          else if((Dirflag_Mor1!=palced_magor[1].dir) && (Dirflag_Mor1!=2))
            palced_magor[1].absulotely_code--;
    }
  #endif
    PID_adjust_speed(ulStatus,1);

}


void  GPIO_Port_D_ISR (void)
{  
    unsigned long ulStatus;
      
    static unsigned int motor3_old_value;
    static unsigned int motor3_new_value;
    
    motor3_old_value = motor3_new_value;//获取上一次timer数据
    motor3_new_value = TimerValueGet(TIMER0_BASE , TIMER_A);//读取本次timer数据
    
    ulStatus  =  GPIOPinIntStatus(Motor_Enco_PORT3 , true);      //  读取中断状态
    GPIOPinIntClear(Motor_Enco_PORT3 , ulStatus);                //  清除中断状态
    
    if(ulStatus & Motor3_Enco_B)
    {
        palced_magor[2].real_timerunit = (timerloadvalue+(motor3_old_value-motor3_new_value))%timerloadvalue;
        palced_magor[2].not_normlation_timerunit = palced_magor[2].real_timerunit;

    }
#define absolute_code
#ifdef absolute_code
    if ( ulStatus & Motor3_Enco_B )          
    {
        if(Dirflag_Mor2==2)
          {
              Dirflag_Mor2 = palced_magor[2].dir;
          }
          
          if(Dirflag_Mor0==palced_magor[2].dir)
            palced_magor[2].absulotely_code++;
          else if((Dirflag_Mor2!=palced_magor[2].dir) && (Dirflag_Mor2!=2))
            palced_magor[2].absulotely_code--;
    }
#endif
    PID_adjust_speed(ulStatus,2);
}




⌨️ 快捷键说明

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