From e9fbb9a3ab370e65b503af37d2cf29fce54f3d42 Mon Sep 17 00:00:00 2001 From: Christian Rauch Date: Mon, 7 Aug 2023 01:39:17 +0200 Subject: [PATCH] pca9685_pwm_out: add parameter PCA9685_RATE to set update frequency --- src/drivers/pca9685_pwm_out/main.cpp | 9 +++++++++ src/drivers/pca9685_pwm_out/module.yaml | 16 ++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/drivers/pca9685_pwm_out/main.cpp b/src/drivers/pca9685_pwm_out/main.cpp index 1c141d5cfa..4c3ee60c54 100644 --- a/src/drivers/pca9685_pwm_out/main.cpp +++ b/src/drivers/pca9685_pwm_out/main.cpp @@ -133,6 +133,15 @@ int PCA9685Wrapper::init() return ret; } + param_t param_h = param_find("PCA9685_RATE"); + + if (param_h != PARAM_INVALID) { + param_get(param_h, &_targetFreq); + + } else { + PX4_DEBUG("PARAM_INVALID: PCA9685_RATE"); + } + this->ChangeWorkQueue(px4::device_bus_to_wq(pca9685->get_device_id())); PX4_INFO("running on I2C bus %d address 0x%.2x", pca9685->get_device_bus(), pca9685->get_device_address()); diff --git a/src/drivers/pca9685_pwm_out/module.yaml b/src/drivers/pca9685_pwm_out/module.yaml index ba12dccf1d..78801fbdb6 100644 --- a/src/drivers/pca9685_pwm_out/module.yaml +++ b/src/drivers/pca9685_pwm_out/module.yaml @@ -9,3 +9,19 @@ actuator_output: max: { min: 1600, max: 2200, default: 2000 } failsafe: { min: 800, max: 2200 } num_channels: 16 +parameters: + - group: PCA9685 + definitions: + PCA9685_RATE: + description: + short: PWM frequency for PCA9685 + long: | + Update rate at which the PWM signal is sent to the ESC. + type: float + decimal: 1 + increment: 0.1 + default: 50 + min: 50 + max: 450 + unit: Hz + reboot_required: true