fl hex { PropForth4.5 PullUpresistor 10kohm between A_phase and 3.3V ----------------------- | | A_phase |------------- P12 |Rotary Encoder Common |------------- Gnd | B_phase |------------- P13 ----------------------- | PullUpresistor 10kohm between A_phase and 3.3V ----------> CW 20132013201320 <-- 2bit binary A_phase 00110011001100 B_phase 10011001100110 CCW <-------- prev current status 0 0 stop 0 1 CW 0 2 CCW 0 3 invalid 1 0 CCW 1 1 stop 1 2 invalid 1 3 CW 2 0 CW 2 1 invalid 2 2 stop 2 3 CCW 3 0 invalid 3 1 CCW 3 2 CW 3 3 stop } c wconstant A_phase d wconstant B_phase wvariable encoder_tbl 0 c, 1 c, 2 c, f c, 2 c, 0 c, f c, 1 c, 1 c, f c, 0 c, 2 c, f c, 2 c, 1 c, 0 c, wvariable prev 0 prev W! wvariable current variable counter 0 counter L! : encoder ina COG@ A_phase rshift 3 and dup \ get current encoder_data prev W@ 4 u* encoder_tbl 2+ + + C@ dup \ get CW/CCW/stop from table 2 < if counter L@ + counter L! else 2 = if counter L@ 1- counter L! thens \ update counter prev W! ; : test begin encoder counter L@ . cr 0 until ; decimal