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
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
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)
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
Each sample for each channel is a uint16_t, where bit number 15 represent the polarity of the pin and bits 14:0 represents the compare value of the PWM's internal timer.
See PWM driver documentation, PWM driver API, PWM HAL API, and the PWM Driver Example in nrf5sdk_17\example\peripheral\pwm_driver.
note that you need 'individual' loading of channel samples.