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.

single phase grid PLL example code

Dear All,

I am doing single phase grid tie inverter project  based on F28069.I did not have previous experience with TI and code composer studio

I imported some example programs from control suite/device support  examples it is working fine.

Now i want to write the task of single phase grid PLL software. i referred the below link

http://e2e.ti.com/support/microcontrollers/c2000/f/171/t/118563.aspx?pi310980=2

Vac_in=(long)((long)AdcResult.ADCRESULT1<<9)-Offset_Volt;

spll1.AC_input=Vac_in>>1;

SPLL_1ph_run(&spll1);

InvSine = (long)(spll1.sin[0])>>6; // InvSine is in Q15

theta = (long)((long)(spll1.theta[0])>>6)+_IQ15(phase_diff); //theta is in Q15

sen_theta = _IQ15sin(theta) // getting error

and used that code in my project but i am getting error when compilation.If i removed the last line "sen_theta = _IQ15sin(theta)" there are no error in compilation.

instead of that  "sen_theta = _IQ15sin(theta)" i replaced the code  with "sen_theta = sin(theta) * 2 ^ 15;"there are no error in compilation.But i did not get the PLL ramp output

Error message:

#10234-D unresolved symbols remain
unresolved symbol __IQ15sin, first referenced in ./main_SPLL.obj    
#10010 errors encountered during linking; "SPLL1.out" not built    SPLL1

And also what value i have to initialize for the phase difference in the  code

Please help to solve this issue as soon as possible.

Is there any where to simulate the soft PLL is working or not.

Please give any suggestions to solve the problem.

Please mail to me some template working PLLcode  because i want to finish this task this weekend

Email: muthamizh26pg@gmail.com

In the code i used the sin lookup table instead of input sine wave thru ADC channel.

This is the code what i written


#include "F2806x_Device.h"
#include "Solar_IQ.h"
#include "3414.SPLL_1ph.h"

SPLL_1ph spll1;

_iq15 InvSine;
_iq15 theta;
//_iq15 sen_theta;
Uint16 ConversionCount;
int32 Vac_in,Vac_FB;
int32 Offset_Volt;
int32 phase_diff;
int32 sen_theta;


// Prototype statements for functions found within this file.
__interrupt void cpu_timer0_isr(void);

extern void InitSysCtrl(void);
extern void InitPieVectTable(void);
extern void InitPieCtrl(void);

/*signed int sin_table[64]={0,25,49,73,96,118,137,
159,177,193,208,220,231,239,245,249,250,249,245,
239,231,220,208,193,177,159,137,118,96,73,49,25,0,-25,-49,-73,-96,-118,-137,
-159,-177,-193,-208,-220,-231,-239,-245,-249,-250,-249,-245,
-239,-231,-220,-208,-193,-177,-159,-137,-118,-96,-73,-49,-25};*/
/*signed int sin_table[32]={0,25,49,73,96,118,137,
159,177,193,208,220,231,239,245,249,250,249,245,
239,231,220,208,193,177,159,137,118,96,73,49,25};*/

/*float sin_table[108]={0,0.1736,0.3420,0.5,0.6427,0.7660,0.8660,0.9396,0.9848,1,
        0.9848,0.9396,0.8660,0.7660,0.6427,0.5,0.3420,0.1736,0,-0.1736,-0.3420,
        -0.5,-0.6427,-0.7660,-0.8660,-0.9396,-0.9848,-1,-0.9848,-0.9396,-0.8660,
        -0.7660,-0.6427,-0.5,-0.3420,-0.1736,0,0.1736,0.3420,0.5,0.6427,0.7660,0.8660,0.9396,0.9848,1,
        0.9848,0.9396,0.8660,0.7660,0.6427,0.5,0.3420,0.1736,0,-0.1736,-0.3420,
        -0.5,-0.6427,-0.7660,-0.8660,-0.9396,-0.9848,-1,-0.9848,-0.9396,-0.8660,
        -0.7660,-0.6427,-0.5,-0.3420,-0.1736,0,0.1736,0.3420,0.5,0.6427,0.7660,0.8660,0.9396,0.9848,1,
        0.9848,0.9396,0.8660,0.7660,0.6427,0.5,0.3420,0.1736,0,-0.1736,-0.3420,
        -0.5,-0.6427,-0.7660,-0.8660,-0.9396,-0.9848,-1,-0.9848,-0.9396,-0.8660,
        -0.7660,-0.6427,-0.5,-0.3420,-0.1736};*/

float sin_table[36]={0,0.1736,0.3420,0.5,0.6427,0.7660,0.8660,0.9396,0.9848,1,
        0.9848,0.9396,0.8660,0.7660,0.6427,0.5,0.3420,0.1736,0,-0.1736,-0.3420,
        -0.5,-0.6427,-0.7660,-0.8660,-0.9396,-0.9848,-1,-0.9848,-0.9396,-0.8660,
        -0.7660,-0.6427,-0.5,-0.3420,-0.1736};

char index = 0;


void main(void)
{
    InitSysCtrl();

    DINT;
    InitPieCtrl();
    IER = 0x0000;
    IFR = 0x0000;
    InitPieVectTable();

    EALLOW;  // This is needed to write to EALLOW protected registers
    PieVectTable.TINT0 = &cpu_timer0_isr;
    EDIS;    // This is needed to disable write to EALLOW protected registers

    EALLOW;
    GpioCtrlRegs.GPADIR.bit.GPIO31 = 1;
    GpioCtrlRegs.GPBDIR.bit.GPIO34 = 1;
    EDIS;

    InitCpuTimers();   // For this example, only initialize the Cpu Timers
    ConfigCpuTimer(&CpuTimer0,90,50);

    CpuTimer0Regs.TCR.all = 0x4001;

    PieCtrlRegs.PIEIER1.bit.INTx7 = 1;

    IER |= M_INT1;

    EINT;
    ERTM;

    GpioDataRegs.GPASET.bit.GPIO31 = 1;
    GpioDataRegs.GPBSET.bit.GPIO34 = 1;

        SPLL_1ph_init(60,_IQ21(0.00005),&spll1);
        Offset_Volt=_IQ21(0.5); // the input sinusoid is offset with 1.65 V
        phase_diff = 20;

// Step 6. IDLE loop. Just sit and loop forever (optional):
   for(;;)
    {

       ;


    }
}

__interrupt void cpu_timer0_isr(void)
{
   CpuTimer0.InterruptCount++;
   GpioDataRegs.GPBTOGGLE.bit.GPIO34 = 1; // Toggle GPIO34 once per 50 MICROseconds

   spll1.AC_input=(long)sin_table[index] >> 3;;
   SPLL_1ph_run(&spll1);
   InvSine = (long)(spll1.sin[0])>>6; // InvSine is in Q15
   theta = (long)((long)(spll1.theta[0])>>6)+_IQ15(phase_diff); //theta is in Q15
   sen_theta = _IQ15sin(theta);
   //sen_theta = sin(theta) * 2 ^ 15;

   /*spll1.AC_input=(long)sin_table[index] >> 3;
   //spll1.AC_input=(long)inv_meas_vol_inst>>3;
   SPLL_1ph_IQ_MACRO(spll1);
   InvSine     = (long)(spll1.sin)>> 3; */// InvSine is in Q24

   /*index++;
   if(index > 107)
   {
       index = 0;
   }*/


   // Acknowledge this interrupt to receive more interrupts from group 1
   PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
}

Regards,

Muthu