mirror of
https://github.com/bdring/Grbl_Esp32.git
synced 2025-09-03 19:32:39 +02:00
Check freq != 0 in PWMSpindle to prevent div-by-0 crashes
This commit is contained in:
@@ -225,6 +225,9 @@ namespace Spindles {
|
|||||||
*/
|
*/
|
||||||
uint8_t PWM::calc_pwm_precision(uint32_t freq) {
|
uint8_t PWM::calc_pwm_precision(uint32_t freq) {
|
||||||
uint8_t precision = 0;
|
uint8_t precision = 0;
|
||||||
|
if (freq == 0) {
|
||||||
|
return precision;
|
||||||
|
}
|
||||||
|
|
||||||
// increase the precision (bits) until it exceeds allow by frequency the max or is 16
|
// increase the precision (bits) until it exceeds allow by frequency the max or is 16
|
||||||
while ((1 << precision) < (uint32_t)(80000000 / freq) && precision <= 16) {
|
while ((1 << precision) < (uint32_t)(80000000 / freq) && precision <= 16) {
|
||||||
|
Reference in New Issue
Block a user