aboutsummaryrefslogtreecommitdiffstats
path: root/src/gpiocmds.c
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2019-05-20 17:41:42 -0400
committerKevin O'Connor <kevin@koconnor.net>2019-05-26 11:09:32 -0400
commit8532e2123ecd3868381fd7438dc25e3fd535bfbf (patch)
tree155f7dd123023ca2ed80f838a7185d0bec995ffb /src/gpiocmds.c
parent8cd8cb492e44d1661add19b2c77b699a82f5eb49 (diff)
downloadkutter-8532e2123ecd3868381fd7438dc25e3fd535bfbf.tar.gz
kutter-8532e2123ecd3868381fd7438dc25e3fd535bfbf.tar.xz
kutter-8532e2123ecd3868381fd7438dc25e3fd535bfbf.zip
gpiocmds: Specify soft pwm duration in clock ticks
Improve the precision of soft pwm pulses by allowing the host to directly specify the clock duration of the pulse. This improvement in precision may be noticeable when controller servos (and bltouch). Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'src/gpiocmds.c')
-rw-r--r--src/gpiocmds.c18
1 files changed, 6 insertions, 12 deletions
diff --git a/src/gpiocmds.c b/src/gpiocmds.c
index 1d48a40e..91d97b75 100644
--- a/src/gpiocmds.c
+++ b/src/gpiocmds.c
@@ -106,9 +106,6 @@ DECL_COMMAND(command_set_digital_out, "set_digital_out pin=%u value=%c");
* Soft PWM output pins
****************************************************************/
-#define MAX_SOFT_PWM 256
-DECL_CONSTANT("SOFT_PWM_MAX", MAX_SOFT_PWM);
-
struct soft_pwm_s {
struct timer timer;
uint32_t on_duration, off_duration, end_time;
@@ -192,17 +189,14 @@ void
command_schedule_soft_pwm_out(uint32_t *args)
{
struct soft_pwm_s *s = oid_lookup(args[0], command_config_soft_pwm_out);
- uint32_t time = args[1];
- uint16_t value = args[2];
+ uint32_t time = args[1], next_on_duration = args[2], next_off_duration;
uint8_t next_flags = SPF_CHECK_END | SPF_HAVE_NEXT;
- uint32_t next_on_duration, next_off_duration;
- if (value == 0 || value >= MAX_SOFT_PWM) {
- next_on_duration = next_off_duration = 0;
- next_flags |= value ? SPF_NEXT_ON : 0;
- if (!!value != s->default_value && s->max_duration)
+ if (next_on_duration == 0 || next_on_duration >= s->cycle_time) {
+ next_flags |= next_on_duration ? SPF_NEXT_ON : 0;
+ if (!!next_on_duration != s->default_value && s->max_duration)
next_flags |= SPF_NEXT_CHECK_END;
+ next_on_duration = next_off_duration = 0;
} else {
- next_on_duration = (s->cycle_time / MAX_SOFT_PWM) * value;
next_off_duration = s->cycle_time - next_on_duration;
next_flags |= SPF_NEXT_ON | SPF_NEXT_TOGGLING;
if (s->max_duration)
@@ -227,7 +221,7 @@ command_schedule_soft_pwm_out(uint32_t *args)
irq_enable();
}
DECL_COMMAND(command_schedule_soft_pwm_out,
- "schedule_soft_pwm_out oid=%c clock=%u value=%hu");
+ "schedule_soft_pwm_out oid=%c clock=%u on_ticks=%u");
void
soft_pwm_shutdown(void)