cancel
Showing results for 
Search instead for 
Did you mean: 

How to Properly Implement a Lookup Table for a Unipolar Sine Wave Inverter?

thannara123
Senior

I'm designing a unipolar sine wave inverter using a lookup table to generate PWM signals, but I'm encountering some issues and have a few questions:

  1. Should the values in the lookup table start from zero, or from the peak value of the sine wave?
  2. Is it sufficient to create the lookup table for only half of the sine wave cycle (0 to 180 degrees)? After generating the first half-cycle, can I simply change the polarity to complete the full cycle, or is there another method I should follow?
  3. How should I handle the transition between the first and second half-cycles? Should I invert the polarity of the PWM signal, or do I need to modify the lookup table values?
  4. Could someone provide a small example of a lookup table for a unipolar sine wave inverter, and explain how to use it across a full cycle?
  5. I'm able to generate a sine wave without using complementary channels, but when I try to use complementary outputs on two channels, it doesn't work correctly. What could be causing this issue, and how can I fix it?

I'm struggling with these concepts, and any guidance or examples would be greatly appreciated. Thank you!

 

 

3 REPLIES 3
Sarra.S
ST Employee

1/ The values in the lookup table should represent the amplitude of the sine wave at different points in the cycle. Typically, these values start from zero and go up to the peak value of the sine wave.

2/ yes, you can generate the first half-cycle and then change the polarity to complete the full cycle. 

3/ after generating the first half-cycle (0 to 180 degrees), you can use the same lookup table values but invert the output to generate the second half-cycle (180 to 360 degrees).

5/ ensure that the two channels are properly synchronized and there is an appropriate dead time between the complementary signals.

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

thannara123
Senior

But I tried Likewise , but whenever the polarity changes its makes high spikes plese look the image 

As am a beginer am dont know the exact problem 

WhatsApp Image 2024-08-30 at 12.28.24 PM.jpeg

WhatsApp Image 2024-08-30 at 12.28.24 PM.jpeg

 

1.png

I used one Half cycle , CH1 output polarity is normal , and CH2 's polarty is inverted , whenever thehalf array value is transfered by the DMA the PWM_PulseFinishedCallback funtion trigger aand it inverter  the polarty of the channels . aand working as expected see the above logic signals .

 

 

 

void PWM_PulseFinishedCallback(TIM_HandleTypeDef *htim)
{    if (htim->hdma[TIM_DMA_ID_CC1] != NULL && htim->hdma[TIM_DMA_ID_CC1] == &hdma_tim1_ch1)
       {



          if (htim->Channel == HAL_TIM_ACTIVE_CHANNEL_1)
              {   i++;
                //if(i==2)
                {
        	  HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5);
                }
                htim1.Instance->CCER ^= (TIM_CCER_CC1P | TIM_CCER_CC1NP);
                // Toggle the polarity bits for CH2 and CH2N
               htim1.Instance->CCER ^= (TIM_CCER_CC2P | TIM_CCER_CC2NP);
               if (i==2) i=0;

              }
       }
}

 

 

 

PWM freq = 20khz DMA array is for one half cycle is 200

so 50us *200 = 10ms

 

 

 

 

htim1.PWM_PulseFinishedCallback = PWM_PulseFinishedCallback;
 HAL_TIM_Base_Start(&htim1);
 // generate_center_aligned_sine_tables();


     HAL_TIM_PWM_Start_DMA(&htim1, TIM_CHANNEL_1, (uint32_t *)sin_table,200);//low
     HAL_TIMEx_PWMN_Start_IT(&htim1, TIM_CHANNEL_1);
    HAL_TIM_PWM_Start_DMA(&htim1, TIM_CHANNEL_2, (uint32_t *)sin_table, 200); //high
     HAL_TIMEx_PWMN_Start_IT(&htim1, TIM_CHANNEL_2);

this is the main function call

 

 

 

How do i get a smooth sinewave ??

 

 

 

 

uint32_t  sin_table[200]={0, 4, 8, 12, 16, 20, 24, 27, 31, 35, 39, 43, 47, 51, 55, 58, 62, 66, 70,
		74, 77, 81, 85, 88, 92, 96, 99, 103, 106, 110, 113, 117, 120, 124, 127, 131, 134, 137, 141,
		144, 147, 150, 153, 156, 159, 162, 165, 168, 171, 174, 177, 180, 182, 185, 188, 190, 193,
		195, 198, 200, 202, 205, 207, 209, 211, 213, 215, 217, 219, 221, 223, 225, 226, 228, 229,
		231, 232, 234, 235, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 246, 247, 248, 248,
		248, 249, 249, 250, 250, 250, 250, 250, 250, 250, 250, 250, 249, 249, 248, 248, 248, 247,
		246, 246, 245, 244, 243, 242, 241, 240, 239, 238, 237, 235, 234, 232, 231, 229, 228, 226,
		225, 223, 221, 219, 217, 215, 213, 211, 209, 207, 205, 202, 200, 198, 195, 193, 190, 188,
		185, 182, 180, 177, 174, 171, 168, 165, 162, 159, 156, 153, 150, 147, 144, 141, 137, 134,
		131, 127, 124, 120, 117, 113, 110, 106, 103, 99, 96, 92, 88, 85, 81, 77, 74, 70, 66, 62,
		58, 55, 51, 47, 43, 39, 35, 31, 27, 24, 20, 16, 12, 8, 4};
This is the half wave array  am using 

 

 

@TDK 

@MM..1 

sorry for the mentioning , i am trying it to correct from 3,4 days

Your trouble is based on schematics and MCU PWM cant create negative signal on simply invert ...

NORMAL one sine require shifted DC data... complementary based on schematics...