pwm_out: update pwm outputs up to twice as fast as actual pwm frequency

- this is done to minimize real end-to-end latency
 - actual pulse width only updated for next period regardless of output module
 - add cycle interval perf counter
This commit is contained in:
Daniel Agar 2020-05-06 15:31:00 -04:00
parent aa380f351f
commit 6d846143dc
2 changed files with 11 additions and 1 deletions

View File

@ -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;

View File

@ -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);