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

📄 bldc3_1.c

📁 TI公司28系列DSP控制无刷直流电机
💻 C
📖 第 1 页 / 共 2 页
字号:
 	pid1_spd.Kc = _IQ(0.2);
    pid1_spd.OutMax = _IQ(0.99);
    pid1_spd.OutMin = _IQ(0); 

// Enable global Interrupts and higher priority real-time debug events:
	EINT;   // Enable Global interrupt INTM
	ERTM;	// Enable Global realtime interrupt DBGM

// IDLE loop. Just sit and loop forever:	
	for(;;) BackTicker++;

} 	

interrupt void MainISR(void)
{

// Verifying the ISR
     IsrTicker++;

// ***************** LEVEL1 *****************
#if (BUILDLEVEL==LEVEL1)

// ------------------------------------------------------------------------------
//    Call the ADC04U_DRV read function.
// ------------------------------------------------------------------------------
	  adc1.read(&adc1);

// ------------------------------------------------------------------------------
//    Connect inputs of the HALL module and call the Hall sensor
//    read function.
// ------------------------------------------------------------------------------
      hall1.HallMapPointer = (int16)mod1.Counter; 
      hall1.read(&hall1);

// ------------------------------------------------------------------------------
//    Connect inputs of the MOD6 module and call the Modulo 6 counter
//    calculation function.
// ------------------------------------------------------------------------------
      mod1.TrigInput =(int32)hall1.CmtnTrigHall;
      mod1.Counter = (int32)hall1.HallMapPointer; 
      mod1.calc(&mod1);

// ------------------------------------------------------------------------------
//    Connect inputs of the RMP2 module and call the Ramp control 2
//    calculation function.
// ------------------------------------------------------------------------------
      rmp2.DesiredInput = (int32)DFuncDesired;
      rmp2.calc(&rmp2);

// ------------------------------------------------------------------------------
//    Connect inputs of the PWM_DRV module and call the PWM signal generation
//    update function.
// ------------------------------------------------------------------------------
      pwm1.CmtnPointer = (int16)mod1.Counter;
      pwm1.DutyFunc = (int16)rmp2.Out;
      pwm1.update(&pwm1);

// ------------------------------------------------------------------------------
//    Connect inputs of the SPEED_PR module and call the speed calculation 
//    function.
// ------------------------------------------------------------------------------  
      if ((mod1.Counter == 5)&(hall1.CmtnTrigHall == 0x7FFF)) {
         speed1.TimeStamp = VirtualTimer;
         speed1.calc(speed1);
      }

// ------------------------------------------------------------------------------
//    Connect inputs of the DATALOG module 
// ------------------------------------------------------------------------------
      DlogCh1 = (int16)mod1.Counter; 
      DlogCh2 = hall1.HallGpioAccepted; 
      DlogCh3 = (int16)mod1.TrigInput;
      DlogCh4 = hall1.CmtnTrigHall;

// ------------------------------------------------------------------------------
//    Connect inputs of the EN_DRV module and call the enable/disable PWM signal
//    update function.
// ------------------------------------------------------------------------------
      drv1.EnableFlag = EnableFlag;
      drv1.update(&drv1); 

#endif // (BUILDLEVEL==LEVEL1)


// ***************** LEVEL2 *****************
#if (BUILDLEVEL==LEVEL2)

// ------------------------------------------------------------------------------
//    Call the ADC04U_DRV read function.
// ------------------------------------------------------------------------------
	  adc1.read(&adc1);

// ------------------------------------------------------------------------------
//    Connect inputs of the HALL module and call the Hall sensor
//    read function.
// ------------------------------------------------------------------------------
      hall1.HallMapPointer = (int16)mod1.Counter; 
      hall1.read(&hall1);

// ------------------------------------------------------------------------------
//    Connect inputs of the MOD6 module and call the Modulo 6 counter
//    calculation function.
// ------------------------------------------------------------------------------
      mod1.TrigInput =(int32)hall1.CmtnTrigHall;
      mod1.Counter = (int32)hall1.HallMapPointer; 
      mod1.calc(&mod1);

// ------------------------------------------------------------------------------
//    Connect inputs of the RMP2 module and call the Ramp control 2
//    calculation function.
// ------------------------------------------------------------------------------
      rmp2.DesiredInput = (int32)DFuncDesired;
      rmp2.calc(&rmp2);

// ------------------------------------------------------------------------------
//    Connect inputs of the PID_REG3 module and call the PID controller
//    calculation function.
// ------------------------------------------------------------------------------  
      pid1_idc.Ref = CurrentSet;
      pid1_idc.Fdb = _IQ15toIQ(adc1.Ch4Out);
      pid1_idc.calc(&pid1_idc); 

// ------------------------------------------------------------------------------
//    Connect inputs of the PWM_DRV module and call the PWM signal generation
//    update function.
// ------------------------------------------------------------------------------
   // Switch from fixed duty-cycle or controlled Idc duty-cycle by ILoopFlag variable 
      if (ILoopFlag == FALSE)
         pwm1.DutyFunc = (int16)rmp2.Out;           // fixed duty-cycle
      else 
         pwm1.DutyFunc = (int16)_IQtoIQ15(pid1_idc.Out);   // controlled Idc duty-cycle       

      pwm1.CmtnPointer = (int16)mod1.Counter;
      pwm1.update(&pwm1);

// ------------------------------------------------------------------------------
//    Connect inputs of the SPEED_PR module and call the speed calculation 
//    function.
// ------------------------------------------------------------------------------  
      if ((mod1.Counter == 5)&(hall1.CmtnTrigHall == 0x7FFF)) {
         speed1.TimeStamp = VirtualTimer;
         speed1.calc(speed1);
      }

// ------------------------------------------------------------------------------
//    Connect inputs of the DATALOG module 
// ------------------------------------------------------------------------------
      DlogCh1 = (int16)mod1.Counter; 
      DlogCh2 = (int16)mod1.TrigInput;
      DlogCh3 = (int16)_IQtoIQ15(pid1_idc.Ref);
      DlogCh4 = (int16)_IQtoIQ15(pid1_idc.Fdb);

// ------------------------------------------------------------------------------
//    Connect inputs of the EN_DRV module and call the enable/disable PWM signal
//    update function.
// ------------------------------------------------------------------------------    
      drv1.EnableFlag = EnableFlag;
      drv1.update(&drv1);

#endif // (BUILDLEVEL==LEVEL2)


// ***************** LEVEL3 *****************
#if (BUILDLEVEL==LEVEL3)

// ------------------------------------------------------------------------------
//    Call the ADC04U_DRV read function.
// ------------------------------------------------------------------------------
	  adc1.read(&adc1);

// ------------------------------------------------------------------------------
//    Connect inputs of the RMP module and call the Ramp control
//    calculation function.
// ------------------------------------------------------------------------------
      rc1.TargetValue = _IQ(SpeedRef);
      rc1.calc(&rc1);

// ------------------------------------------------------------------------------
//    Connect inputs of the HALL module and call the Hall sensor
//    read function.
// ------------------------------------------------------------------------------
      hall1.HallMapPointer = (int16)mod1.Counter; 
      hall1.read(&hall1);

// ------------------------------------------------------------------------------
//    Connect inputs of the MOD6 module and call the Modulo 6 counter
//    calculation function.
// ------------------------------------------------------------------------------
      mod1.TrigInput =(int32)hall1.CmtnTrigHall;
      mod1.Counter = (int32)hall1.HallMapPointer; 
      mod1.calc(&mod1);

// ------------------------------------------------------------------------------
//    Connect inputs of the RMP2 module and call the Ramp control 2
//    calculation function.
// ------------------------------------------------------------------------------
      rmp2.DesiredInput = (int32)DFuncDesired;
      rmp2.calc(&rmp2);

// ------------------------------------------------------------------------------
//    Connect inputs of the PID_REG3 module and call the PID speed controller
//    calculation function.
// ------------------------------------------------------------------------------  
      pid1_spd.Ref = rc1.SetpointValue;
      pid1_spd.Fdb = speed1.Speed;
      pid1_spd.calc(&pid1_spd);

// ------------------------------------------------------------------------------
//    Set the speed closed loop flag once the speed is built up to a desired value. 
// ------------------------------------------------------------------------------
      if (rc1.EqualFlag == 0x7FFFFFFF)  {
         SpeedLoopFlag = TRUE; 
         rc1.RampDelayMax = 300;  
      }

// ------------------------------------------------------------------------------
//    Connect inputs of the PWM_DRV module and call the PWM signal generation
//    update function.
// ------------------------------------------------------------------------------
   // Switch from fixed duty-cycle or controlled Speed duty-cycle by SpeedLoopFlag variable
      if (SpeedLoopFlag == FALSE)
         pwm1.DutyFunc = (int16)rmp2.Out;           // fixed duty-cycle
      else 
         pwm1.DutyFunc = (int16)_IQtoIQ15(pid1_spd.Out);   // controlled Speed duty-cycle

      pwm1.CmtnPointer = (int16)mod1.Counter;
      pwm1.update(&pwm1);

// ------------------------------------------------------------------------------
//    Connect inputs of the SPEED_PR module and call the speed calculation 
//    function.
// ------------------------------------------------------------------------------  
      if ((mod1.Counter == 5)&(hall1.CmtnTrigHall == 0x7FFF)) {
         speed1.TimeStamp = VirtualTimer;
         speed1.calc(speed1);
      }

// ------------------------------------------------------------------------------
//    Connect inputs of the DATALOG module 
// ------------------------------------------------------------------------------
      DlogCh1 = (int16)mod1.Counter; 
      DlogCh2 = (int16)mod1.TrigInput;
      DlogCh3 = (int16)_IQtoIQ15(pid1_spd.Ref);
      DlogCh4 = (int16)_IQtoIQ15(pid1_spd.Fdb);

// ------------------------------------------------------------------------------
//    Connect inputs of the EN_DRV module and call the enable/disable PWM signal
//    update function (for DMC1500 only).
// ------------------------------------------------------------------------------    
      drv1.EnableFlag = EnableFlag;
      drv1.update(&drv1);

#endif // (BUILDLEVEL==LEVEL3)


// ------------------------------------------------------------------------------
//    Increase virtual timer and force 15 bit wrap around
// ------------------------------------------------------------------------------
	VirtualTimer++;
	VirtualTimer &= 0x00007FFF;

// ------------------------------------------------------------------------------
//    Call the DATALOG update function.
// ------------------------------------------------------------------------------
    dlog.update(&dlog);


#if (DSP_TARGET==F2808)
// Acknowledge interrupt to recieve more interrupts from PIE group 1
	PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
#endif


#if (DSP_TARGET==F2812)
// Enable more interrupts from this timer
	EvaRegs.EVAIMRB.bit.T2PINT = 1;
	
// Note: To be safe, use a mask value to write to the entire
	// EVAIFRB register.  Writing to one bit will cause a read-modify-write
	// operation that may have the result of writing 1's to clear 
	// bits other then those intended. 
    EvaRegs.EVAIFRB.all = BIT0;
	
// Acknowledge interrupt to recieve more interrupts from PIE group 3
	PieCtrlRegs.PIEACK.all |= PIEACK_GROUP3;
#endif
}


//===========================================================================
// No more.
//===========================================================================

⌨️ 快捷键说明

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