This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

can't get step motor to response, with epwm from tms320c28x

hello,

 I am new to dsp and arm, this is my first project. I'm working on F28M36P63C to control stepping motors.

driver: SG-514MSC

motor: SIGMA SGSP-60YAW-0B

 I have both created the project on Cortex-M3 with main function "mian1.c", and the project on TMS320C28x with main function "main2.c". the code is just a test to see if the c28x epwm function works well, the result is that the motor gives no response. I have given F28M36P63C some other tests to prove that the motor,the driver,the M3 processor work fine. This concludes several possibilities why the motor doesn't give response, which I'm still working on.
 I'm not sure if there is anything wrong with the code, so I post it here,it's very simple. would anyone be kind enough to take a review? I would be really appriciate your any help!

 
/* main1.c */
#include <string.h>
#include "hw_ints.h"
#include "hw_memmap.h"
#include "hw_sysctl.h"
#include "hw_types.h"
#include "hw_nvic.h"
#include "interrupt.h"
#include "debug.h"
#include "sysctl.h"
#include "flash.h"
#include "ipc.h"
#include "gpio.h"

#ifdef _FLASH
// These are defined by the linker
extern unsigned long RamfuncsLoadStart;
extern unsigned long RamfuncsRunStart;
extern unsigned long RamfuncsLoadSize;
#endif

//*****************************************************************************
// The error routine that is called if the driver library encounters an error.
//*****************************************************************************
#ifdef DEBUG
void
__error__(char *pcFilename, unsigned long ulLine)
{
}
#endif

int main(void) {

 HWREG (SYSCTL_MWRALLOW) = 0xA5A5A5A5;

 // Sets up PLL, M3 running at 100MHz and C28 running at 100MHz
 SysCtlClockConfigSet(
   SYSCTL_USE_PLL | (SYSCTL_SPLLIMULT_M & 0xA) | SYSCTL_SYSDIV_1
     | SYSCTL_M3SSDIV_1 | SYSCTL_XCLKDIV_4);

 //relocate the vector table.
 HWREG (NVIC_VTABLE) = 0x00201000;

 //if running from FLASH, first set up flash configuration.flash configure functions must be executed out of RAM。
#ifdef _FLASH
 // Copy time critical code and Flash setup code to RAM
 // This includes the following functions:  InitFlash();
 // The  RamfuncsLoadStart, RamfuncsLoadSize, and RamfuncsRunStart
 // symbols are created by the linker. Refer to the device .cmd file.
 memcpy(&RamfuncsRunStart, &RamfuncsLoadStart, (size_t) &RamfuncsLoadSize);

 // Call Flash Initialization to setup flash waitstates
 // This function must reside in RAM
 FlashInit();
#endif

#ifdef _STANDALONE
#ifdef _FLASH
 //  Send boot command to allow the C28 application to begin execution
 IPCMtoCBootControlSystem(CBROM_MTOC_BOOTMODE_BOOT_FROM_FLASH);
 //  Send boot command to allow the C28 application to begin execution
 IPCMtoCBootControlSystem(CBROM_MTOC_BOOTMODE_BOOT_FROM_RAM);
#endif
#endif

 //enable clock gating for GPIOA,F,G,J,P,Q.
 SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
 SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
 SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG);
 SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOJ);
 SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOQ);

 //give C28x control of port A pin 0
 GPIOPinConfigureCoreSelect(GPIO_PORTA_BASE, GPIO_PIN_0,
   GPIO_PIN_C_CORE_SELECT);

 // Enable processor interrupts.
 IntMasterEnable();

 /*rotate*/
 //c28 EPWM output,pad configure are controlled by m3.
 GPIOPadConfigSet(GPIO_PORTA_BASE, GPIO_PIN_0, GPIO_PIN_TYPE_OD);
 //step angle,D0,opendrain
 GPIOPinTypeGPIOOutputOD(GPIO_PORTJ_BASE, GPIO_PIN_7);
 //step angle,D1,opendrain
 GPIOPinTypeGPIOOutputOD(GPIO_PORTF_BASE, GPIO_PIN_2);
 //step angle,D2,opendrain
 GPIOPinTypeGPIOOutputOD(GPIO_PORTG_BASE, GPIO_PIN_3);
 //step angle,D3,opendrain
 GPIOPinTypeGPIOOutputOD(GPIO_PORTQ_BASE, GPIO_PIN_7);

//=================================================================================
// run time
// rotate step angle setting D0~D3
//========================================
 GPIOPinWrite(GPIO_PORTJ_BASE, GPIO_PIN_7, 0); //D0
 GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 0); //D1
 GPIOPinWrite(GPIO_PORTG_BASE, GPIO_PIN_3, 0); //D2
 GPIOPinWrite(GPIO_PORTQ_BASE, GPIO_PIN_7, 0); //D3

 for (;;) {
 }

}


/* main2.c */
#include <string.h>
#include "F28M36x_Gpio.h"
#include "F28M36x_Device.h"
#include "F28M36x_Epwm.h"
#include "F28M36x_EPwm_defines.h"
#include "F28M36x_Examples.h"

#define C28_FREQ    150         //CPU frequency in MHz
#ifdef _FLASH
// These are defined by the linker (see device linker command file)
extern Uint16 RamfuncsLoadStart;
extern Uint16 RamfuncsLoadSize;
extern Uint16 RamfuncsRunStart;
#endif

void InitEpwm1(void);

int main(void) {

 // step 1: initialize system control to known state
 InitSysCtrl(); 

 // step 2: initialize GPIO to a known state
 InitGpio();

 // Step 3. Clear all interrupts and initialize PIE vector table
 InitPieCtrl();

#ifdef _FLASH
 // Copy time critical code and Flash setup code to RAM
 // This includes the following functions: InitFlash();
 // The  RamfuncsLoadStart, RamfuncsLoadEnd, and RamfuncsRunStart
 // symbols are created by the linker. Refer to the device .cmd file.
 memcpy(&RamfuncsRunStart, &RamfuncsLoadStart, (size_t) &RamfuncsLoadSize);

 // Call Flash Initialization to setup flash waitstates
 // This function must reside in RAM
 InitFlash();
#endif

 // Disable CPU interrupts and clear all CPU interrupt flags:
 IER &= 0x0000;
 IFR &= 0x0000;
     
 InitPieVectTable();

 // Enable global Interrupts and higher priority real-time debug events:(also for boot process to respond MTOCIPCINT1 interrupt.)
 EINT;
 // Enable Global interrupt INTM
 ERTM;
 // Enable Global realtime interrupt DBGM

 // enable CPU interrupts
 IER &= 0xFFFF;

 //GPIO0 as EPWM1A
 EALLOW;
 GpioG1CtrlRegs.GPAMUX1.bit.GPIO0 = 1;
 EDIS;

 InitEpwm1();

 while (1) {
 }

}
//=============================
//ePWM1A - rotate CW - GPIO0
//============================
void InitEpwm1(void) {

 EALLOW;
 //TB module
 EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN;
 EPwm1Regs.TBCTL.bit.PHSEN = TB_DISABLE;
 EPwm1Regs.TBCTL.bit.HSPCLKDIV = TB_DIV4;
 EPwm1Regs.TBCTL.bit.CLKDIV = TB_DIV4;
 EPwm1Regs.TBPHS.half.TBPHS = 0x0000;
 EPwm1Regs.TBPRD = 6000;
 EPwm1Regs.TBCTR = 0x0000;

 //CC module
 EPwm1Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;   // Load registers every ZERO
 EPwm1Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO;
 EPwm1Regs.CMPA.half.CMPA = 3000;

 //AQ module
 EPwm1Regs.AQCTLA.bit.CAU = AQ_SET;           // Set PWM1A on CAU
 EPwm1Regs.AQCTLA.bit.CAD = AQ_CLEAR;         // Clear PWM1A on CAD
 //EPwm1Regs.AQSFRC.bit.

 //TZ module
 EPwm1Regs.TZSEL.bit.OSHT1 = TZ_ENABLE;
 EPwm1Regs.TZCTL.bit.TZA = TZ_FORCE_HI;

 EDIS;
}