自己设计的驱动器硬件没问题了,软件怎么也驱动不起来,4拍双四拍八拍都试了电机就是抖动,板子上的保险都快烧了就是转不起来什么情况呢实在是没辙了?
附个程序就是个4拍的,是周期频率的问题吗?
#include "DSP28x_Project.h" // Device Headerfile and Examples Include File
// Prototype statements for functions found within this file.
void InitEPwm1Example(void);
void InitEPwm2Example(void);
interrupt void epwm1_tzint_isr(void);
interrupt void epwm2_tzint_isr(void);
void Gpio_setup1(void);
// Global variables used in this example
Uint32 EPwm1TZIntCount;
Uint32 EPwm2TZIntCount;
//int i;
void main(void)
{
// Step 1. Initialize System Control:
// PLL, WatchDog, enable Peripheral Clocks
// This example function is found in the DSP2803x_SysCtrl.c file.
InitSysCtrl();
// Step 2. Initalize GPIO:
// This example function is found in the DSP2803x_Gpio.c file and
// illustrates how to set the GPIO to it's default state.
// InitGpio(); // Skipped for this example
// For this case just init GPIO pins for ePWM1, ePWM2, and TZ pins
InitEPwm1Gpio();
InitEPwm2Gpio();
InitTzGpio();
// Step 3. Clear all interrupts and initialize PIE vector table:
// Disable CPU interrupts
DINT;
// Initialize the PIE control registers to their default state.
// The default state is all PIE interrupts disabled and flags
// are cleared.
// This function is found in the DSP2803x_PieCtrl.c file.
InitPieCtrl();
// Disable CPU interrupts and clear all CPU interrupt flags:
IER = 0x0000;
IFR = 0x0000;
// Initialize the PIE vector table with pointers to the shell Interrupt
// Service Routines (ISR).
// This will populate the entire table, even if the interrupt
// is not used in this example. This is useful for debug purposes.
// The shell ISR routines are found in DSP2803x_DefaultIsr.c.
// This function is found in DSP2803x_PieVect.c.
InitPieVectTable();
// Interrupts that are used in this example are re-mapped to
// ISR functions found within this file.
EALLOW; // This is needed to write to EALLOW protected registers
PieVectTable.EPWM1_TZINT = &epwm1_tzint_isr;
PieVectTable.EPWM2_TZINT = &epwm2_tzint_isr;
EDIS; // This is needed to disable write to EALLOW protected registers
// Step 4. Initialize all the Device Peripherals:
// This function is found in DSP2803x_InitPeripherals.c
// InitPeripherals(); // Not required for this example
EALLOW;
SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0;
EDIS;
InitEPwm1Example();
InitEPwm2Example();
Gpio_setup1();
EALLOW;
SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;
EDIS;
// Step 5. User specific code, enable interrupts
// Initalize counters:
EPwm1TZIntCount = 0;
EPwm2TZIntCount = 0;
// Enable CPU INT3 which is connected to EPWM1-3 INT:
IER |= M_INT2;
// Enable EPWM INTn in the PIE: Group 2 interrupt 1-3
PieCtrlRegs.PIEIER2.bit.INTx1 = 1;
PieCtrlRegs.PIEIER2.bit.INTx2 = 1;
// Enable global Interrupts and higher priority real-time debug events:
EINT; // Enable Global interrupt INTM
ERTM; // Enable Global realtime interrupt DBGM
// Step 6. IDLE loop. Just sit and loop forever (optional):
/* for(a=100;a>50;a--)
{ int j,k;
i=a;
InitEPwm1Example();
InitEPwm2Example();
for(j=0;j<100;j++)
for(k=0;k<500;k++);
}
while(1)
{
i=50;
InitEPwm1Example();
InitEPwm2Example();
}*/
for(;;)
{
asm(" NOP");
}
}
interrupt void epwm1_tzint_isr(void)
{
EPwm1TZIntCount++;
/*EALLOW;
EPwm1Regs.TZCLR.bit.DCAEVT1 = 1;
EPwm1Regs.TZCLR.bit.INT = 1;
EDIS;*/
// Acknowledge this interrupt to receive more interrupts from group 2
PieCtrlRegs.PIEACK.all = PIEACK_GROUP2;
}
interrupt void epwm2_tzint_isr(void)
{
EPwm2TZIntCount++;
// Clear the flags - we will continue to take
// this interrupt until the TZ pin goes high
//
/*EALLOW;
EPwm2Regs.TZCLR.bit.CBC = 1;
EPwm1Regs.TZCLR.bit.DCAEVT1 = 1;
EPwm2Regs.TZCLR.bit.INT = 1;
EDIS;*/
// Acknowledge this interrupt to receive more interrupts from group 2
PieCtrlRegs.PIEACK.all = PIEACK_GROUP2;
}
void Gpio_setup1(void)
{
EALLOW;
GpioCtrlRegs.GPAPUD.bit.GPIO12 = 0; // GPIO26 = GPIO26
GpioDataRegs.GPACLEAR.bit.GPIO12 = 1;
GpioCtrlRegs.GPAMUX1.bit.GPIO12 = 1;
GpioCtrlRegs.GPADIR.bit.GPIO12 = 1;
EDIS;
}
void InitEPwm1Example()
{
EPwm1Regs.CMPA.half.CMPA =2500 ;
EPwm1Regs.CMPB = 5000;
EPwm1Regs.TBPRD = 10000;
EPwm1Regs.TBPHS.half.TBPHS = 0x0000; // Phase is 0
EPwm1Regs.TBCTR = 0x0000; // Clear counter
// Setup counter mode
EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UP; // Count up
EPwm1Regs.TBCTL.bit.HSPCLKDIV = 50; // Clock ratio to SYSCLKOUT
EPwm1Regs.TBCTL.bit.CLKDIV = 50;//0x0-1分频,TBCLK = SYSCLKOUT / (HSPCLKDIV × CLKDIV)
EPwm1Regs.TBCTL.bit.PHSEN = TB_DISABLE; // Master module
EPwm1Regs.TBCTL.bit.PRDLD = TB_SHADOW;
EPwm1Regs.TBCTL.bit.SYNCOSEL = TB_CTR_ZERO; // Sync down-stream module
// Setup shadowing
EPwm1Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;
EPwm1Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW;
EPwm1Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO; // Load on Zero时间基准计数器等于周期
EPwm1Regs.CMPCTL.bit.LOADBMODE = CC_CTR_ZERO;
// Action Qualifier SubModule Registers
EPwm1Regs.AQCTLA.bit.ZRO = AQ_SET;
EPwm1Regs.AQCTLA.bit.CAU = AQ_CLEAR;
EPwm1Regs.AQCTLB.bit.CAU = AQ_SET;
EPwm1Regs.AQCTLB.bit.CBU = AQ_CLEAR;
}
void InitEPwm2Example()
{
EPwm2Regs.CMPA.half.CMPA =2500 ;
EPwm2Regs.CMPB = 5000;
EPwm2Regs.TBPRD =10000 ;
// Setup TBCLK
EPwm2Regs.TBPHS.half.TBPHS = 0x1388; // Phase is 0
EPwm2Regs.TBCTR = 0x0000; // Clear counter
// Setup counter mode
EPwm2Regs.TBCTL.bit.CTRMODE = TB_COUNT_UP; // Count up
EPwm2Regs.TBCTL.bit.HSPCLKDIV = 50; // Clock ratio to SYSCLKOUT
EPwm2Regs.TBCTL.bit.CLKDIV = 50;//0x0-1分频,TBCLK = SYSCLKOUT / (HSPCLKDIV × CLKDIV)
EPwm2Regs.TBCTL.bit.PHSEN = TB_ENABLE; // Slave module
EPwm2Regs.TBCTL.bit.PRDLD = TB_SHADOW;
EPwm2Regs.TBCTL.bit.SYNCOSEL = TB_SYNC_IN;//TB_SYNC_DISABLE; // sync flow-through
// Setup shadowing
EPwm2Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;
EPwm2Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW;
EPwm2Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO; // Load on Zero
EPwm2Regs.CMPCTL.bit.LOADBMODE = CC_CTR_ZERO;
// Action Qualifier SubModule Registers
EPwm2Regs.AQCTLA.bit.ZRO = AQ_SET;
EPwm2Regs.AQCTLA.bit.CAU = AQ_CLEAR;
EPwm2Regs.AQCTLB.bit.CAU = AQ_SET;
EPwm2Regs.AQCTLB.bit.CBU = AQ_CLEAR;
}
|