📄 f281xbdcpwm.c
字号:
/* ==================================================================================
File name: F281XBDCPWM.C
Originator: Digital Control Systems Group
Texas Instruments
Description: This file contains source for the PWM drivers for the F281x for DC-motor
dc-bus+ ------------------------
| |
[1] [3]
|----(dc-motor)----|
[2] [4]
| |
dc-bus- ------------------------
Target: TMS320F281x family
=====================================================================================
History:
-------------------------------------------------------------------------------------
04-15-2005 Version 3.20: Using DSP281x v. 1.00 or higher
----------------------------------------------------------------------------------*/
#include "DSP281x_Device.h"
#include "f281xbdcpwm.h"
void F281X_EV1_BDC_PWM_Init(PWMGEN *p)
{
EvaRegs.T1PR = p->PeriodMax; // Init Timer 1 period Register
EvaRegs.T1CON.all = BDCPWM_INIT_STATE; // Init PWM Operation
EvaRegs.ACTRA.all = 0x0000; // Init ACTRA Register
EvaRegs.GPTCONA.all = 0x0000; // Init GPTCONA Register
EvaRegs.COMCONA.all = 0xA200; // Init COMCONA Register
EALLOW; // Enable EALLOW
GpioMuxRegs.GPAMUX.all |= 0x000F; // Setting PWM1-4 as primary output pins
EDIS; // Disable EALLOW
}
void F281X_EV1_BDC_PWM_Update(PWMGEN *p)
{
int32 Tmp;
int16 Period, GPR0_BDC_PWM;
// PWM1&4 are enabled (PWM4's forced ON) and PWM2&3 are disabled
if (p->Rotation==0)
EvaRegs.ACTRA.all = 0x00C2;
// PWM2&3 are enabled (PWM2's forced ON) and PWM1&4 are disabled
else if (p->Rotation==1)
EvaRegs.ACTRA.all = 0x002C;
// Otherwise, PWM1-4 are disabled
else
EvaRegs.ACTRA.all = 0x0000;
// 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 pwm_active setting
if (p->PwmActive==1) // PWM active high
GPR0_BDC_PWM = 0x7FFF - p->DutyFunc;
else if (p->PwmActive==0) // PWM active low
GPR0_BDC_PWM = p->DutyFunc;
// Convert "DutyFunc" or "GPR0_BDC_PWM" (Q15) duty modulation function to Q0
Tmp = (int32)Period*(int32)GPR0_BDC_PWM; // Q15 = Q0*Q15
EvaRegs.CMPR1 = (int16)(Tmp>>15); // Q15 -> Q0
EvaRegs.CMPR2 = (int16)(Tmp>>15); // Q15 -> Q0
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -