1
0
mirror of https://github.com/bdring/Grbl_Esp32.git synced 2025-09-01 02:21:46 +02:00

Check freq != 0 in PWMSpindle to prevent div-by-0 crashes

This commit is contained in:
Mitch Bradley
2021-05-21 13:53:58 -10:00
parent fe41a4d516
commit d1d74165f6

View File

@@ -225,6 +225,9 @@ namespace Spindles {
*/
uint8_t PWM::calc_pwm_precision(uint32_t freq) {
uint8_t precision = 0;
if (freq == 0) {
return precision;
}
// increase the precision (bits) until it exceeds allow by frequency the max or is 16
while ((1 << precision) < (uint32_t)(80000000 / freq) && precision <= 16) {