

/**
 * main.c
 */
#include"Peripheral.h"
#include"global.h"
#include<math.h>//lab 5-2

int main(void)
{
        InitSysCtrl();//Initialize the system control.
        DINT;// disable the CPU interrupt.
        InitPieCtrl();// initialize the PIE control register to their default state.
        IER = 0x0000;// Disable the CPU interrupt.
        IFR = 0x0000;// Clear the CPU flag
        InitPieVectTable();// Initialize the PIE vector table

        Setup_GPIO() ;
        Setup_ePWM();// LAB 4
        Setup_ADC();//LAB 6
        Setup_DAC();
        Setup_CMPSS();
        CLA1_ConfigCLAMemory();
            CLA1_InitCpu1Cla1();

         EALLOW;
          PieVectTable.TIMER0_INT = &isr_cpu_timer0;
          PieVectTable.ADCA1_INT=&isr_adc;  //lab 6
          PieVectTable.EPWM1_TZ_INT=&isr_epwm_trip;
          PieCtrlRegs.PIEIER1.bit.INTx7=1;//PIE IER for timer0;
          PieCtrlRegs.PIEIER1.bit.INTx1=1;//pie IER FOR ADC
          PieCtrlRegs.PIEIER2.bit.INTx1=1;//Enable the pie trip zone 1 interrupt
          EDIS;
          IER|=M_INT1|M_INT2;

          InitCpuTimers();   // For this example, only initialize the Cpu Timers


           ConfigCpuTimer(&CpuTimer0, 200, 1000);//1us, 1000=1ms

           // To ensure precise timing, use write-only instructions to write to the entire
           // register. Therefore, if any of the configuration bits are changed in
           // ConfigCpuTimer and InitCpuTimers (in F2837xD_cputimervars.h), the below
           // settings must also be updated.
           //
           CpuTimer0Regs.TCR.all = 0x4001;//0100 0000 0000 0001  //14 bit TIE, 4bit, TSS=0 start the timer.// che
               //checkout why there is 01
           SOGI_init(50,5e-5, &v_pll);
           SOGI_coeff_update(5e-5, 314.1593, 0.7,&v_pll);
           SOGI_init(50, 5e-5, &cla1_pll);
           SOGI_coeff_update(5e-5, 314.1593, 0.7, &cla1_pll);
           //SOGI_init(60, 32.5520833E-06, &cla1_pll);
          //SOGI_coeff_update(32.5520833E-06, 376.99112, 0.7, &cla1_pll);
          EINT;     //enable the global interrupt INTM
          ERTM;// ENABLE THE GLOBAL REALTIME Interrupt DBGM£¬ debug the interrupt

       while(1)
       {

       }

        return 0;
}


