From: rearman Date: Fri, 11 Nov 2022 22:01:58 +0000 (-0500) Subject: Edit functions for int/float type, added counts-to-volts X-Git-Url: https://git.earman.xyz/?a=commitdiff_plain;h=950e7c2081893bbc672881390d1c4228f1915ff3;p=emacsinit.git Edit functions for int/float type, added counts-to-volts --- diff --git a/work-eqs.el b/work-eqs.el index a661044..88b12b9 100644 --- a/work-eqs.el +++ b/work-eqs.el @@ -83,9 +83,14 @@ Applies `c-to-k' to `f-to-c'." (defun max-counts (resolution) "Calculate the max count for a PLC analog, given card's bit-resolution. Formula is 1 - 2^(resolution)" - (- (expt 2 resolution) 1.0)) + (- (expt 2 resolution) 1)) (defun volts-to-counts (vin vmax resolution) "Convert a voltage signal to a PLC count. Calculates a ratio of vin/vmax, then scales by `max-counts'." - (* (/ vin vmax) (max-counts resolution))) + (* (/ (float vin) (float vmax)) (float (max-counts resolution)))) + +(defun counts-to-volts (cin vmax resolution) + "Convert a PLC count to a voltage. +Calculates a ratio of cin/`max-counts', then multiplies by vmax." + (* (/ cin (float (max-counts resolution))) vmax))