Use this forum to chat about hardware specific topics for the ESP8266 (peripherals, memory, clocks, JTAG, programming)

User avatar
By Solomon Candy
#69881 I hear that esp8266 doesn't have hardware PWM and the PWM library uses internal timer to drive outputs like PWM. But I recently discovered esp8266's delta_sigma pin driver compatibility and was happy because I could finally dim LED's through it. But then I thought - Wait a minute!! ... isn't this sigma_delta thing what a PWM is?? What is the difference between these two?
User avatar
By eriksl
#70406 There are a number of differences between PWM and delta-sigma (implementations on ESP8266).

The main difference is that delta-sigma won't keep the modulation frequency constant. So if you change the duty cycle, the frequency also changes. If you don't want that, you will have to compensate for it.

Secondly, there is only one sigma-delta generator. Although it may drive multiple outputs, it has only one set of configuration registers.

Third, sigma-delta is implemented in hardware, the ESP8266 does not have any hardware support for PWM, so one will need to implement it using software. The function in the native SDK supplies something like that, but it's far from optimal. I know at least two alternative implementations (one of them by myself) that quite closely approach a real hardware PWM, which allows for different duty cycles on all attached pins.

Fourth, the sigma-delta function only allow for 8 bit resolution, which is really quite small. A software PWM can achieve full 16 bit resolution at 122 Hz, if the cpu is set to 160 MHz.
User avatar
By malachi
#77818
eriksl wrote:There are a number of differences between PWM and delta-sigma (implementations on ESP8266).

The main difference is that delta-sigma won't keep the modulation frequency constant. So if you change the duty cycle, the frequency also changes. If you don't want that, you will have to compensate for it.

Secondly, there is only one sigma-delta generator. Although it may drive multiple outputs, it has only one set of configuration registers.

Third, sigma-delta is implemented in hardware, the ESP8266 does not have any hardware support for PWM, so one will need to implement it using software. The function in the native SDK supplies something like that, but it's far from optimal. I know at least two alternative implementations (one of them by myself) that quite closely approach a real hardware PWM, which allows for different duty cycles on all attached pins.

Fourth, the sigma-delta function only allow for 8 bit resolution, which is really quite small. A software PWM can achieve full 16 bit resolution at 122 Hz, if the cpu is set to 160 MHz.


I found this a very helpful response, thank you!
Just curious, did you mean 122 Hz, or 122 KHz?
User avatar
By eriksl
#77830 122 Hz, really, at 16 bits. A hardware implementation, like on the ATmega, can't reach very much higher than that.

What are you trying to achieve with a PWM at 121 KHz? It will probably fry your mosfets if they need to switch a significant amount of current.