Skip to main content
VSira
Associate II
September 26, 2019
Question

Hi, I am trying to generate sine modulated PWM on STM32F401-Disco board using MATLAB. The desired freq of a sine wave is 50Hz and of the carrier wave is 20kHz. But I am not getting 50Hz freq. Please suggest a solution.

  • September 26, 2019
  • 3 replies
  • 1082 views

I need sine modulated PWM during +ve half cycle of sine wave and zero output during -ve cycle of sine wave. Desired samples of sine are 200. I have attached the MATLAB simulation circuit snapshot. Problem is that I am getting 5Hz freq.0690X000009jHLCQA2.png

This topic has been closed for replies.

3 replies

waclawek.jan
Super User
September 26, 2019

There's probably nobody here who could answer MATLAB-related questions.

Are you sure your system clock is 84MHz as you expect? Output system clock onto a MCO pin and observe.

JW

Cyril FENARD
ST Employee
October 16, 2019

​Hi @VSira​ ,

It will be nice if you could share your project (*.slx + *.ioc).

Thanks in advance.

Regards.

Cyril

Cyril FENARD
ST Employee
October 25, 2019

Hi @VSira​  

,

Some precautions should be taken for sampling times in a complex model.

- check the value of the fundamental sample time.

   Be aware that if it is set to 'auto', it will be implemented at 0.001 s.

   Therefore, as an hint, set the exact value (I am not sure that 0.0001 s will allow a correct execution, depending on the CPU frequency of the device).

   Set Timebase Source in the STM32CubeMX projet to TIMER. (SysTick is used for "stepping","profiling" the Simulink model).

- Re-adjust your model from 0.001 s for the fundamental value of the sampling time and set the sampling time of the Sine Wave source.

  Check if overrun happens in the execution loop in the main() function.

Hoping that this gives leads to investigations.

Regards.

Cyril