This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

SIN WAVE GENERATION USING PWM DRIVER

Hi i am using the nRF52dk and i am trying to control a bldc can anyone help me to guide in how i can generate a pwm to get a sin wave 

best regards Nikolai

Parents
  • Use the PWM — Pulse width modulation peripheral, read the spec before you continue. 

    Generate PWM sequences with the sine wave equation, y(t) = A * sin(af*t +p) , where y is the sequence value, A is the COUNTERTOP value, af is your angluar frequency, t is the period of the PWM peripheral, p is phase. 

    t = u(x) = x * 1 / PWM frequency, where x is the sequence number.

    PWM frequency = PWM_CLK / 2^PRESCALER / COUNTERTOP, where PWM_CLK is fixed at 16MHz.

    A PRESCALER of 4(DIV_16) and COUNTERTOP of 100 gives a frequency of 10kHz: t(x) = x / (16MHz / 2^4 /100) = x / 10kHz. Note that the value of COUNTERTOP defines the PWM's amplitude resolution. 

    Generate three sets of sequences with a phase offset of 2*pi/3 from the previous set.

    The angular frequency defines the advance of the motor == rpm, depending on the number of poles/steps in your motor you set the desired angular frequency to get the desired rpm of the motor.  


    Other settings:
    MODE = 0 // up
    DECODER.LOAD = Individual //needed to load individual sequence samples
    DECODER.MODE = 0 // SEQ[n].REFRESH is used to determine loading internal compare registers. Amount of additional PWM periods between samples loaded into compare register (load every REFRESH.CNT+1 PWM periods)

  • hi Haakonsh

    thank you for your very fast response.. would it be possible to provide me how it would look liike in the sequence values array functions as im still abit confused. thank you so much

    bes regards

    nikolai

Reply Children
Related