Because of the Thanksgiving holiday in the U.S., TI E2E™ design support forum responses may be delayed from November 25 through December 2. Thank you for your patience.

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.

Regarding 50Hz sine wave PWM!

To generate 50Hz sine wave PWM using sine table, I am somehow unable to decide the clock settings. Can anyone please help me out?

Useful details:

Timer Period = 0xFF=256 cycles of CLKIN

total no. of  Sine table entries for one sine cycle =  256

Now, since I have to generate 50 Hz sine wave, the input frequency to the timer should be approx. 50 x 256 x 256 =3276800 cycles = 3.2768 MHz

I need HSPCLK register free as I want to LINEARLY vary the sine frequency from 5 Hz to 50 Hz, with the ADCRESULT. Say when ADCin=0V, fsine=5Hz and when ADCin= 3V, fsine=50Hz. Linear variation wont be possible by changing TCON register value.

 

 

 

  • Please check out C28x Signal Generator Library (SPRC083) for examples and codes on how to generate various waveforms including sine wave using different methods.

  • Thanks Arefeen.

    Apart from using signal generater library, I  wanted to say that I have been successful in generating sine wave PWM, but just somehow unable to think of how to set its frequency to 50 Hz!

    I need PWM for further switching of some devices.

  •  your calculation above is wrong, how do you get a frequency (MHz) when you multiply just numbers?.

    Here is some basic math:

    fsin = 50 Hz; Tsin = 20ms.

    Let us assume you use 512 data points per period of  the 50Hz sine wave (recommendation: use the sine wave lookup table in the ROM of the F28x, which has 512 samples for 360 degree).

    20ms / 512 = 39.0625µs = TPWM

    T1PR = 0.5 * TPWM / (TCPU * HSPCLK * CLKDIV) = 0.5 * 39.0625µs  / ( 6.6667 ns * 1 * 1)  = 2930

    Initialize T1PR wit that number, request an interrupt service with each compare event to calulate a new duty cycle between 0 and 100 % based on the ROM lookup table, update T1CMPR with that relative value and you get a very nice sinusoidal PWM pattern at ePWM1!  

    Regards

     

  • Thanks Frank!

    Actually, I generated a SINE table, with 256 samples over 360 deg, ans sampled values varied from 00 to FF. So the TIPR value got fixed to FF, as when "FF from sine table" would match to "FF in the T1CNT (as T1CNT<= T1PR)"  value, I get 0% duty cycle.

    Your calculations are perfect, provided I change the maximum value of sample in the sine table to 2930, which when loaded in T1CMP register fetches me 0% duty cycle.

    I just want to know why that 0.5 factor has appeared in your calculation of T1PR. Are you assuming UP-DOWN timer mode. I guess, since I am working in UP timer mode, that factor won't come in my calculation.

    I am actually new to the DSPs. I just want to understand, what do mean by, "recommendation: use the sine wave look up table in the ROM of the F28x, which has 512 samples for 360 degree"; specially the ROM part. How do the ROM contain the 512 sample point sine table over 360 deg?Do we need to add it into the ROM? If so, how do we do it? And then how do we use those ROM values in our CODE?

    I am using ezDSP board and used to declare the sine table in my code itself.

    Also please correct me if I am wrong somewhere in my discussion.

    Thanks again!

    Regards

     

  • look at the Boot Rom User's Guide

    ex: F28335

    http://focus.ti.com/general/docs/litabsmultiplefilelist.tsp?literatureNumber=spru963a

    The boot ROM is factory programmed with boot-loading software. Boot-mode signals (general purpose I/Os) are used to tell the bootloader software which mode to use on power up. The boot ROM also contains standard math tables, such as SIN/COS waveforms, for use in IQ math related algorithms found in the C28x™ IQMath Library - A Virtual Floating Point Engine (literature number SPRC087). Floating-point tables for SIN/COS are also included for use with the Texas Instruments™ C28x FPU Fast RTS Library (SPRC664).

  • Bhushan,

    Yes, the factor 1/2 is related to "up-down" mode of the PWM counter. If you use "up"-mode, the factor is not present.

    The sine wave lookup table is already inside the ROM, it has been programmed in the factory. For the F28335 there are actually two lookup tables in ROM, one for fixed-point IQ - Math (start address is 0x3FE000, format is I2Q30) and one for float (start address is 0x3FEBDC, format is 32bit float). I have attached an example how to use the IQ-Math table to produce a sinusoidal PWM output signal. All you have to do is to place a pointer at the beginning of that table and use an offset to access the table. The tables have 512 entries for 360 degree - a step size of approx. 0.7 degree.

    Regards

     

  • Thanks Chris and Frank, thanks a lot. I am happy to learn so much on this community! If any doubts further, I shall get back to you all! :)

  • Few botherings!

    Basically , I am generating a 3 Phase sine wave PWM. And the frequency of the sine wave will be controlled by voltage. So, I want a V to F converter.

    Now, I can take voltage from ADC, convert it, process it and set the frquency of the sine wave.

    Sine wave uses a sine table which should have less than or equal to 1 degree resoulution that is: 360 or more samples (to meet maximum noise error limits) .

    I want to vary the frequency from 5Hz to 50Hz while i/p at adc varies from 0 to 3v, keeping the carrier frequency constant i.e. the timer period constant.

    I am confused how to do so. My algorithm was

    1. To use every sine table entry in the CMP register, while generating 5Hz sine wave,

    2. While for generating 50 Hz sine wave,  using every 10th sine table entry so that maintaining same career frequency, I have traveresed the sine table in less time, consequently producing 50 Hz sine wave. So, the step size will be 10. For intermediate frequencies using intermediate step values.

    i.e. placing sine table values in the CMPR1=Sine_Table[ index*step ]

    The value of step shall be determind in the ADC ISR.

    Now, the issue is since I need minimum 1 deg. resolution, say for 5Hz, I use a sine table with 512 entires (resolution 0.7 degrees/sample). And for max freq 50 Hz, I am using every 10th sample from the same sine table, the resolution would be (7 deg/sample) which is greater than 1 degree per sample.

    So, if I have 5120 samples in my sine table:

    Resolution for 5Hz would be 0.07 deg/sample (acceptable).

    And for 50 Hz it will be 0.7 deg/sample, as I am using every 10th sine table entry.

    For frequencies between 5Hz to 50Hz, the resolution will be btween 0.07 and 0.7, which is acceptable.

    Now the major issue for me is, how to store these 5120 samples sine table in the memory, how to modify the memory map. Each sine able entry is say 16-bit.

    If my approch is wrong, kindly revert back some idea or methodology, that shall help me out.

     

  • Well, you can actually utilize first few blocks of ACI3-1 example which implements a V/Hz algorithm for a three phase AC induction drive. I suggest you download the example project and look into build-1. Your "V" value will come from your ADC measurement. Once you have "V" value then you can utilize V/Hz block to determine the corresponding frequency and you go from there to realize the PWM outputs. If I understand your requirements correctly then this example project will provide you more than 90% of what you need. You will just need to add the ADC portion to obtain your "V" command from 0-3V input.

  • Can you please share your spwm code.

  • hi bhushan..

    can you show me the code.....

    i am also working similar to that...

    i am new to ti DSP....please help me

    thank you