cancel
Showing results for 
Search instead for 
Did you mean: 

how to generate sine wave by generating pwm signals

MS.11
Associate III

Hi,

how to generate the sine wave using pulse width modulation for 5Khz frequency using Sine wave look up table. I have already created the sine wave look up table but I am not getting how to do with the help of sine wave look up table to generate the sine wave.

Please help me how to write the code for this concept.

Thank you.

11 REPLIES 11
TDK
Guru

To do this, you would use DMA to transfer the duty cycle values into CCRx after each timer update or OC event. You can use HAL_TIM_PWM_Start_DMA to do this.

https://github.com/STMicroelectronics/STM32CubeF4/blob/2f3b26f16559f7af495727a98253067a31182cfc/Projects/STM324x9I_EVAL/Examples/TIM/TIM_DMA/Src/main.c

If you feel a post has answered your question, please click "Accept as Solution".
MS.11
Associate III

Thank you.

is it required to generate a timer with interrupt to vary the duty cycle 0% to 95% to generate the sine wave for 360 points form by generating pulse width modulation . For every 4msec I have to generate one sine wave form.

Javier1
Principal

Maybe you should take a look at this https://deepbluembedded.com/stm32-change-pwm-duty-cycle-with-dma-for-sine-wave-generation/

we dont need to firmware by ourselves, lets talk

Thank you

I have referred this one but they are using DAC to generate the sine wave. I am not using DAC. I just want by generating the PWM signals at 5Khz frequency in stm32f103c8t6.

In created sine look up table they have defined as an array from the look up table. How to defined that numbers from the sine lookup table in code.

plz help me.

Im quite sure they do PWM not only DAC, you should read the tutorial trough

Scroll down to the   STM32 PWM-To-DAC WaveForm Generator – LAB25  

part

we dont need to firmware by ourselves, lets talk
MS.11
Associate III

Thank you.

MS.11
Associate III

Thank you.

If the lookup table never changes, you can do this asynchronously with DMA. No need to regenerate a table that doesn't change.

If you feel a post has answered your question, please click "Accept as Solution".
MS.11
Associate III

Thank you.

plz if u have any example code share it to me. If I saw the example code it is easy to understand for me.