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

📄 dsp281x_bldcpwm.c

📁 程序是我用DSP2812开发的无刷直流电机控制程序
💻 C
字号:
/* ==================================================================================
File name:       DSP281x_BLDCPWM.C
                    
Originator:	Digital Control Systems Group
			Texas Instruments

Description:   This file contains source for the Full Compare BLDC PWM drivers for the F281x

Target: TMS320F281x family
              
=====================================================================================
History:
-------------------------------------------------------------------------------------
 04-15-2005	Version 3.20: Using DSP281x v. 1.00 or higher 
----------------------------------------------------------------------------------*/

#include "DSP281x_Device.h"
#include "DSP281x_BLDCPWM.h"

void F281X_EV1_BLDC_PWM_Init(PWMGEN *p) 
{       
        EvaRegs.T1PR = p->PeriodMax;             // Init Timer 1 Period Register
        EvaRegs.T1CON.all = BLDCPWM_INIT_STATE;   // Init PWM Operation
        EvaRegs.ACTRA.all = 0x0000;                
        EvaRegs.GPTCONA.all = 0x0000;
        EvaRegs.COMCONA.all = 0xA200;

        EALLOW;                       // Enable EALLOW
        GpioMuxRegs.GPAMUX.all |= 0x003F;    // Setting PWM1-6 as primary output pins
        EDIS;                         // Disable EALLOW
}


void F281X_EV1_BLDC_PWM_Update(PWMGEN *p) 
{       

	int32 Tmp;
	int16 Period, GPR0_BLDC_PWM;
	
// State s1: current flows to motor windings from phase A->B, de-energized phase = C
	if (p->CmtnPointer==0)
         EvaRegs.ACTRA.all = 0x00C2;

// State s2: current flows to motor windings from phase A->C, de-energized phase = B
    else if (p->CmtnPointer==1)  
         EvaRegs.ACTRA.all = 0x0C02;

// State s3: current flows to motor windings from phase B->C, de-energized phase = A
    else if (p->CmtnPointer==2)  
         EvaRegs.ACTRA.all = 0x0C20;
   
// State s4: current flows to motor windings from phase B->A, de-energized phase = C
    else if (p->CmtnPointer==3)  
         EvaRegs.ACTRA.all = 0x002C;

// State s5: current flows to motor windings from phase C->A, de-energized phase = B
    else if (p->CmtnPointer==4)  
         EvaRegs.ACTRA.all = 0x020C;

// State s6: current flows to motor windings from phase C->B, de-energized phase = A
    else if (p->CmtnPointer==5)  
         EvaRegs.ACTRA.all = 0x02C0;

// Convert "Period" (Q15) modulation function to Q0
    Tmp = (int32)p->PeriodMax*(int32)p->MfuncPeriod;   // Q15 = Q0*Q15
    Period = (int16)(Tmp>>15);                         // Q15 -> Q0 (Period)
 
// Check PwmActive setting
	if (p->PwmActive==1)                   // PWM active high
      GPR0_BLDC_PWM = 0x7FFF - p->DutyFunc;   
    
    else if (p->PwmActive==0)              // PWM active low
      GPR0_BLDC_PWM = p->DutyFunc;

// Convert "DutyFunc" or "GPR0_BLDC_PWM" (Q15) duty modulation function to Q0
    Tmp = (int32)Period*(int32)GPR0_BLDC_PWM;     // Q15 = Q0*Q15
    EvaRegs.CMPR1 = (int16)(Tmp>>15);             // Q15 -> Q0
    EvaRegs.CMPR2 = (int16)(Tmp>>15);             // Q15 -> Q0
    EvaRegs.CMPR3 = (int16)(Tmp>>15);             // Q15 -> Q0

}


⌨️ 快捷键说明

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