Skip to main content
Graduate II
July 23, 2024
Question

Efficient Method to Generate a Sine Wave Using DMA and TIM1

  • July 23, 2024
  • 1 reply
  • 777 views

Hi 

What is the most efficient method in program logic to generate a sine wave using an H-bridge with an advanced timer?

I am using TIM1 on an STM32 microcontroller, which has two channels (Channel 1 and Channel 2) and complementary outputs. For generating the sine wave, I am using the following configuration:

  • Positive Half-Cycle: The MOSFETs Q1 and Q4 are driven with PWM signals, while Q2 and Q3 are turned off.
  • Negative Half-Cycle: The MOSFETs Q2 and Q3 are driven with PWM signals, while Q1 and Q4 are turned off.

I am also using center-aligned mode. What is the best and most efficient method in program logic to achieve this?

I need programming logic on how to efficiently feed a sine wave to CCR1 and CCR2 via DMA to achieve this. What is the best method?

 

 Can I feed a full sine wave array value using a single array (look up table )? or should each half-cycle be fed sequentially? Specifically, should the first half-cycle be fed, and then the polarity of the channels be inverted to handle the next half-cycle? What is the most efficient and straightforward way to achieve this?

 

@waclawek.jan 

    This topic has been closed for replies.

    1 reply

    Super User
    July 23, 2024

    @thannara123 wrote:

    What is the most efficient (sic) method...


    That depends on your definition of, "efficient"; eg,

     


    @thannara123 wrote:

     Can I feed a full sine wave array value using a single array (look up table )? or should each half-cycle be fed sequentially?  


    A full cycle table is obviously going to take up more memory that a half cycle - so is memory efficiency your prime concern?

    Having  just a half-cycle table saves memory, but gives you a bit more work to do - so is programmer efficiency your prime concern?

    You could just use a quarter-cycle table ...