edge.comp

来自「CNC 的开放码,EMC2 V2.2.8版」· COMP 代码 · 共 49 行

COMP
49
字号
//   This is a component for EMC2 HAL//   Copyright 2006 Jeff Epler <jepler@unpythonic.net>////   This program is free software; you can redistribute it and/or modify//   it under the terms of the GNU General Public License as published by//   the Free Software Foundation; either version 2 of the License, or//   (at your option) any later version.////   This program is distributed in the hope that it will be useful,//   but WITHOUT ANY WARRANTY; without even the implied warranty of//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the//   GNU General Public License for more details.////   You should have received a copy of the GNU General Public License//   along with this program; if not, write to the Free Software//   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USAcomponent edge "Edge detector";pin in bit in;pin out bit out "Goes high when the desired edge is seen on 'in'";pin out bit out_invert "Goes low when the desired edge is seen on 'in'";param rw bit in_edge=TRUE "Selects the desired edge: TRUE means falling, FALSE means rising";param rw signed out_width_ns=0 "Time in nanoseconds of the output pulse";param r signed time_left_ns "Time left in this output pulse";param r bit last_in "Previous input value";function _ nofp "Produce output pulses from input edges";license "GPL";;;FUNCTION(_){     int new_in = in;    if(in_edge) new_in = ! new_in;    if(new_in && new_in != last_in) {        time_left_ns = out_width_ns;        out = 1; out_invert = 0;    } else if(time_left_ns > 0) {        time_left_ns -= period;        out = 1; out_invert = 0;    } else {        time_left_ns = 0;        out = 0; out_invert = 1;    }    last_in = new_in;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?