Skip to content
Chris edited this page Jun 6, 2023 · 43 revisions

PWM resolution

Bluejay drives PWM by the EFM8BBxx PCA0 peripheral. PCA0 timebase is taken from 49Mhz system clock. PCA0 is capable of 8, 9, 10, 11 and 16bit resolution PWM modes. Current Bluejay implementation makes use of 8, 9, and 10bit PWM modes. PWM frequency of each module is limited by the following formula:

PWMfreq = CLOCK / (2 * 2^bit)
PWMfreq = 49MHz / (2 * 2^bit)

So when:

  • 10bit is used PWMfreq = 49000000/(2 * 1024) = 24khz
  • 9bit is used PWMfreq = 49000000/(2 * 512) = 48khz
  • 8bit is used PWMfreq = 49000000/(2 * 256) = 96khz
Bit Steps PWM Frequency
10 1024 49MHz / (2 * 1024) = 24kHz
9 512 49MHz / (2 * 512) = 48kHz
8 256 49MHz / (2 * 256) = 96 kHz

Notice: Factor 2 is used because of center aligned PWM is used in Bluejay for deadtime insertion. Check below.

RC pulse input

RC pulse input AKA rcpulse is received by a DSHOT frame: https://brushlesswhoop.com/dshot-and-bidirectional-dshot/

rcpulse in DSHOT frame is a 11bit resolution value from 0 to 2047. Values from 0 to 47 inclusive are reserved for dshot commands, so effective values are the ones between 48 to 2047, that are recoded to 0 to 1999. When using bidirectional 3D mode recoded values from 0 to 999 are used for forward direction and values from 1000 to 1999 are used for reverse direction. When using normal mode values from 0 to 1999 are used for forward direction.

11bit rcpulse is transformed depending on bidirectional 3D mode or normal mode is configured so when:

  • 10bit 24khz frequency and bidirectional 3D mode is used, the 0-999 and 1000-1999 rcpulse are scaled to a 0-1023 PWM value
  • 9bit 48khz frequency and bidirectional 3D mode is used, the 0-999 and 1000-1999 rcpulse are scaled to a 0-511 PWM value
  • 8bit 96khz frequency and bidirectional 3D mode is used, the 0-999 and 1000-1999 rcpulse are scaled to a 0-255 PWM value
  • 10bit 24khz frequency and normal mode is used, the 0-1999 rcpulse is scaled to a 0-1023 PWM value
  • 9bit 48khz frequency and normal mode is used, the 0-1999 rcpulse is scaled to a 0-511 PWM value
  • 8bit 96khz frequency and normal mode is used, the 0-1999 rcpulse is scaled to a 0-255 PWM value

Deadtime

Bluejay hardware modulates motor windings voltage using a PWM waveform. When a phase is being switched it is driving a PWM signal to a half bridge arm (Q1 in the image below) and a complementary PWM to the same half bridge leg (Q2 below):

imagen

Half bridge switching does not happen immediately so Q1 (half bridge arm) and Q2 (half bridge leg) cannot be driven with PWM and complementary PWM respectively at the same time, otherwise there would be a short moment in time where Q1 and Q2 are still switching so both may be open at the same time letting current through between VCC and GND (shoot through). For this reason BLDC ESCs insert a time between the commutation of Q1 and Q2 called deadtime and do the switching in an orderly manner.

Inserting deadtime prevents shoot through (shorting VCC and GND).

Every MOSFET model on the market has its own deadtime value. Manufacturers always use the same type of MOSFET with the same deadtime on their ESCs. For this reason each ESC model on the market has it's own deadtime for the ESC as whole.

PWM duty cycle and Deadtime

Bluejay hardware uses center aligned PWM, so deadtime is inserted at the beginning and at the end of the PWM duty cycle. Normally CEX0 and CEX1 outputs have opposite polarity. This is the way Bluejay implements complementary PWM.

For example, let CEX0 be connected to the half bridge arm and CEX1 be connected to the half bridge leg, also let CEX0 output inverted, and CEX1 not inverted. Initially CEX0 is opening the half bridge arm and CEX1 is closing the leg. Then CEX1 opens the leg and after the deadtime CEX0 closes the arm. After duty cycle CEX0 opens the arm and after the deadtime CEX1 closes the leg.

imagen

PWM resolution and Deadtime

Bluejay uses the system clock of 49Mhz as PCA (Programmable Counter Array, used to generate PWM signal) clock source. This peripheral has several bit resolution options to generate PWM waveforms. When choosing 8bit resolution the PCA is capable of producing a 96Khz waveform, when choosing 9bit, the PCA produces a 48khz waveform and when using 10bit it produces a 24khz waveform.

For example suppose that a motor can be started when rcpulse is 20 at 24khz. Remember that rcpulse is a 11bit value between 0-1999 (we previously removed the DSHOT command range), so when converting it to a 10 bit value the resulting pwm value is 10. Now for example think that instead of using 48khz instead. In this case the resulting PWM value is 5. The same way when using 96khz pwm the resulting pwm value is even smaller, it is 2.

In summary for a 20 rcpulse we have a resulting PWM duty cycle of:

  • 10 at 24khz
  • 5 at 48khz
  • 2 at 96khz

But what happens to deadtime? For the same time a 24khz frequency cycle takes there are 2 x 48khz cycles and 4 x 96khz cycles. In a 24khz frequency a deadtime is inserted at the beginning of the duty cycle and one at the end of the duty cycle, on the other hand when using 48khz frequency in the same timespan 4 deadtimes are inserted, and when using 96khz frequency in the same timespan as a 24khz cycle 8 deadtimes are inserted. This results in more freewheeling and more time for coil power disipation, so even if you apply the same power at 96khz than 24khz you are disipating 4 times the power by deadtimes. So when increasing frequency we lose some power because of reducing resolution, coil energization is spreaded along time and deadtime insertion allows to disipate previously injected coil power.

Glossary

Duty cycle

The duty cycle is the duration of the PWM signal being in high state. Often times this is also referenced as percentage of a duty cycle.

Example: Duty cycle of 20% means the signal is high for the first 20% of the PWM period.

Period

The duration of a PWM period. On 24kHz this is equal to 41.67us.

Half bridge

Mosfet configuration composed by a high side switch (AKA arm) and a low side switch (AKA leg). imagen

Arm

High side switch or Q3 in half bridge capture.

Leg

Low side switch or Q4 in half bridge capture.