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.

TMS320F280049C-Q1: Sine wave generation frequency offset

Part Number: TMS320F280049C-Q1
Other Parts Discussed in Thread: C2000WARE

Hi all,

     I am trying to generate a sinusoidal signal of around 10 KHz using the following code from F280049C.

// Initialization

ConfigCpuTimer(&CpuTimer0, 100, 5);  

// ISR

wt = wt + Ts_Freq; // Ts_Freq = 0.05 = 10 KHz * 5e-6; Ts = 5e-6 (200 KHz)

if (wt > 1.0)

    wt = wt - 1.0;

else if (wt < -1.0)

    wt = wt + 1.0;

else

    wt = wt;

sin_gen = __sinpuf32(wt);

  The output is given to a DAC and filtered using a BPF. The generated signal is sinusoidal but with an offseted frequency of around 6-7 Hz. This is same for any"Freq" given. All variables are in single float.

   I have saved the output in DSC internal memory (for around 7000 samples due to memory limitation) and took an FFT which gave a peak at 3.0 Hz frequency offset from the set value.

  What may be the reason for the same ?

Thanks and Regards

    Karthik 

  • Hi Karthik,

    Are you running the code from the internal oscillator?

  • Hi Frank,

        I am using external crystal, same as the one in launch pad xl.

    Thanks and Regards

         Karthik 

  • Karthik,

    We have a dac sine wave example in C2000Ware for the F2838x device (C2000Ware_version\driverlib\f2838x\examples\c28x\dac\buffdac_ex3_sine). This should work with minor modifications for the F28004x device. Can you give that a try and let us know?

  • Hi Frank,

        Thanks for the reply. I have gone through the example but couldn't get much on it since they have used driverlib functions a lot. I am not familiar with driverlib and developed applications based on bit field approaches. Is it possible to figure out what exactly is wrong with the code ?  I have rechecked the same with a precision lock-in amplifier and observed the frequency offset. I also tried taking FFT based on internal RAM stored values which I thin is not reliable due to limited number of samples.

      Thanks and Regards

           Karthik R

  • Hi Karthik,

    I understand. The reason why I suggested trying out our C2000Ware examples instead of debugging your version is because we have already tested our examples and know that they work and hence you can use our examples as a starting point.

    I recommended the driverlib versions because they are easier to port across devices. Nevertheless, if you prefer the bit-field versions, please port the ones in these locations to the F28004x device:

    1. C2000Ware_version\device_support\f2837xd\examples\cpu1\buffdac_sine_dma\cpu01.

    2. C2000Ware_version\device_support\f2837xd\examples\cpu1\buffdac_sine\cpu01.

    The dma version (#1) might be simpler to port so try that one first. It might actually suit your application better than the CPU one.

    Give it a try and let us know how it goes.

  • Hi Frank,

     I have gone through the code. The singen example has integer out where I need float value. So I tried using intrinsic sin function from math.h. It is also having the same frequency offset issue. I tried for different sampling frequencies and different floating point formats.

      On further notice it was found that my 200KHz CPUTimer0 interrupt is having a jitter of 100ns. This is causing an uncertainty in my DAC update rate. But the frequency is repeatable and accurate even to 1 mHz but have an offset. So I am not sure whether this is the reason. I have not used any other interrupts. The jitter is still present even if I comment all my application code and simply put a while(1). The same issue is observed on launchpad as wall as our own dedicated board. Both uses the same crystal though.

       Thanks and Regards

           Karthik R

  • Hi Karthik,

    I need to try this in the lab. Please expect a response by mid next week.

  • Hi Karthik,

    Sorry about the delay. Still looking into this and wanted to give you an update. I'm not quite seeing the frequency shift. Can you let me know what you see when you output a 1KHz sine. If possible, please report the min/max frequency you see for 1KHz. Please take these measurements for both the launchpad and your dedicated board and let us know. Thanks.

  • Hi Frank,

        Sorry for late reply due to the present situations. 

     In the F280049C Launchpad, I am using CPUTimer0 and configuring it for generating an interrupt every 10us (100 KHz) using the code below.

    //.......Initialization Functions

    ConfigCpuTimer(&CpuTimer0, 100, 10);

    CpuTimer0Regs.TCR.all = 0x4000;

    //.......Initialization Functions

    while(1)

    {

       // Application Code

    }

       I am using a GPIO to Toggle in the first instruction under the CPUTimer0 ISR to monitor the loop frequency.
     
    __interrupt void cpuTimer0ISR(void)
    {
        GpioDataRegs.GPBTOGGLE.bit.GPIOXX  =  1;

        CpuTimer0.InterruptCount++;
        ........
        ........
        ........
        PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
    }
     
      If I monitor the GPIO on oscilloscope there is a jitter in the GPIO output of the order of 100ns as shown below. The waveform should be in the middle of the cursors to have exact 10 us period but its jittering between 2 cursor points. Whether my sine frequency offset is fundamentally due to this ??

      Thanks and regards

        Karthik R

  • Hi Karthik,

    No problem. Thanks for providing the extra details. I had to move off from debugging this due to the delayed response but will get back to it in a couple of days. Expect an update on Friday.