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

📄 convert_assembak_isa20060613.c

📁 DSP2812编写的模拟退火算法改进程序
💻 C
📖 第 1 页 / 共 2 页
字号:
	EvaRegs.T1CNT = 0x0000;      // Timer1 counter
	// TMODE = continuous up/down
	// Timer enable
	// Timer compare enable
	EvaRegs.T1CON.all = 0x0843;//0x0843 can only regualte the foreland of pulse;
	//EvaRegs.T1CON.all = 0x0847;//0x0847 can regulate both the foreland and backland of pulse
	                                       //15-14 00 一旦仿真挂起,立即停止
	                                       //13     0  reserved
	                                       //12-11 01  Continuous-Up/-Down Count Mode
	                                       //10-8 000  Input clock prescaler: 000 x/1(x = HSPCLK)
	                                       //7    0    Use own TENABLE bit
	                                       //6    1    Enable timer operations
	                                       //5-4  00  Internal Clock source(i.e., HSPCLK)
	                                       //3-2  00  Timer compare register reload When counter is 0
	                                       //01    Timer compare register reload When counter value is 0 or equals period register value
	                                       //1    1   Enable timer compare operation
	                                       //0    1   Use T1PR (in case of EVA) or T3PR (in case of EVB) as period
	                                       //register ignoring own period register
	                                       // Initalize EVA Timer2 
	EvaRegs.T2PR = 0x0EA6;       // Timer2 period
	EvaRegs.T2CMPR = 0x03C0;     // Timer2 compare
	EvaRegs.T2CNT = 0x0000;      // Timer2 counter
	// TMODE = continuous up/down
	// Timer enable
	// Timer compare enable
	EvaRegs.T2CON.all = 0x0000;//15-14 00 一旦仿真挂起,立即停止
	                          //13     0  reserved
	                          //12-11 00  Stop/Hold Count Mode
	                          //10-8 000  Input clock prescaler: 000 x/1(x = HSPCLK)
	                          //7    0    Use own TENABLE bit
	                          //6    0    disable timer operations(the timer is put in hold and the prescalercounter is reset)
	                          //5-4  00  Internal Clock source(i.e., HSPCLK)
	                          //3-2  00  Timer compare register reload When counter is 0
	                          //1    0   disable timer compare operation
	                          //0    0   Use own period register
	// Setup T1PWM and T2PWM
	// Drive T1/T2 PWM by compare logic
	EvaRegs.GPTCONA.bit.TCMPOE = 0;
	// Polarity of GP Timer 1 Compare = Active low
	EvaRegs.GPTCONA.bit.T1TOADC=0;
	EvaRegs.GPTCONA.bit.T2TOADC=1;
	//T2UFINT starts ADC
	EvaRegs.GPTCONA.bit.T1PIN = 1;
	// Polarity of GP Timer 2 Compare = Active high
	EvaRegs.GPTCONA.bit.T2PIN = 2;
	// Enable compare for PWM1-PWM6
	EvaRegs.CMPR1 = 0x0400;
	EvaRegs.CMPR2 = 0x0400;
	EvaRegs.CMPR3 = 0x0400;
	// Compare action control.  Action that takes place
	// on a cmpare event
	// output pin 2 CMPR1 - active high
	// output pin 1 CMPR1 - active low
	// output pin 4 CMPR2 - active high
	// output pin 3 CMPR2 - active low
	// output pin 6 CMPR3 - active high
	// output pin 5 CMPR3 - active low
	EvaRegs.ACTRA.all = 0x0969;
	EvaRegs.DBTCONA.all = 0x0AF8; // 2us deadband
	EvaRegs.COMCONA.all = 0xA6E0;
	EvaRegs.EVAIMRA .all =0x0280;//Enable T1UFINT,T1CINT
	EvaRegs.EVAIMRB.bit.T2UFINT =1; //Enable T2UFINT
	EvaRegs.EVAIFRA .all =0xFFFF;
	EvaRegs.EVAIFRB .all =0xFFFF;
	
}
	
void init_evb()
{
	// EVB Configure T3PWM, T4PWM and PWM7-PWM12
	// Step 1 - Initialize the Timers
	// Initialize EVB Timer3 
	// Timer3 controls T3PWM and PWM7-12
  EvbRegs.T3PR = 0xFFFF;       // Timer3 period
  EvbRegs.T3CMPR = 0x3C00;     // Timer3 compare
  EvbRegs.T3CNT = 0x0000;      // Timer3 counter
  // TMODE = continuous up/down
  // Timer enable
  // Timer compare enable
  EvbRegs.T3CON.all = 0x1042;   

  // Initialize EVB Timer4 
  // Timer4 controls T4PWM
  EvbRegs.T4PR = 0x00FF;       // Timer4 period
  EvbRegs.T4CMPR = 0x0030;     // Timer4 compare
  EvbRegs.T4CNT = 0x0000;      // Timer4 counter
  // TMODE = continuous up/down
  // Timer enable
  // Timer compare enable
  EvbRegs.T4CON.all = 0x1042;   

  // Setup T3PWM and T4PWM
  // Drive T3/T4 PWM by compare logic
  EvbRegs.GPTCONB.bit.TCMPOE = 1;
  // Polarity of GP Timer 3 Compare = Active low
  EvbRegs.GPTCONB.bit.T3PIN = 1;
  // Polarity of GP Timer 4 Compare = Active high
  EvbRegs.GPTCONB.bit.T4PIN = 2;
 
  // Enable compare for PWM7-PWM12
  EvbRegs.CMPR4 = 0x0C00;
  EvbRegs.CMPR5 = 0x3C00;
  EvbRegs.CMPR6 = 0xFC00;
    
  // Compare action control.  Action that takes place
  // on a cmpare event
  // output pin 1 CMPR4 - active high
  // output pin 2 CMPR4 - active low
  // output pin 3 CMPR5 - active high
  // output pin 4 CMPR5 - active low
  // output pin 5 CMPR6 - active high
  // output pin 6 CMPR6 - active low
  EvbRegs.ACTRB.all = 0x0666;
  EvbRegs.DBTCONB.all = 0x0000; // Disable deadband
  EvbRegs.COMCONB.all = 0xA600;
}


void InitAdc(void)
{
	extern void DSP28x_usDelay(Uint32 Count);
	
    // To powerup the ADC the ADCENCLK bit should be set first to enable
    // clocks, followed by powering up the bandgap and reference circuitry.
    // After a 5ms delay the rest of the ADC can be powered up. After ADC
    // powerup, another 20us delay is required before performing the first
    // ADC conversion. Please note that for the delay function below to
    // operate correctly the CPU_CLOCK_SPEED define statement in the
    // DSP28_Examples.h file must contain the correct CPU clock period in
    // nanoseconds. For example:

	AdcRegs.ADCTRL3.bit.ADCBGRFDN = 0x3;	// Power up bandgap/reference circuitry
	DELAY_US(ADC_usDELAY);                  // Delay before powering up rest of ADC
	AdcRegs.ADCTRL3.bit.ADCPWDN = 1;		// Power up rest of ADC
	DELAY_US(ADC_usDELAY2);                 // Delay after powering up ADC
}


//ISR
interrupt void T1PINTIsr(void)
{   
    if (step<99)
    {
    //CMPR_LAST=sinv[step]*M+3750;
    EvaRegs.CMPR1 = CMPR_LAST;
    EvaRegs.CMPR2 = CMPR_LAST-320;  //160 is used for generating PWM3,PWM4 2us deadband
    EvaRegs.CMPR3 = CMPR_LAST-DIF;
    }
    else
    {
    //CMPR_LAST=3750-M*sinv[step-100];
    EvaRegs.CMPR1 = CMPR_LAST;
    if ((CMPR_LAST-320)>0)
      {EvaRegs.CMPR2 = CMPR_LAST-320;}
    else
      {EvaRegs.CMPR2 =0;}
    EvaRegs.CMPR3 = CMPR_LAST-DIF;
    }
    
    
    EvaRegs.EVAIFRA .all =0x0080;
	PieCtrlRegs.PIEACK.all=0x0002;       // Issue PIE ack
}

interrupt void T1UFINTIsr(void)
{  //extern void DSP28x_WaveCon(void);
   
  if ((CMPR_LAST1>1875)&(CMPR_LAST1<5625))
  {
  //use T2 for CM current collection
    EvaRegs.T2CNT = 0x0000;      // Timer2 counter
    EvaRegs.T2PR = 7550-(CMPR_LAST1>>1);       // Timer2 period,7605=7500+105,7500---period,105---1.4us
    CMPR_LAST=EvaRegs.T2CNT;    //CMPR_LAST清0
    EvaRegs.T2CON.all = 0x4842; //15-14 01 一旦仿真挂起,在当前周期结束后停止
                              //13     0  reserved
                              //12-11 01  Continuous-Up/-Down Count Mode
                              //10-8 000  Input clock prescaler: 000 x/1(x = HSPCLK)
                              //7    0    Use own TENABLE bit
                              //6    1    Enable timer operations
                              //5-4  00  Internal Clock source(i.e., HSPCLK)
                              //3-2  00  Timer compare register reload When counter is 0
                              //1    1   Enable Timer Operation
                              //0    0   Use own period register
  
  GpioDataRegs.GPFDAT.bit.GPIOF10  =0;
  
  //ADC for CM current
    AdcRegs.ADCTRL2.all = 0x4900;
    AdcRegs.ADCMAXCONV.all=0xF;
    AdcRegs.ADCCHSELSEQ1.bit.CONV00 = 0x8;    
    AdcRegs.ADCCHSELSEQ1.bit.CONV01 = 0x8;
    AdcRegs.ADCCHSELSEQ1.bit.CONV02 = 0x8;
    AdcRegs.ADCCHSELSEQ1.bit.CONV03 = 0x8; 
    AdcRegs.ADCCHSELSEQ2.bit.CONV04 = 0x8;    
    AdcRegs.ADCCHSELSEQ2.bit.CONV05 = 0x8;
    AdcRegs.ADCCHSELSEQ2.bit.CONV06 = 0x8;
    AdcRegs.ADCCHSELSEQ2.bit.CONV07 = 0x8; 
    AdcRegs.ADCCHSELSEQ3.bit.CONV08 = 0x8;    
    AdcRegs.ADCCHSELSEQ3.bit.CONV09 = 0x8;
    AdcRegs.ADCCHSELSEQ3.bit.CONV10 = 0x8;
    AdcRegs.ADCCHSELSEQ3.bit.CONV11 = 0x8; 
    AdcRegs.ADCCHSELSEQ4.bit.CONV12 = 0x8;    
    AdcRegs.ADCCHSELSEQ4.bit.CONV13 = 0x8;
    AdcRegs.ADCCHSELSEQ4.bit.CONV14 = 0x8;
    AdcRegs.ADCCHSELSEQ4.bit.CONV15 = 0x8; 
  }    
//claculate the energy of the CM current
  for(BX=2;BX<14;BX++)
  {
  CM[BX]=((CM[BX-2]+CM[BX-1]+CM[BX+1]+CM[BX+2])>>2);
  }
  for(BX=0;BX<16;BX++)
  {
  CM_energy=CM_energy+((CM[BX]*CM[BX])>>10);
  if (CM[BX]>CM_largest)
  {CM_largest=CM[BX];}
  else if (CM[BX]>CM_larger)
  {CM_larger=CM[BX];}
  }
  CM_energy=CM_energy+((CM_largest*CM_largest+CM_larger*CM_larger)<<1);
  energy_step=energy_step-1;
  CM_largest=CM_larger=0;
//put the value to the CMPR for the SIN output
    //WaveCon();
    if  (AX>1870)
    	{
      AX=1870;
      }
   if (step<99)
    {
    	CMPR_LAST=sinv[step]*M+3750;
       EvaRegs.CMPR1 = CMPR_LAST;
       EvaRegs.CMPR2 = CMPR_LAST-320;  //320 is used for generating PWM3,PWM4 2us deadband
       EvaRegs.CMPR3 = CMPR_LAST+DIF;
       CMPR_LAST1=sinv[step+1]*M+3750;
    }
    else
    {
    	 CMPR_LAST= 3750-M*sinv[step-100];
    	 EvaRegs.CMPR1=CMPR_LAST;
    	 if ((CMPR_LAST-320)>0)
    	 	  {EvaRegs.CMPR2 = CMPR_LAST-320;}
    	 else
    	 	  {EvaRegs.CMPR2 =0;}
    	 EvaRegs.CMPR3 = CMPR_LAST+DIF;
    	 CMPR_LAST1= 3750-M*sinv[step-99];
    }
    if (step+1>199)
    {
    	step=0;
    }
    else
    {
    	step=step+1;
    }

	
	EvaRegs.EVAIFRA .all =0x0200;
	PieCtrlRegs.PIEACK.all=0x0002;       // Issue PIE ack
}



interrupt void T2UFINTIsr(void)
{
 
  GpioDataRegs.GPFDAT.bit.GPIOF10 =1;
  EvaRegs.T2CON.all = 0x4802;//15-14 01 一旦仿真挂起,在当前周期结束后停止
                              //13     0  reserved
                              //12-11 01  Continuous-Up/-Down Count Mode
                              //10-8 000  Input clock prescaler: 000 x/1(x = HSPCLK)
                              //7    0    Use own TENABLE bit
                              //6    0    Disable timer operation (the timer is put in hold and the prescaler
                                          //counter is reset)
                              //5-4  00  Internal Clock source(i.e., HSPCLK)
                              //3-2  00  Timer compare register reload When counter is 0
                              //1    1   Enable timer operations
                              //0    0   Use own period register
  
  EvaRegs.EVAIFRB.bit.T2UFINT  =1;
  PieCtrlRegs.PIEACK.all=0x0004;       // Issue PIE ack
 
}
interrupt void ADCINTIsr(void)
{
//get ADC result
    while (AdcRegs.ADCST.bit.INT_SEQ1== 0) {} // Wait for interrupt
    // Software wait = (HISPCP*2) * (ADCCLKPS*2) * (CPS+1) cycles
    //               = (1*2)      * (3*2)        * (0+1)   = 12 cycles
    asm(" RPT #11 || NOP");
    AdcRegs.ADCST.bit.INT_SEQ1_CLR = 1;
    CM[0] =((AdcRegs.ADCRESULT0>>4) ); 
    CM[1] =((AdcRegs.ADCRESULT1>>4) );    
    CM[2] =((AdcRegs.ADCRESULT2>>4) );
    CM[3] =((AdcRegs.ADCRESULT3>>4) );
    CM[4] =((AdcRegs.ADCRESULT4>>4) ); 
    CM[5] =((AdcRegs.ADCRESULT5>>4) );    
    CM[6] =((AdcRegs.ADCRESULT6>>4) );
    CM[7] =((AdcRegs.ADCRESULT7>>4) );
    CM[8] =((AdcRegs.ADCRESULT8>>4) ); 
    CM[9] =((AdcRegs.ADCRESULT9>>4) );    
    CM[10] =((AdcRegs.ADCRESULT10>>4) );
    CM[11] =((AdcRegs.ADCRESULT11>>4) );
    CM[12] =((AdcRegs.ADCRESULT12>>4) ); 
    CM[13] =((AdcRegs.ADCRESULT13>>4) );    
    CM[14] =((AdcRegs.ADCRESULT14>>4) );
    CM[15] =((AdcRegs.ADCRESULT15>>4) );
//AdcRegs.ADCST .bit .INT_SEQ1_CLR =1;
    PieCtrlRegs.PIEACK.all=0x0001;       // Issue PIE ack
}
//===========================================================================
// No more.
//===========================================================================

⌨️ 快捷键说明

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