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.

Triangle wave to use with TMS320F28335

Other Parts Discussed in Thread: TMS320F28335

Hello!I'm new to microcontrollers and I'm using the TMS320F28335 product.

As I'm trying to learn the basics about using analog and digital IOs, I need help creating a triangular waveform  in simulink to use as a carrier signal for PWM.

The waveform needs to have an amplitude range from 0 to 1 and a sampling period of Ts.

I tried to build the model in Matlab/Simulink and compile with code composer studio but there is no discrete triangular wave source in simulink. I tried to create one by using a square pulse generator and a discrete integrator but it didn't work. So I'm asking if someone could provide a model solution for the triangular wave to use with TMS320F28335.

Thanks in advance,

Spyros

  • Hi Spyros,

    I'm currently having the same problem than you so I'd be very interested if you have any solution.

     

    Maxime

  • I am not sure if I understand your question properly. Do you want to generate digital waveform (in software) or you want to generate analog triangle wave?

    If you want to generate analog triangle wave, you'd better use DDS or DAC  rather than directly using C2000 DSP or whatever MCU.

    MCU can be a controller for DDS/DAC if you want to control its parameters in real-time. Normally, for generating hardware wavform, simulink is helpless.

  • Well, I'd like to create a triangle wave through software ways. I tried to code one in C programming through the Matlab plateform. I have the Matlab code which isn't quite difficult and looks like it doesn't work. The C2000 toolbox on Simulink with the S Function Builder allows me to generate the associated code in C.

    float i=0;
    float step = (1/frequency)/sample;
    for(i=0;i<period/2;i++){
    triangle[i] = i*step;     // first half
    }
    for(i=period/2;i<period;i++)
    {
    triangle[i]=triangle[period-1];    // second half
    }

  • Hi all,

    I have same problem. In C2000 there is no discrite triangle generator, but there some way to generate this wave.
    Firstly, we must use discrite block. If we use continuous blocks, there will be complication error.
    So, i have tried to generate the wave using repeating sequance , repeating sequance interpolation and repeating sequance stair. With this way, i got the wave but it's frequance is maximum 2.5kHz for acceptiable wave form. @ Tsample= 15 micro second (when you increase frequance, the wave form is so bad to use for SPWM )
    The second way that i have tried is using MAtlab Function block with blow code. Unfurtunatelly, same the previous way, the frequancy of wave can be max 2.5Khz for acceptiable wave form because of discrite clock block.
    I understend from all that in disrite time to obtain acceptiable wave form ,Tsample must be higher than 15micro second (e.g. 60mic.sec.)- that means lower sample time- or frequance must be lower.


    So, i need a solution too :)

    %%%%%%%%%%%%%%%%%%%%%%%%
    function signal = fcn(clk)
    fswi=5e3; %5khz
    Tswi=1/fswi;
    %Tsamp=15e6;
    %n=Tsamp/Tswi;
    %for i=0:Tsamp:n
    k=mod(clk,Tswi);
    t=k;

    if t<= Tswi/4 && t>0
    signal=t*4/Tswi;
    elseif t>Tswi/4 && t<=3*Tswi/4
    signal=(-4*(t-Tswi/2))/Tswi;
    elseif t>3*Tswi/4 && t<Tswi
    signal=(4/Tswi)*(t-Tswi);
    else
    signal=0;
    end

    return;

    %%%%%%%%%%%%%%%%%%%%%%%%%%%


    Emre
  • Hi,

    Im using simulink coder for my application, Its good to use the triangular signal as the counter of epwm, counts up dowm mode as shown in attachment. That can be used most type of pwm appication.

    Regards

    Aslam

  • Hi Aslam ,

    When ePWM block is used, there is no problem, you are right. But, i have a sine wave that is magnitue is maximum 1 and i want to compare it a triangle wave which is magnitute is 1. So, i need a discrite triangle wave to obtain PWM signal. In this technique, the switching frequance is triangle wave's frequance ,you know,
    And yet,  i need a discrite triangle wave whic's frequance is about 5kHz. @ Tsample is about 15micro second.

    Finally, could you share the block parameters which comes before ePWM block in your previous  post ? I want to see your data type (for example double, int16, 32fix point etc.)

    Best Regards,

    Emre

  •  Hi,

    Im using same for sine pwm, only thing is: u have to scale sine wave to the range of 0-100 as percentage. Percentage is to be set as input mode in the block settings.

    -Aslam

  • hi aslam...

    i am here to get information from you . I am doing a project on DSP Based Real Time implementation of AC-DC-AC converter Using SPWM Technique .
    we are using here dsp tms320f28335 and interfacing ccs 3.3 with matlab 2009b .
      here am getting a problem to generateCOMPLIMENTARY PULSES through epwm module .
    taking general block settings as updown and timer period 7500

    input port value required is 3500.
    how to take the values in epwmA and epwmB blocks in order to get pulses COMPLIMENTARY ??
    i mean the settings of CMPA and al those parameters in those blocks ?
     
    The information provided by u will be soo useful ... plss repply as soon as possible to my mali id : rakesh.pudhari1@gmail.com

  • Hi Rakesh,

    Please let us know if you get the information you are looking for. If not, feel free to start a new forum thread describing what information you need (feel free to link to this post).