• PUDN用户
    了解作者
  • C/C++
    开发工具
  • 3KB
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • 10 积分
    下载积分
  • 15
    下载次数
  • 2009-11-25 17:39
    上传日期
single phase inverter
si.rar
  • si.c
    7.2KB
内容介绍
#define GLOBAL_Q 24 long GlobalQ = GLOBAL_Q; // Used for GEL & Graph Debug. #include "DSP281x_Device.h" // DSP281x Headerfile Include File #include "DSP281x_Examples.h" // DSP281x Examples Include File #include "IQmathLib.h" // Prototype statements for functions found within this file. //interrupt void eva_timer1_isr(void); interrupt void adc_isr(void); void init_eva_timer1(void); void Gpio_select(void); // Global counts used in this example Uint32 EvaTimer1InterruptCount; _iq m1,theta _iq sa,sb, sc, sa1,sb1,sc1,sa2,sb2,sc2; int n,nn,CMPREGT1; Uint16 VASD; Uint16 VMAS[500]; _iq Vsa; void main(void) { nn=1; CMPREGT1 = 0x186A; // Step 1. Initialize System Control: // PLL, WatchDog, enable Peripheral Clocks // This example function is found in the DSP281x_SysCtrl.c file. InitSysCtrl(); EALLOW; SysCtrlRegs.HISPCP.all = 0x1; // HSPCLK = SYSCLKOUT/6 EDIS; // Step 2. Initalize GPIO: // This example function is found in the DSP281x_Gpio.c file and // illustrates how to set the GPIO to it's default state. InitGpio(); // Skipped for this example // InitGpio(); // Skipped for this example // For this example use the following configuration: Gpio_select();// Step 3. Clear all interrupts and initialize PIE vector table: // Disable CPU interrupts DINT; // Initialize 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 DSP281x_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 DSP281x_DefaultIsr.c. // This function is found in DSP281x_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.T1PINT = &eva_timer1_isr; PieVectTable.ADCINT = &adc_isr; EDIS; // This is needed to disable write to EALLOW protected registers // Step 4. Initialize all the Device Peripherals: // This function is found in DSP281x_InitPeripherals.c // InitPeripherals(); // Not required for this example InitAdc(); // Step 5. User specific code, enable interrupts: // Initialize count values to 0 EvaTimer1InterruptCount = 0; // Enable PIE group 2 interrupt 4 for T1PINT //--> PieCtrlRegs.PIEIER2.all = M_INT4; PieCtrlRegs.PIEIER1.bit.INTx6 = 1; // PieCtrlRegs.PIEIER2.all = M_INT1; // Enable CPU INT2 for T1PINT, INT3 for T2PINT, INT4 for T3PINT // and INT5 for T4PINT: // --> IER |= M_INT2; IER |= M_INT1; // Enable global Interrupts and higher priority real-time debug events: EINT; // Enable Global interrupt INTM ERTM; // Enable Global realtime interrupt DBGM init_eva_timer1(); // GpioDataRegs.GPBDAT.bit.GPIOB6 = 0; // Step 6. IDLE loop. Just sit and loop forever: while(1){} } void init_eva_timer1(void) { // Configure ADC AdcRegs.ADCMAXCONV.all = 0x0000; // Setup 2 conv's on SEQ1 AdcRegs.ADCCHSELSEQ1.bit.CONV00 = 0x0; // Setup ADCINA3 as 1st SEQ1 conv. // AdcRegs.ADCCHSELSEQ1.bit.CONV01 = 0x1; // Setup ADCINA2 as 2nd SEQ1 conv. // AdcRegs.ADCCHSELSEQ1.bit.CONV02 = 0x2; // Setup ADCINA2 as 2nd SEQ1 conv. // AdcRegs.ADCCHSELSEQ1.bit.CONV03 = 0x3; // Setup ADCINA2 as 2nd SEQ1 conv. AdcRegs.ADCTRL2.bit.EVA_SOC_SEQ1 = 1; // Enable EVASOC to start SEQ1 // AdcRegs.ADCTRL2.bit.EVB_SOC_SEQ2=1; AdcRegs.ADCTRL2.bit.INT_ENA_SEQ1 = 1; // Enable SEQ1 interrupt (every EOS) EvaRegs.T1CMPR = 0x0080; // Setup T1 compare value EvaRegs.T1PR = CMPREGT1; // Setup period register // EvaRegs.GPTCONA.bit.T1TOADC = 1; // Enable EVASOC in EVA // EvaRegs.T1CON.all = 0x1042; // Enable timer 1 compare (upcount mode) // Initialize EVA Timer 1: // Setup Timer 1 Registers (EV A) EvaRegs.GPTCONA.all = 0x0050; // T1: Forced low EvbRegs.GPTCONB.all = 0x0050; EvaRegs.GPTCONA.bit.T1TOADC = 1; EvbRegs.T3PR = CMPREGT1; // Period//@@@ EvaRegs.T1CON.all = 0x0842; EvbRegs.T3CON.all = 0x0842; //@@@@@@@@ EvaRegs.CMPR1 = 0x1400; EvaRegs.CMPR2 = 0x1000; EvaRegs.CMPR3 = 0x1000; EvbRegs.CMPR4 = 0x1400;//@@ EvbRegs.CMPR5 = 0x1400;//@@ EvbRegs.CMPR6 = 0x1400;//@@ EvaRegs.ACTRA.all =0x0666; EvaRegs.DBTCONA.all = 0x0FF8; // Enable deadband EvaRegs.COMCONA.all = 0xA600; EvbRegs.ACTRB.all = 0x0666;// EvbRegs.DBTCONB.all = 0x0FF8; // Enable deadband/@2@ EvbRegs.COMCONB.all = 0xA600;//@222 EvaRegs.EVAIMRA.bit.T1PINT = 1; EvaRegs.EVAIFRA.bit.T1PINT = 1; EvaRegs.EVAIMRA.bit.PDPINTA = 1; } interrupt void adc_isr(void) { int32 Tmp; int16 Temp; int16 Temp2; VMAS[nn] = AdcRegs.ADCRESULT0 >>4; Vsa = ((int32)VASD-(int32)(2073))* _IQ(0.0009); //_IQ(0.00048828125); nn++; if (nn==499)nn=1; n = n + 1; if(n ==120) n=0; theta = _IQmpy(_IQ(2*3.14/120),_IQ(n)); sa1 = _IQmpy(m1,_IQsin(theta)); sb1=-sa1; EvaTimer1InterruptCount++; AdcRegs.ADCTRL2.bit.RST_SEQ1 = 1; // Reset SEQ1 AdcRegs.ADCST.bit.INT_SEQ1_CLR = 1; // Clear INT SEQ1 bit PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; return; } void Gpio_select(void) { Uint16 var1; Uint16 var2; Uint16 var3; var1= 0x0000; // sets GPIO Muxs as I/Os var2= 0xFFFF; // sets GPIO DIR as outputs var3= 0x0000; // sets the Input qualifier values EALLOW; GpioMuxRegs.GPAMUX.all=var1; GpioMuxRegs.GPBMUX.all=var1; GpioMuxRegs.GPDMUX.all=var1; GpioMuxRegs.GPFMUX.all=var1; GpioMuxRegs.GPEMUX.all=var1; GpioMuxRegs.GPGMUX.all=var1; GpioMuxRegs.GPADIR.all=var2; // GPIO PORTs as output GpioMuxRegs.GPBDIR.all=var2; // GPIO DIR select GPIOs as output GpioMuxRegs.GPDDIR.all=var2; GpioMuxRegs.GPEDIR.all=var2; GpioMuxRegs.GPFDIR.all=var2; GpioMuxRegs.GPGDIR.all=var2; GpioMuxRegs.GPAQUAL.all=var3; // Set GPIO input qualifier values GpioMuxRegs.GPBQUAL.all=var3; GpioMuxRegs.GPDQUAL.all=var3; GpioMuxRegs.GPEQUAL.all=var3; // GpioMuxRegs.GPAMUX.bit.T1PWM_GPIOA6=1; // GpioMuxRegs.GPBDIR.bit.GPIOB6 = 1; // GPIO DIR select GPIOs as output GpioMuxRegs.GPDMUX.bit.T1CTRIP_PDPA_GPIOD0 = 1; // GpioMuxRegs.GPBMUX.bit.T3PWM_GPIOB6=1;//************* GpioMuxRegs.GPDMUX.bit.T3CTRIP_PDPB_GPIOD5 = 1;//************* // Initialize only GPAMUX and GPBMUX for this test // Enable PWM pins GpioMuxRegs.GPAMUX.all = 0x00FF; // EVA PWM 1-6 pins GpioMuxRegs.GPBMUX.all = 0x003F; // EVB PWM 7-12 pins EDIS; } //=========================================================================== // No more. //===========================================================================
评论
    相关推荐