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.

TMS320F28335: sine wave generation using a ramp

Part Number: TMS320F28335
Other Parts Discussed in Thread: C2000WARE

Dear all,

I am struggling to generate a sine wave using iqmath library. However I would like to share my algorithm I devised. I ended up getting a sin wave shown in the image which is a screenshot of CCS while running the program given below.

Step1:  Generate a Ramp incrementing and resetiing a integer i

Step2: Convert it into p.u and then convert into iq format

Step3: Substitute it in IQ sin function

Step4: Convert it into floating point

Step5: store in a buffer

Program:

int i,o
_iq j,cons,k,out2

//ramp generation
i= i+1;
if(i> 100) i=0;

//convert the ramp into a p.u(iq)
j=_IQ18(i);
cons = _IQ18(100);
k=_IQ18div(j,cons);

//substitute the p.u into sin function
out2=_IQ18sin(k*2*PI);

//convert sine values to floating number
o= _IQ18toF(out2);

//scale to 100

o=o*100;

//store in a buffer to graph it on CCS

AdcBuf[index] =o;
index++;
if(index == AdcBufLen) index = 0;

Regards,

Rajesh BN.

  • Hi,

    Due to Thanksgiving Holiday, the subject matter expert is out of office. We will get back to you next week.

    Thanks & Regards,
    Santosh

  • Hello Mr. Santosh,

    Anyone available today to sort out the above issue!

    Regards,

    Rajesh BN.

  • Hi Rajesh,

    My sincere apology for delay in responding. I will send reminder to the subject matter expert now. We should expect the response later today.

    Regards, Santosh

  • Rajesh,

    Conceptually, your approach looks correct. With this, you should generate one cycle of a sine wave, 100 samples long. When you graph this, you should see one cycle every 100 samples. From the figure, this does not appear to be the case. It seems like the cycle is ending sooner than 100 cycles, and you are getting about 1.5 cycles per 100 samples. I also don't know what the value of AdcBufLen is. Have you looked at the generated values to understand the behavior?

    A simpler approach may be to use our DCL reference generator.

    C:\ti\c2000\C2000Ware_4_02_00_00\libraries\control\DCL\c28\docs/DCL Reference Generator Users Guide

    Thanks,

    Sira

  • Dear Sira,

    I use this sin data not to generate a reference rather I use it in the calculations during realtime where I get acquire the theta from the real-world. Could you please suggest some other way.

    Coming to my observations, I suspect the IQ number(for instance 18 in the above example) because I remember a particular IQ has got a fixed number of samples. For instance, IQ30 has got 512 samples(subject to correction). I don't know how many samples does IQ18 has got and this suspiciction stems from the erratic behaviour of sine the iqsin() generates from the ramp. I get irregular sin waveforms for different divisors(100 in the above example).

    Coming to the clarification regarding the buffer size, it's 200 and I even checked keeping the buffer length and samples size same and it didn't give any fruitful results.

    The sin generate section of my code is below. 

    i= i+1;

      if(i> 512)

       {i=0;

       }

      j=_IQ18(i);

      cons = _IQ18(512);

      k=_IQ18div(j,cons);

      out2=_IQ18cos(k*PI);

      o= _IQ18toF(out2);

      sino = _IQ18sin(k*PI)

      coso = _IQ18cos(k*PI)

                //data acquire buffer

      o=o*100;

                          AdcBuf[index] =o;

               index++;

               if(index == AdcBufLen) index = 0;

    Kindly guide me! I

    Looking forward,

    Rajesh BN.

  • Rajesh,

    The DCL Reference generator is meant to be used in real-time applications i.e. run-time code.

    Some more detailed debugging is necessary here - you need to look at the individual values for a specific index, and trace the values at each step of your algorithm, and see if there's anything unexpected.

    I don't understand what this comment means "I remember a particular IQ has got a fixed number of samples. For instance, IQ30 has got 512 samples(subject to correction). I don't know how many samples does IQ18 has got "

    Thanks,

    Sira

  • Sira,

    I am referring 'C2000 teaching rom' for programming microcontroller. There is a module that explains the realisation of PWM. Iqmath is introduced in one of the sections of this module which talks about sinusoidal PWM generation. It says, there are 512 samples in IQ30. So, this is the number I mentioned in the correspondence. I've attached the document below.

    Anyways, Kindly clarify 3 things

    1. if we choose a particular IQ format for a calculation, are there a finite number of sinusoidal samples?

    2. Can we add/multiply two different IQ formats?

    3.  To graph a waveform on CCS, is it mandatory to select the buffer length same as the number of samples present in a sine period?

    Thanks,

    Rajesh.

     

  • Rajesh,

    Please give me a day or so to review and get back to you.

    Thanks,

    Sira

  • Sira,

    I solved the problem! 

    Thanks,

    Rajesh.