diff --git a/src/drivers/pwm_out/PWMOut.cpp b/src/drivers/pwm_out/PWMOut.cpp index 84c59b53a9..283c5851ba 100644 --- a/src/drivers/pwm_out/PWMOut.cpp +++ b/src/drivers/pwm_out/PWMOut.cpp @@ -36,7 +36,8 @@ PWMOut::PWMOut() : CDev(PX4FMU_DEVICE_PATH), OutputModuleInterface(MODULE_NAME, px4::wq_configurations::hp_default), - _cycle_perf(perf_alloc(PC_ELAPSED, MODULE_NAME": cycle")) + _cycle_perf(perf_alloc(PC_ELAPSED, MODULE_NAME": cycle")), + _interval_perf(perf_alloc(PC_INTERVAL, MODULE_NAME": interval")) { _mixing_output.setAllMinValues(PWM_DEFAULT_MIN); _mixing_output.setAllMaxValues(PWM_DEFAULT_MAX); @@ -52,6 +53,7 @@ PWMOut::~PWMOut() unregister_class_devname(PWM_OUTPUT_BASE_DEVICE_PATH, _class_instance); perf_free(_cycle_perf); + perf_free(_interval_perf); } int PWMOut::init() @@ -397,6 +399,11 @@ void PWMOut::update_current_rate() // oneshot if ((_pwm_default_rate == 0) || (_pwm_alt_rate == 0)) { max_rate = 2000; + + } else { + // run up to twice PWM rate to reduce end-to-end latency + // actual pulse width only updated for next period regardless of output module + max_rate *= 2; } // max interval 0.5 - 100 ms (10 - 2000Hz) @@ -564,6 +571,7 @@ void PWMOut::Run() } perf_begin(_cycle_perf); + perf_count(_interval_perf); _mixing_output.update(); @@ -1992,6 +2000,7 @@ int PWMOut::print_status() } perf_print_counter(_cycle_perf); + perf_print_counter(_interval_perf); _mixing_output.printStatus(); return 0; diff --git a/src/drivers/pwm_out/PWMOut.hpp b/src/drivers/pwm_out/PWMOut.hpp index 8b36b55918..131954032f 100644 --- a/src/drivers/pwm_out/PWMOut.hpp +++ b/src/drivers/pwm_out/PWMOut.hpp @@ -181,6 +181,7 @@ private: unsigned _num_disarmed_set{0}; perf_counter_t _cycle_perf; + perf_counter_t _interval_perf; void capture_callback(uint32_t chan_index, hrt_abstime edge_time, uint32_t edge_state, uint32_t overflow);