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.

tms320f28035

Other Parts Discussed in Thread: TMS320F28035

hi this is vinod,i am designing power dc supply.for that i am using tms320f28035.i am getting pulsese like bridge rectifier.When i used stop button there is some unwanted glitches(spikes).it is harmful for system.so i want remove this glitch.my code is following :
/**********************************************************************
* File: Main_4.c
* Devices: TMS320F28035
**********************************************************************/

#include "DSP2802x_Device.h" // DSP2802x Headerfile Include File
#include "DSP2802x_Examples.h" // DSP2802x Examples Include File
#include "PeripheralHeaderIncludes.h"
#include "Lab.h"      // Main include file


#define MIN_FREQUENCY 30000
#define MAX_FREQUENCY 300

#define STRAT_STOP_KEY 0
#define MODE_KEY  1
#define INCREASE_KEY 2
#define DECREASE_KEY 3
#define INVALIED_KEY 4

void init_keypad(void);
void start_stop_system(void);
void increase_current(void);
void decrease_current(void);
void start_system(void);
Uint16 read_key(void);

//--- Global Variables
Uint16 AdcBuf[ADC_BUF_LEN];     // ADC buffer allocation
Uint16 DEBUG_TOGGLE = 1;     // Used for realtime mode investigation test
Uint16 set_curent,set_current_count;
signed int Vcap;
signed int Vdelta;
unsigned int pwm_old;
unsigned int pwm;
signed int Vout;
Uint16 Vset,i_set,i_set_count,i;
Uint16 key;
volatile Uint16 Vmeasure;
volatile Uint16 pwm_period,pwm_freq;

struct FLAG_BITS {          // System
   Uint16 mode_flag:1;      //
   Uint16 on_off_flag:1;    //
   Uint16 reserved1:14;
   Uint16 reserved2:16;
   };
      
volatile struct FLAG_BITS Flag_bits;

/**********************************************************************
* Function: main()
*
* Description: Main function for C28x workshop labs
**********************************************************************/
void main(void)
{
//--- CPU Initialization
 InitSysCtrl();      // Initialize the CPU (FILE: SysCtrl.c)
 InitGpio();       // Initialize the shared GPIO pins (FILE: Gpio.c)
 InitPieCtrl();      // Initialize and enable the PIE (FILE: PieCtrl.c)
 InitWatchdog();      // Initialize the Watchdog Timer (FILE: WatchDog.c)

//--- Copy all Flash sections that need to run from RAM (use memcpy() from RTS library)

// Section secureRamFuncs contains user defined code that runs from CSM secured RAM

 memcpy( &secureRamFuncs_runstart,
   &secureRamFuncs_loadstart,
   &secureRamFuncs_loadend - &secureRamFuncs_loadstart);


//--- Initialize the Flash and OTP
InitFlash();      // Initialize the Flash (FILE: Flash.c)

//--- Peripheral Initialization
//set_current_count= DEFAULT_CURRENT;
Vset = 2000;
Vcap=0;
InitAdc();       // Initialize the ADC (FILE: Adc.c)
InitEPwm();       // Initialize the EPwm (FILE: EPwm.c)
init_keypad();
Flag_bits.mode_flag =0;
Flag_bits.on_off_flag=0;

i_set = DEFAULT_CURRENT;

i_set_count = i_set*ADC_FULLSCALE_COUNT/MAX_CURRENT;

pwm_freq = FREQ_MAX - i_set*FREQ_STEPS;
pwm_period = (unsigned long) 60000000L/pwm_freq/2;  //60MHz/18kHZ/2
 asm(" EALLOW"); 
     EPwm1Regs.ETSEL.bit.INTSEL=2;
     EPwm1Regs.ETCLR.bit.INT = 1;
  EPwm1Regs.ETFLG.bit.INT=0;
  EPwm1Regs.ETPS.bit.INTPRD = 1;
 

 asm(" EDIS");
//--- Enable global interrupts
 asm(" CLRC INTM, DBGM");   // Enable global interrupts and realtime debug

//--- Main Loop

 while(1)       // endless loop - wait for an interrupt
 {

 // key=1;
 //}
 //{
// DelayUs(10000);

 key=read_key();
 switch(key)
  {
  case INCREASE_KEY:
  increase_current();
  break;
 
  case DECREASE_KEY:
  decrease_current();
  break;

  case STRAT_STOP_KEY:
  start_stop_system();
  break;
  
  case MODE_KEY:
  if(!Flag_bits.on_off_flag)
  {
  Flag_bits.mode_flag=!Flag_bits.mode_flag;
    
     if(Flag_bits.mode_flag)
      { EPwm1Regs.ETSEL.bit.SOCAEN = 1; GpioDataRegs.GPACLEAR.bit.GPIO31 = 1;}
  else
   { EPwm1Regs.ETSEL.bit.SOCAEN = 0; GpioDataRegs.GPASET.bit.GPIO31 = 1;}
  
  }
  break;
  }
 } //end of while

} //end of main()

 

 

 

/*** end of file *****************************************************/

void init_keypad(void)
{
 asm(" EALLOW"); 
 GpioCtrlRegs.GPAMUX2.bit.GPIO16 = 0; //START/STOP Key 0=GPIO         1=SPISIMOA   2=rsvd       3=TZ2
 GpioCtrlRegs.GPAMUX2.bit.GPIO17 = 0; //MODE Key    0=GPIO         1=SPISOMIA   2=rsvd       3=TZ3
 GpioCtrlRegs.GPAMUX2.bit.GPIO18 = 0; //INC Key   0=GPIO         1=SPICLKA    2=SCITXDA    3=XCLKOUT
 GpioCtrlRegs.GPAMUX2.bit.GPIO19 = 0; //DEC Key   0=GPIO/XCLKIN  1=SPISTEA    2=SCIRXDA    3=ECAP1

 GpioCtrlRegs.GPADIR.bit.GPIO16 = 0;  //Confugure as input for key
 GpioCtrlRegs.GPADIR.bit.GPIO17 = 0;  //Confugure as input for key
 GpioCtrlRegs.GPADIR.bit.GPIO18 = 0;  //Confugure as input for key
 GpioCtrlRegs.GPADIR.bit.GPIO19 = 0;  //Confugure as input for key

 GpioCtrlRegs.GPACTRL.bit.QUALPRD2 = 0xFF; //The time between samples is specified in the GPACTRL register.
 GpioCtrlRegs.GPAQSEL2.bit.GPIO16=2;    // Qualification using 6 samples. Valid for pins configured as GPIO or a peripheral function.
 GpioCtrlRegs.GPAQSEL2.bit.GPIO17=2;
 GpioCtrlRegs.GPAQSEL2.bit.GPIO18=2;
 GpioCtrlRegs.GPAQSEL2.bit.GPIO19=2;  
 asm(" EDIS");
}


void start_stop_system(void)
{
  asm(" EALLOW"); 
 if(Flag_bits.on_off_flag)
  
 {
   EPwm1Regs.ETCLR.bit.INT = 1;
    EPwm1Regs.ETFLG.bit.INT=1;
   EPwm1Regs.ETSEL.bit.INTEN = 1;
   EPwm1Regs.ETFRC.bit.INT = 1;
    while(EPwm1Regs.ETFLG.bit.INT==0); // wait for COMPA event to happen
    EPwm1Regs.AQSFRC.bit.RLDCSF = 3;
    EPwm1Regs.AQSFRC.bit.ACTSFA = 1;
    EPwm1Regs.AQSFRC.bit.ACTSFB = 1;
    EPwm1Regs.AQSFRC.bit.OTSFA = 1;
    EPwm1Regs.AQSFRC.bit.OTSFB = 1;
    EPwm1Regs.AQCSFRC.bit.CSFA = 1;
    EPwm1Regs.AQCSFRC.bit.CSFB = 1;
    EPwm1Regs.DBCTL.bit.OUT_MODE = 0;
// EPwm1Regs.TBCTL.bit.CTRMODE = TB_FREEZE;  // disable counter

// EPwm1Regs.AQSFRC.bit.ZRO = AQ_TOGGLE; //AQ_SET;             // Set PWM1A on event A, up count
 Flag_bits.on_off_flag=0;
 GpioDataRegs.GPBSET.bit.GPIO34 = 1;
  EPwm1Regs.ETPS.bit.INTCNT=1;
 EPwm1Regs.ETFLG.bit.INT=0;
 EPwm1Regs.ETSEL.bit.INTEN = 0;
  EPwm1Regs.ETPS.bit.INTPRD = 1;
 
 }
 
 else  
 {
// EPwm1Regs.TZCLR.bit.OST=1;  // clear previous trips
 EPwm1Regs.AQCTLA.bit.ZRO = AQ_TOGGLE; //AQ_SET;             // Set PWM1A on event A, up count
 EPwm1Regs.DBCTL.bit.IN_MODE = DBA_ALL; // EPWMxA is the source for both delays
 EPwm1Regs.DBCTL.bit.OUT_MODE =DB_FULL_ENABLE;//DB_DISABLE;// Enable Deadband module
 EPwm1Regs.DBCTL.bit.POLSEL = DB_ACTV_HIC; // Active High Complementary (AHC)
   

 

EPwm1Regs.AQSFRC.bit.RLDCSF = 0;
    EPwm1Regs.AQSFRC.bit.ACTSFA = 0;
    EPwm1Regs.AQSFRC.bit.ACTSFB = 0;
    EPwm1Regs.AQSFRC.bit.OTSFA = 0;
    EPwm1Regs.AQSFRC.bit.OTSFB = 0;
    EPwm1Regs.AQCSFRC.bit.CSFA = 0;
    EPwm1Regs.AQCSFRC.bit.CSFB = 1;
    EPwm1Regs.DBCTL.bit.OUT_MODE = 3;


/* EPwm1Regs.TBCTR = 0x0000;    // Clear timer counter
  EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UP; // Symmetrical mode*/

 Flag_bits.on_off_flag=1;
 GpioDataRegs.GPBCLEAR.bit.GPIO34 = 1;
 }
 asm(" EDIS");
}


void increase_current(void)
{
 i_set++;
 if(i_set > MAX_CURRENT) i_set= MAX_CURRENT;
 i_set_count = i_set*ADC_FULLSCALE_COUNT/MAX_CURRENT;

// if(!Flag_bits.mode_flag)     // if not in closed loop mode increase
        // the increase the freq.
 {
 pwm_freq = FREQ_MAX - i_set*FREQ_STEPS;
 pwm_period = (unsigned long) 60000000L/pwm_freq/2;  //60MHz/19kHZ/2
 EPwm1Regs.TBPRD = pwm_period;;  //{ EPwm1Regs.TBCTR=
 }

}

void decrease_current(void)
{

 i_set--;
 if(i_set < MIN_CURRENT) i_set = MIN_CURRENT;
 i_set_count = i_set*ADC_FULLSCALE_COUNT/MAX_CURRENT;

// if(!Flag_bits.mode_flag)     // if not in closed loop mode increase
        // the increase the freq.
 {
 pwm_freq = FREQ_MAX - i_set*FREQ_STEPS;
 pwm_period = (unsigned long) 60000000L/pwm_freq/2;  //60MHz/19kHZ/2
 EPwm1Regs.TBPRD = pwm_period;;  //{ EPwm1Regs.TBCTR=
 }

}

 

Uint16 read_key(void)
{
Uint16 key=INVALIED_KEY;
if(GpioDataRegs.GPADAT.bit.GPIO16 ==0)
 {
  DelayUs(20000);
  if(GpioDataRegs.GPADAT.bit.GPIO16 ==0)  key = STRAT_STOP_KEY;
  while(!GpioDataRegs.GPADAT.bit.GPIO16);
 }


if(GpioDataRegs.GPADAT.bit.GPIO17 ==0)
 {
  DelayUs(20000);
  if(GpioDataRegs.GPADAT.bit.GPIO17 ==0)  key = MODE_KEY;
  while(!GpioDataRegs.GPADAT.bit.GPIO17);
 }

if(GpioDataRegs.GPADAT.bit.GPIO18 ==0)
 {
  DelayUs(0xffff);
  if(GpioDataRegs.GPADAT.bit.GPIO18 ==0)  key = INCREASE_KEY;
  while(!GpioDataRegs.GPADAT.bit.GPIO18);
 }

if(GpioDataRegs.GPADAT.bit.GPIO19 ==0)
 {
  DelayUs(0xffff);
  if(GpioDataRegs.GPADAT.bit.GPIO19 ==0)  key = DECREASE_KEY;
  while(!GpioDataRegs.GPADAT.bit.GPIO19);
 }


return key;

}


void start_system(void)
{
  for(i= MIN_CURRENT;i<i_set;i++)

  i_set_count = i*ADC_FULLSCALE_COUNT/MAX_CURRENT;

DelayUs(500);

}

please help me
regards:vinod sonkar

  • Vinod,

    It is very difficult to provide an educated guess because I don't have your system, but whenever you are working with real-time systems (especially high-power), extra care must be taken when the debugger is halted, independently of the code running in the target. From the CCSv4 standpoint, halting the debugger means a complete stop at that point in the code, therefore any intermediate calculations based on ADC input values, or required to update PWM output registers will be completely halted.

    Therefore, although I am not an expert in control systems, glitches should be expected if the code stops suddenly and the outputs of your rectifier are in specific states that could cause a spike in the output voltage or even worse - in other words, before halting the target you have to be sure your PWM outputs are zero or at least don't change suddenly.

    As an alternative you can implement specific control points in your source code to monitor its status, but I think the experts in the C2000 forum will have much better ideas, therefore I will move this post there.

    Hope this helps,

    Rafael