Вы практически точно всё напсали. Единственное уставку по ресету нужно было делать через триггер. Иначе так и висит 4 .
СпасибоКод:function_block encoder_123_ var_input in_1 : bool; in_2 : bool; reset : bool; t_step : bool; end_var var_output count : real := 4; end_var var in_1_rt : SYS.RTRIG; in_2_rt : SYS.RTRIG; in_1_tof : SYS.TOF; in_2_tof : SYS.TOF; reset_rtr : SYS.RTRIG; N : real; end_var //============================================================================================================= in_1_tof(I := in_1 T := t#100ms); in_1_rt(i:=in_1); in_2_tof(I := in_2 T := t#100ms); in_2_rt(i:=in_2); reset_rtr(I:=reset); if t_step = true then N := 1; elsif t_step = false then N := 0.1; end_if if reset_rtr.Q then count := 12.0; else if in_1_rt.Q and not in_2_tof.Q then count := count + N; elsif in_2_rt.Q and not in_1_tof.Q then count := count - N; end_if end_if if count > 20.0 then count := 20.0; end_if if count < 4.0 then count := 4.0; end_if //============================================================================================================== end_function_block


Ответить с цитированием
