[Grbl_Esp32 PR#722] PWM fix and simplification

未分类 bolang 6个月前 (10-14) 42次浏览

Issue #722 | 状态: 已关闭 | 作者: MitchBradley | 创建时间: 2020-12-24


This is an alternative solution to the PWM/ISR/float problem.

1. The set_level() argument is the exact value that is passed
to the LEDC Write function. It can be interpreted as the
numerator of a rational fraction whose denominator is the
max PWM value, i.e. the precision, == 1 << resolutionbits

2. There is a new denominator() method that returns the precision.

3. The syspwmcontrol(mask, duty, synchronize) function is
replaced by two functions sysanalogall_off() and
syssetanalog(io_num, duty). This closely matches the
actual usage. The old routine was called from two places,
one where the mask was alway 0xFF, the duty was always 0,
and synchronize was always false. That is the one that
was troublesome from ISR context. The other call always
affected a single pin, so the mask formulation with its
loop was useless extra baggage. By splitting into two
functions, each one becomes much simpler, thus faster and
easier to understand. The “synchronize” argument and
associated logic moved out to the caller (GCode.cpp),
which more closely reflects the behavioral logic.

4. For symmetry, sysiocontrol() was similarly split.

5. syscalcpwm_precision() was moved into UserOutput.cpp
since is it driver specific, not a general system routine.

原始Issue: https://github.com/bdring/Grbl_Esp32/pull/722

喜欢 (0)