From f8ff667ddeff000d7b7099b83d6a4e801d02c345 Mon Sep 17 00:00:00 2001 From: CAI Dongcai Date: Sun, 5 Jun 2016 12:08:31 +0200 Subject: [PATCH] pwm steps bugs fixed (#4719) fix the divide 0 bug in using "pwm steps" in NSH, and add it's description --- src/systemcmds/pwm/pwm.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/systemcmds/pwm/pwm.c b/src/systemcmds/pwm/pwm.c index 1457e7fe2d..302ed5aaf2 100644 --- a/src/systemcmds/pwm/pwm.c +++ b/src/systemcmds/pwm/pwm.c @@ -75,7 +75,7 @@ usage(const char *reason) errx(1, "usage:\n" - "pwm arm|disarm|rate|failsafe|disarmed|min|max|test|info ...\n" + "pwm arm|disarm|rate|failsafe|disarmed|min|max|test|steps|info ...\n" "\n" "arm\t\t\t\tArm output\n" "disarm\t\t\t\tDisarm output\n" @@ -101,6 +101,9 @@ usage(const char *reason) "\t[-a]\t\t\tConfigure all outputs\n" "\t-p \t\tPWM value\n" "\n" + "steps ...\t\t\tRun 5 steps\n" + "\t[-c ]\t\t(e.g. 1234)\n" + "\n" "info\t\t\t\tPrint information\n" "\n" "\t-v\t\t\tVerbose\n" @@ -663,7 +666,7 @@ pwm_main(int argc, char *argv[]) } else if (phase == 1) { /* ramp - depending how steep it is this ramp will look instantaneous on the output */ - val = idle + (full - idle) * (phase_maxcount / (float)phase_counter); + val = idle + (full - idle) * ((float)phase_counter / phase_maxcount); } else { val = off;