diff options
author | Ivan <ivand58@users.noreply.github.com> | 2017-09-06 21:25:51 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-06 21:25:51 +0300 |
commit | 17ae207176c6ae52d263e55c82ff1e9b0cb0a20e (patch) | |
tree | 563a4a2c20a41c9b44dc7ae3468d08e9e4632589 | |
parent | 7e667fdc0f15ee4063b9f282e9563969d1ddf523 (diff) | |
download | cforth-17ae207176c6ae52d263e55c82ff1e9b0cb0a20e.tar.gz |
this file is moved
-rw-r--r-- | example.fth | 58 |
1 files changed, 0 insertions, 58 deletions
diff --git a/example.fth b/example.fth deleted file mode 100644 index 46a9dc7..0000000 --- a/example.fth +++ /dev/null @@ -1,58 +0,0 @@ -\ Example event loop for periodic ADC sampling - -\ Exponential smoothing filter -#10000 value filter-denom - #9000 value filter-alpha -0 value smoothed-adc -: filter ( new-value -- filtered value ) - filter-denom filter-alpha - * ( new-value'*denom ) - smoothed-adc filter-alpha * + ( smoothed-value*denom ) - filter-denom / ( smoothed-value' ) \ Rounded division - dup to smoothed-adc ( filtered-value ) -; - -#300 value adc-ms \ The sampling period in milliseconds - -0 value next-adc-time - -: set-next-adc-time ( -- ) get-msecs adc-ms + to next-adc-time ; -: adc-time? ( -- flag ) get-msecs next-adc-time - 0>= ; -: check-adc ( -- ) - adc-time? if - set-next-adc-time - adc@ dup ." Current: " .d ( val ) - ." filtered " filter .d cr ( ) - then -; - -#800 value led-ms \ The sampling period in milliseconds - -0 value next-led-time -0 value led-state - -: set-next-led-time ( -- ) get-msecs led-ms + to next-led-time ; -: led-time? ( -- flag ) get-msecs next-led-time - 0>= ; - -: check-led ( -- ) - led-time? if - set-next-led-time - led-state led-gpio gpio-pin! - led-state 0= to led-state - then -; - -: test ( -- ) - init-led - set-next-led-time - - 0 init-adc - set-next-adc-time \ Set up for first periodic sample - adc@ drop \ Discard the first sample which is often suspect - adc@ to smoothed-adc \ Prime the smoothed value with the current value - - begin - check-led \ Blink - check-adc \ Handle the ADC every so often - wfi \ The processor idles here until the next timer tick - key? until \ Exit when a key is pressed -; |