Skip to content
Daniel Mosquera edited this page Jun 5, 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 = 49000000 / max_resolution_value

So when:

  • 10bit is used PWMfreq = 49000000/1024 = 24khz
  • 9bit is used PWMfreq = 49000000/512 = 48khz
  • 8bit is used PWMfreq = 49000000/256 = 96khz

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 the end of the PWM duty.

For example: If the necessary deadtime is 816us and a PWM period takes 4000us this deadtime will reduce effective PWM by about a 20%, which means that until the PWM duty cycle is above 20% the effective duty cycle is still 0.

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.

Bluejay uses 1/49000000 seconds (20,4ns) units to configure deadtime, so deatime values are directly substracted to PWM duty producing an effective PWM duty equals to duty - deadtime.

For example: The Layout O-H-5 indiciates a dead-time of 5 units, so 20.4 * 5 = 102ns.

For this reason the effective resolution is PWM resolution minus deadtime. For example, when using 96khz frequency 8bit resolution is used. If we have a 40 deadtime ESC the effective resolution is 256 - 40. This is over 15% resolution diluted simply because of the deadtime.

This loss of resolution is what causes issues when starting motors in Bluejay using high frequency PWM and ESCs with high deadtimes. PWM deadtime can be corrected, but Bluejay runs in EFM8BB21 8bit MCU, that is not able to do calculations fast enough to implement this correction.

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.