This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Sinusoidal PWM

Hello,

I'm tyring to program a STM32F4 (with ARM F4) board to generate a sinusoidal PWM, that is a sequence of pulses with variable width that, once filtered by a LPF, gives a sinusoid.

I was told the best way to get it is by generating a sequence of single pulses synchronized to timer by interrupts.

I've tried several solutions but I'm not good at managing interrupts.

Do you have any idea how to achieve this goal?
Can you attach a piece of code where it's explained how to do it?

Thanks in advance! ;)

Mara

Parents Reply Children
  • It uses the ST Standard Peripheral Library (SPL)

    The Red Download button at the bottom
    www.st.com/.../PF257901

    You'd have to make sure the project called out the 401, and configure the PLL correctly in the system_stm32f4xx.c

    There are project templates for MDK4, for MDK5 you will probably need to install the Cortex Legacy Pack

    The 401C Discovery firmware library may be a shorter jump
    www.st.com/.../PF259428

  • Hello Clive,

    I'm replacing the functions you've used for the F4 library's functions, so I can better understand what you meant to do.

    But there is one thing I can't still figure it out.

    Why did you define the "TIM2_IRQHandler(void)" function if you din't even call it in the main part?

    Do I have to call it just before the "while(1)" cycle?

    Thank you,
    Mara

  • It's an Interrupt, it's called by the processor when the TIM2 Update Interrupt asserts. The NVIC/TIM configuration enable this, and the vector table of interrupt handlers are listed in startup_stm32f4xx.s direct execution to the routine.

    It will be called outside the flow of regular code, you don't need to explicitly call it. This is how interrupts work. Please refer to Computer Science and Micro-Controller texts if you need foundational understanding.

    I'd recommend one of Joseph Yiu's books on the Cortex-Mx series parts, and there are of course ARM's Technical Reference Manuals (TRM) which describe the cores in significant detail.