From 6a3fe20d6ab09e4886c0914801c417823721e793 Mon Sep 17 00:00:00 2001 From: Diego Omitto Date: Mon, 5 Oct 2020 12:12:39 -0400 Subject: [PATCH] Fix off by one error on WAV_DELAY when calculating velocity --- nPointApp/src/LC400MotorDriver.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/nPointApp/src/LC400MotorDriver.cpp b/nPointApp/src/LC400MotorDriver.cpp index c623b79..52da2b1 100644 --- a/nPointApp/src/LC400MotorDriver.cpp +++ b/nPointApp/src/LC400MotorDriver.cpp @@ -268,7 +268,15 @@ static void genTrapezoid(epicsFloat64 ipos, epicsFloat64 fpos, epicsFloat64 vel, } } - result->cycle_count = cycle_count; + // We must subtract cycle_count by 1 before writing its value to the + // WAV_DELAY register because the delay per cycle is actually: + // (1 + WAV_DELAY)*LC400_MIN_DELAY seconds + if (!cycle_count) { + fprintf(stderr, "Cycle Count was calculated to be 0, which shouldn't happen. Setting it to 1\n"); + ++cycle_count; + } + + result->cycle_count = cycle_count - 1; result->data_len = npts; }