aboutsummaryrefslogtreecommitdiff
path: root/nuttx
diff options
context:
space:
mode:
authorpx4dev <px4@purgatory.org>2012-08-05 16:31:04 -0700
committerpx4dev <px4@purgatory.org>2012-08-05 16:31:04 -0700
commitc513f5ade8a605721f0d9c859b1ba0a1f3949963 (patch)
treeb87bcbc886af5a940bc5f88d3c7f4e0cefa849a0 /nuttx
parent59962bc3da97a102117e3d4e5c90b9062beb7180 (diff)
downloadpx4-firmware-c513f5ade8a605721f0d9c859b1ba0a1f3949963.tar.gz
px4-firmware-c513f5ade8a605721f0d9c859b1ba0a1f3949963.tar.bz2
px4-firmware-c513f5ade8a605721f0d9c859b1ba0a1f3949963.zip
Adjust some scaling factors for more precise PWM output.
Diffstat (limited to 'nuttx')
-rw-r--r--nuttx/configs/px4fmu/src/up_pwm_servo.c6
-rw-r--r--nuttx/configs/px4io/src/drv_pwm_servo.c6
2 files changed, 8 insertions, 4 deletions
diff --git a/nuttx/configs/px4fmu/src/up_pwm_servo.c b/nuttx/configs/px4fmu/src/up_pwm_servo.c
index 05daf1e97..adb9b5030 100644
--- a/nuttx/configs/px4fmu/src/up_pwm_servo.c
+++ b/nuttx/configs/px4fmu/src/up_pwm_servo.c
@@ -164,10 +164,10 @@ pwm_timer_init(unsigned timer)
rDCR(timer) = 0;
/* configure the timer to free-run at 1MHz */
- rPSC(timer) = pwm_timers[timer].clock_freq / 1000000;
+ rPSC(timer) = (pwm_timers[timer].clock_freq / 1000000) - 1;
/* and update at the desired rate */
- rARR(timer) = 1000000 / pwm_update_rate;
+ rARR(timer) = (1000000 / pwm_update_rate) - 1;
/* generate an update event; reloads the counter and all registers */
rEGR(timer) = GTIM_EGR_UG;
@@ -234,6 +234,8 @@ up_pwm_servo_set(unsigned channel, servo_position_t value)
return -1;
/* configure the channel */
+ if (value > 0)
+ value--;
switch (pwm_channels[channel].timer_channel) {
case 1:
rCCR1(timer) = value;
diff --git a/nuttx/configs/px4io/src/drv_pwm_servo.c b/nuttx/configs/px4io/src/drv_pwm_servo.c
index 7f3238da3..4d821cba6 100644
--- a/nuttx/configs/px4io/src/drv_pwm_servo.c
+++ b/nuttx/configs/px4io/src/drv_pwm_servo.c
@@ -96,10 +96,10 @@ pwm_timer_init(unsigned timer)
rDCR(timer) = 0;
/* configure the timer to free-run at 1MHz */
- rPSC(timer) = cfg->timers[timer].clock_freq / 1000000;
+ rPSC(timer) = (cfg->timers[timer].clock_freq / 1000000) -1;
/* and update at the desired rate */
- rARR(timer) = 1000000 / cfg->update_rate;
+ rARR(timer) = (1000000 / cfg->update_rate) - 1;
/* generate an update event; reloads the counter and all registers */
rEGR(timer) = GTIM_EGR_UG;
@@ -166,6 +166,8 @@ pwm_channel_set(unsigned channel, servo_position_t value)
return;
/* configure the channel */
+ if (value > 0)
+ value--;
switch (cfg->channels[channel].timer_channel) {
case 1:
rCCR1(timer) = value;