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.

errors in the sine triangle PWM

Other Parts Discussed in Thread: TMS320F2812, CONTROLSUITE

i am using TMS320F2812  processor and the ccsV4. i want to generate sine triangle PWM  in which sine wave is generated using the some array of  of numbers(taken 1000 instantaneous values for one cycle and converted  as digital values using the formula (4095* instantaneous value/3)). i have written the code but it is giving the error. here i am attaching the code. please help me.

4848.test.c
Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#define fc 2000;
#define fs 50;
#define ma 1;
main()
{
// Step 1. Initialize System Control:
// PLL, WatchDog, enable Peripheral Clocks
// This example function is found in the DSP281x_SysCtrl.c file.
InitSysCtrl();
// 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
EALLOW;
// Enable PWM pins
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

  • Hi Kiran,

    First suggestion is try the sine wave generation library provided in control suite. See if it meets your requirement. It simplifies the wave generation process.

    Vivek

  • From your code i can see that you need to generate a sine wave of 50Hz (=fs) and for that the carrier frequency is 2KHz( = fc). If my assumptions are correct then you need to have only (2000/50) values only in your sine table. Which = 40. Your sine table has more values than that.

    Vivek

  • Thank you sir, i have 1000 samples of sine wave and i will take first sample after that 26th sample for 50HZ. for 40HZ after 1st sample 21st will be taken. this is for V/F control. number of samples are not the matter but the interrupts or some declaration error may be there which i am facing difficult to find out. help me please....

  • sir,   control suite means?

  • So one more thing i noticed is you are copying ka, kb, kc values to CMPA. Won't ka, kb and kc be negative for sine values from 180degs to 360 degs. And that cannot be directly copied to CMPR because CMPR takes only positive values.

    Vivek

    (P.S: Call me Vivek please.)

  • Control Suite is a complete software package  for C2000 Family. Though it is mostly for use with higher end C2000, some codes can reused for F2812. 

    http://www.ti.com/tool/controlsuite

    Vivek

  • thank you sir, can i get any solution for rectifing the -ve sign.

  • Can you explain the math to me a little bit. How did you generate the sine table? Does it contain CMPR values staightaway?

    Vivek

  • Sir, i have taken 1000 samples for one cycle in MATLAB. and i have converted all these instantaneous values to digital values by using the formula (4095* instantaneous value)/3 . these i have taken in a array format. somebody suggested me this, but actually i donot know whether it is correct or not.

  • Vivek -

     

    I'm not sure how compatible the code in the Signal Generation section of the Control Suite will be with the F28x series processors - I'm implementing one in my code and it appears that there's a lookup table in the Delfino series that the modules rely on (if I read it correctly) and all the examples are written for the Delfino series. One would have to check if the F28x has the same table. they are .asm modules that are C-callable, so if the chip will support it, he can use them.

     

     

    Tony

     

  • Kiran,

     

    If this helps as well, I have attached a pdf from the control suite that describes the C-callable .asm modules, as well as a sample C program that utilizes one of the modules. I suggest, as Vivek did, that you download ControlSuite from TI and view the modules. Review the datasheet on your processor to see if there's compatibility. This Control Suite is a wealth of information and example code, especially in the Signal Generation section.

     Tony

    Tony

  • It apears that the files did not attach properly. Here they are again:

     

    0336.sgent1.c
    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    // =====================================================================================
    // This software is licensed for use with Texas Instruments C28x
    // family DSCs. This license was provided to you prior to installing
    // the software. You may review this license by consulting a copy of
    // the agreement in the doc directory of this library.
    // -------------------------------------------------------------------------------------
    // Copyright (C) 2010-2011 Texas Instruments, Incorporated.
    // All Rights Reserved.
    //======================================================================================
    /* ==============================================================================
    System Name: Signal Generator Module demo
    File Name: SGENT1.C
    Description: Primary System file for demonstrating the Signal Generator module
    Originator: Digital control systems Group - Texas Instruments
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

     

    7433.sgen_mdl.pdf 

  • Kiran-

    So take a look at the pdfs anthony has attached. see if your processor supports the .asm routine (You can possibly open a new thread on the forum to post that query). If it doesn't work out, post back on this thread. We can generate the sine wave without the software package pretty easily too.

    Vivek

  • Thank you sir for your kind reply, 

    may i know what is the significance of  sgen.step_max(take 1000), sgen.phase(taken 4000h). 

  • Thank You sir,

    i am taking array of sin values(values generated from MATLAB directly). will it work

  • Yes.. But 1000 values are too much. Take a table of 256 values. These values can straightaway have the CMPR values in them. This can be done in an excel sheet. Note that sin 0 corresponds to 50% duty cycle, sin 90 corresponds to 100%, Sin 270 will be 0% duty and sin 360 is again 50%.

    Example calculation

    Epwm Time period = 1000;                 // This value is just an example. But it must be equal to the time period used for carrier frequency.

    Array index             Angle(deg)               Sin(Angle)            Value Stored = CMPR Value = ((sin(Angle) + 1.65)/3.3) * (Epwm Time Period)

    sineTable[0]         0                                  0                            500

    :

    :

    :

    sinTable[63]       90                                1                            1000

    :

    :

    :

    SineTable[127]   270                           -1                            0

    :

    :

    :

    SineTable[255]  360                           0                              500

    In every interrupt you will go and copy the last column in the CMPR. Hope this helps... Post in case of doubts.

    Vivek      

  • Thank You sir, for your kind reply.

    sir here, Value Stored = CMPR Value = ((sin(Angle) + 1.65)/3.3) * (Epwm Time Period), why are we adding 1.65 and dividing with 3.3.

  • 3.3V corresponds to 100% duty cycle on the pin. 1.65V corresponds to 50% duty cycle on the pin. You want sin0 to correspond to 1.65V and sin90 to correspond to 3.3V.

    So you finally get a sine wave that is centred on 1.65 volts that has a top peak at 2.65 volts and a bottom peak of 0.65V.

    Vivek

  • sir, when i am taking sine wave data in an array, it is giving  Error: expected an expression. what may be the reason. please....

  • Kiran,

     

    Don't be afraid to call us by our names, you don't have to call us "sir" :-)  Can you attach your troublesome code, or just the line that you are having a problem with?

     

    Tony

     

  • Thank You very much,

    in a sine-triangle modulation for five-level inverter where one sine wave (amplitude from -1 to 1) and four triangler waves( each having amplitude 0.5, i.e. from -1 to -0.5, -0.5 to 0, 0 to 0.5, 0.5 to 1). But in implementation with DSP we have one trianglar wave from 0 to 0.5. so some offset value is added to the sine wave to adjust it between 0 to 0.5 as shown in the figure attached to this mail. But i need the pulse when sine wave (from -1 to -0.5) is compared with triangler wave, when sine wave (from -0.5 to 0) is compared with triangler wave, when sine wave (from 0 to 0.5) is compared with triangler wave,  when sine wave (from 0.5 to 1) is compared with triangler wave  indipendently. like wise for B-phase and C-phase. any help to achieve this. here i am attaching my code also please see this.

  • Kiran,

     

    You did not attach the relevant code - please try again!

     

    Tony

     

  • here i am attaching my code.

    1263.test2.c
    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    //###########################################################################
    // $TI Release: DSP281x C/C++ Header Files V1.20 $
    // $Release Date: July 27, 2009 $
    //###########################################################################
    #include "DSP281x_Device.h" // DSP281x Headerfile Include File
    #include "DSP281x_Examples.h" // DSP281x Examples Include File
    interrupt void eva_timer1_isr(void);
    void main(void)
    {
    //Step 1. Initialize System Control registers, PLL, WatchDog,
    // peripheral Clocks to default state:
    // This function is found in the DSP281x_SysCtrl.c file.
    InitSysCtrl();
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    please see this.

  • Which line is giving you an error for the sine data? You did not specify so I wil make a general assumption. From what I can see you have several similar expressions:

    if (1171 < a[ic] <2343)

    I am assuming that the compiler doesn't like your comparison within the "if()" statement. I have run into this issue once or twice myself.  Try using this instead:

    if (a[ic] >1171 && a[ic] < 2343)

    See if that helps. And let me know where you were having the error.

     

    Tony

     

     

  • Thank you very much sir. yes now it is working fine after changing if statement as You have suggested. thank You.

  • Thank You very much,

    in a sine-triangle modulation for five-level inverter where one sine wave (amplitude from -2343 to 2343) and four triangular waves( each having amplitude 1171). But in implementation with DSP we have one triangular wave from 0 to 1171. so some offset value is added to the sine wave to adjust it between 0 to 1171 as shown in the figure attached to this mail. But i need the pulse when sine wave (from -2343 to -1171) is compared with triangular wave, when sine wave (from -1171 to 0) is compared with triangular wave, when sine wave (from 0 to 01171) is compared with triangular wave,  when sine wave (from 1171 to 2343) is compared with triangular wave  independently. any help to achieve this.