The W1209 is a very cheap control board with one analogue input, one relay output, and basic UI elements. It's sufficient for many SISO (single input single output) control, monitoring or timer applications.
The only problem is that the serial interface uses the same GPIO pin as the analog input. However, often it's sufficient to use the serial interface off-line (i.e. either the control application, or the diagnostics).
The following small program demonstrates such a use case:
( W1209 measures U with Q12.4 LPF U = adc + U - U/16 )
FILE NVM
: adc ( -- n ) 6 ADC! ADC@ 7 ADC! ;
: U ( -- a ) 0 ;
: lpf ( n -- n ) U @ DUP 16 / - + DUP U ! ;
: measure ( -- ) adc lpf 16 / . ;
: start ( -- )
0 U !
[ ' measure ] LITERAL BG !
BEGIN
?KEY IF 13 = ELSE 0 THEN
UNTIL
0 BG ! ;
' start 'BOOT !
RAM HAND
The word adc reads ADC6 (and switches then to the non existent ADC7 to free up RxD), U, a symbol for address 0 in the scratch-pad RAM, is the state variable of the LPF (a Q12.4 fractional number, i.e. fixed point arithmetics), lpf is a 1st order low-pass-filter with k=1.0625. The word measure samples the ADC, applies the LPF, scales fixed point to integer, and displays the result (in background on the 7S-LED display).
The initialization part in start first resets the LPF state variable U, then sets measure as the background task. All the foreground task has to do now is checking if ASCII CR (13) appears on the serial port, which indicates that the sensor has been exchanged by a serial terminal. It exits the loop, stops the background task, and drops to the Forth prompt.
Finally, the phrase ' start 'BOOT ! sets the word start as the initialization routine, and RAM for stores the Flash dictionary pointers to Flash.
Instead of just displaying the low-pass-filtered ADC value on the 7S-LED display, by using this simple pattern other features can be implemented easily on the W1209.
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.