Home        Store        Learn        Blog

Adjusting the PWM Output (ECS to Motor) of a Basic/AfroEsc 30A

Hi all.

I am looking to be able change the output frequency of the ESC (The pwm sent from the ESC to the motors). From the documentation it has the default frequency of 18kHz with 800 steps for driving the motors but it can be modified. I have several question about it:

1- Is there an easy way to modify the output PWM of an ESC ?

2- I was looking at the tgy firmware I found in tgy.asm the following lines:

; Minimum PWM on-time (too low and FETs won’t turn on, hard starting)
.if !defined(MIN_DUTY)
.equ MIN_DUTY = 56 * CPU_MHZ / 16

; Number of PWM steps (too high and PWM frequency drops into audible range)
.if !defined(POWER_RANGE)
.equ POWER_RANGE = 800 * CPU_MHZ / 16 + MIN_DUTY

and also:

.equ	TIMING_MIN	= 0x8000 ; 8192us per commutation
.equ	TIMING_RANGE1	= 0x4000 ; 4096us per commutation
.equ	TIMING_RANGE2	= 0x2000 ; 2048us per commutation
.equ	TIMING_MAX	= 0x00e0 ; 56us per commutation

where TIMING_MAX seems to correspond to a period of ~55us (~18kHz).
Same for MIN_DUTY.

If I have to recompile the firmware, what are the parameters I have to change to lower or increase the frequency output of the ESC. And can I change the output frequency without changing the number of step or both of these parameters are correlated ?

Thank you for your help !

Hi @Not,

Thanks for the post! We’ve never actually changed the PWM output frequency of the ESC, but it should be possible. According to the comments ing tgy.asm the following line seems like the one that needs to change:

.equ	POWER_RANGE	= 800 * CPU_MHZ / 16 + MIN_DUTY

That line is overridden in one of the ESC configuration files, tp_8khz.inc to change the frequency to 8 kHz:

.equ    POWER_RANGE     = 2000 * T_CPU_MHZ / 16 + MIN_DUTY

Hopefully that’s enough info to figure it out. What frequency are you trying to achieve?


Thank for your answer @rjehangir

I’m trying to achieve a lower frequency (10kHz). I am guessing I have to set POWER_RANGE to a value between 856 and 2056 as 800 and 2000 are the numbers of PWM steps.
If I understand correctly, for 10kHz, POWER_RANGE should be 1760*CPU_MHZ /16 + MIN_DUTY with MIN_DUTY=56 (I supposed there was an affine relation between the frequency and the power range).

Edit: I just had the possibility to measure, proving me wrong. Using cross-multiplication gives a value of ~1590 for Power_range.