Signal generator simplification

Hi guys! :cowboy_hat_face:

I want to generate a dummy rpm signal, which we will follow with a variable frequency drive
via modbus communication protocol. I already made a signal generator subflow, which is
really complicated. I think it is possible to write a function to simplify it, but i am new to javascript.
Could you help me with that, how to replace trigger nodes and reset messages with javascript
functions?

I leave my nodes here. You have to only look at the "n_rotor_cycle" subflow which i want
to simplify. I was trying my best. I hope you can run this without the whole project flows.
There are some of global variables need to be set, but i hope you can understand this.
You need to have "node-red-contrib-simple-gate" installed from the palette.

Thanks in advance!

[
    {
        "id": "8629a72a0ca72980",
        "type": "subflow",
        "name": "n_rotor_cycle",
        "info": "",
        "category": "",
        "in": [
            {
                "x": 40,
                "y": 240,
                "wires": [
                    {
                        "id": "85461dad2a1f67a6"
                    }
                ]
            }
        ],
        "out": [
            {
                "x": 1620,
                "y": 80,
                "wires": [
                    {
                        "id": "fb998dd55c469317",
                        "port": 0
                    }
                ]
            }
        ],
        "env": [],
        "meta": {},
        "color": "#DDAA99"
    },
    {
        "id": "5370289c6c0aa34e",
        "type": "trigger",
        "z": "8629a72a0ca72980",
        "name": "",
        "op1": "true",
        "op2": "false",
        "op1type": "bool",
        "op2type": "bool",
        "duration": "250",
        "extend": false,
        "overrideDelay": true,
        "units": "ms",
        "reset": "",
        "bytopic": "all",
        "topic": "topic",
        "outputs": 1,
        "x": 560,
        "y": 240,
        "wires": [
            [
                "dcf0c207ef9d5277"
            ]
        ]
    },
    {
        "id": "dcf0c207ef9d5277",
        "type": "switch",
        "z": "8629a72a0ca72980",
        "name": "",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "true"
            },
            {
                "t": "false"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 750,
        "y": 220,
        "wires": [
            [
                "d67f8fe32d7f0e32"
            ],
            [
                "4a439ecae84edcd0",
                "e075078b629c0644"
            ]
        ]
    },
    {
        "id": "8026e1f1e2416997",
        "type": "change",
        "z": "8629a72a0ca72980",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "delay",
                "pt": "msg",
                "to": "t_1",
                "tot": "global"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 340,
        "y": 240,
        "wires": [
            [
                "5370289c6c0aa34e"
            ]
        ]
    },
    {
        "id": "d67f8fe32d7f0e32",
        "type": "trigger",
        "z": "8629a72a0ca72980",
        "name": "",
        "op1": "n",
        "op2": "true",
        "op1type": "global",
        "op2type": "bool",
        "duration": "-250",
        "extend": false,
        "overrideDelay": false,
        "units": "ms",
        "reset": "",
        "bytopic": "all",
        "topic": "topic",
        "outputs": 1,
        "x": 950,
        "y": 80,
        "wires": [
            [
                "fb998dd55c469317"
            ]
        ]
    },
    {
        "id": "eac2af5540ef8094",
        "type": "delay",
        "z": "8629a72a0ca72980",
        "name": "",
        "pauseType": "delay",
        "timeout": "250",
        "timeoutUnits": "milliseconds",
        "rate": "1",
        "nbRateUnits": "1",
        "rateUnits": "second",
        "randomFirst": "1",
        "randomLast": "5",
        "randomUnits": "seconds",
        "drop": false,
        "allowrate": false,
        "outputs": 1,
        "x": 790,
        "y": 460,
        "wires": [
            [
                "269f11f31bfbc112"
            ]
        ]
    },
    {
        "id": "269f11f31bfbc112",
        "type": "function",
        "z": "8629a72a0ca72980",
        "name": "",
        "func": "var n_2 = global.get('n_2');\n\nif (msg.payload > n_2){\n    msg.payload = msg.payload - 10;\n}\nelse if (msg.payload <= n_2){\n    msg.payload = n_2;   \n}\n\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 800,
        "y": 380,
        "wires": [
            [
                "eac2af5540ef8094",
                "244be70960909911"
            ]
        ]
    },
    {
        "id": "e075078b629c0644",
        "type": "change",
        "z": "8629a72a0ca72980",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "n",
                "tot": "global"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 540,
        "y": 380,
        "wires": [
            [
                "269f11f31bfbc112"
            ]
        ]
    },
    {
        "id": "4a439ecae84edcd0",
        "type": "change",
        "z": "8629a72a0ca72980",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "reset",
                "pt": "msg",
                "to": "true",
                "tot": "bool"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 730,
        "y": 160,
        "wires": [
            [
                "d67f8fe32d7f0e32"
            ]
        ]
    },
    {
        "id": "244be70960909911",
        "type": "switch",
        "z": "8629a72a0ca72980",
        "name": "",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "neq",
                "v": "n_2",
                "vt": "global"
            },
            {
                "t": "eq",
                "v": "n_2",
                "vt": "global"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 960,
        "y": 340,
        "wires": [
            [
                "fb998dd55c469317"
            ],
            [
                "8634caf6e8a05a88",
                "75dd94aeac976f71"
            ]
        ]
    },
    {
        "id": "8634caf6e8a05a88",
        "type": "trigger",
        "z": "8629a72a0ca72980",
        "name": "",
        "op1": "true",
        "op2": "false",
        "op1type": "bool",
        "op2type": "bool",
        "duration": "3",
        "extend": false,
        "overrideDelay": true,
        "units": "s",
        "reset": "",
        "bytopic": "all",
        "topic": "topic",
        "outputs": 1,
        "x": 1220,
        "y": 340,
        "wires": [
            [
                "a39a3cd0e069e342"
            ]
        ]
    },
    {
        "id": "a39a3cd0e069e342",
        "type": "switch",
        "z": "8629a72a0ca72980",
        "name": "",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "true"
            },
            {
                "t": "false"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 1390,
        "y": 320,
        "wires": [
            [
                "b176ebcd68064fe7"
            ],
            [
                "365f5d32e30a3c30",
                "56e2b3b01d3ece0f"
            ]
        ]
    },
    {
        "id": "75dd94aeac976f71",
        "type": "change",
        "z": "8629a72a0ca72980",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "reset",
                "pt": "msg",
                "to": "true",
                "tot": "bool"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 550,
        "y": 460,
        "wires": [
            [
                "eac2af5540ef8094"
            ]
        ]
    },
    {
        "id": "b176ebcd68064fe7",
        "type": "trigger",
        "z": "8629a72a0ca72980",
        "name": "",
        "op1": "n_2",
        "op2": "true",
        "op1type": "global",
        "op2type": "bool",
        "duration": "-250",
        "extend": false,
        "overrideDelay": false,
        "units": "ms",
        "reset": "",
        "bytopic": "all",
        "topic": "topic",
        "outputs": 1,
        "x": 1460,
        "y": 240,
        "wires": [
            [
                "fb998dd55c469317"
            ]
        ]
    },
    {
        "id": "f0d664f32095b5d3",
        "type": "delay",
        "z": "8629a72a0ca72980",
        "name": "",
        "pauseType": "delay",
        "timeout": "250",
        "timeoutUnits": "milliseconds",
        "rate": "1",
        "nbRateUnits": "1",
        "rateUnits": "second",
        "randomFirst": "1",
        "randomLast": "5",
        "randomUnits": "seconds",
        "drop": false,
        "allowrate": false,
        "outputs": 1,
        "x": 1750,
        "y": 500,
        "wires": [
            [
                "9deb378b890c7fd9"
            ]
        ]
    },
    {
        "id": "9deb378b890c7fd9",
        "type": "function",
        "z": "8629a72a0ca72980",
        "name": "",
        "func": "var n_0 = global.get('n_0');\n\nif (msg.payload < n_0){\n    msg.payload = msg.payload + 25;\n}\nelse if (msg.payload >= n_0){\n    msg.payload = n_0;   \n}\n\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 1760,
        "y": 420,
        "wires": [
            [
                "f0d664f32095b5d3",
                "2e8a6318ee40e572"
            ]
        ]
    },
    {
        "id": "365f5d32e30a3c30",
        "type": "change",
        "z": "8629a72a0ca72980",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "reset",
                "pt": "msg",
                "to": "true",
                "tot": "bool"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 1280,
        "y": 420,
        "wires": [
            [
                "b176ebcd68064fe7"
            ]
        ]
    },
    {
        "id": "56e2b3b01d3ece0f",
        "type": "change",
        "z": "8629a72a0ca72980",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "n_2",
                "tot": "global"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 1600,
        "y": 380,
        "wires": [
            [
                "9deb378b890c7fd9"
            ]
        ]
    },
    {
        "id": "9b9b115feb674651",
        "type": "change",
        "z": "8629a72a0ca72980",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "reset",
                "pt": "msg",
                "to": "true",
                "tot": "bool"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 1520,
        "y": 500,
        "wires": [
            [
                "f0d664f32095b5d3"
            ]
        ]
    },
    {
        "id": "2e8a6318ee40e572",
        "type": "switch",
        "z": "8629a72a0ca72980",
        "name": "",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "neq",
                "v": "n_0",
                "vt": "global"
            },
            {
                "t": "eq",
                "v": "n_0",
                "vt": "global"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 1930,
        "y": 360,
        "wires": [
            [
                "fb998dd55c469317"
            ],
            [
                "37b57fa7ccec558d",
                "9b9b115feb674651"
            ]
        ]
    },
    {
        "id": "37b57fa7ccec558d",
        "type": "trigger",
        "z": "8629a72a0ca72980",
        "name": "",
        "op1": "true",
        "op2": "false",
        "op1type": "bool",
        "op2type": "bool",
        "duration": "10",
        "extend": false,
        "overrideDelay": true,
        "units": "s",
        "reset": "",
        "bytopic": "all",
        "topic": "topic",
        "outputs": 1,
        "x": 2110,
        "y": 360,
        "wires": [
            [
                "59805e51e86508fe"
            ]
        ]
    },
    {
        "id": "361f8fd7ec11f9f5",
        "type": "change",
        "z": "8629a72a0ca72980",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "reset",
                "pt": "msg",
                "to": "true",
                "tot": "bool"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 2080,
        "y": 260,
        "wires": [
            [
                "31905112341eb7ef"
            ]
        ]
    },
    {
        "id": "59805e51e86508fe",
        "type": "switch",
        "z": "8629a72a0ca72980",
        "name": "",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "true"
            },
            {
                "t": "false"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 2250,
        "y": 360,
        "wires": [
            [
                "31905112341eb7ef"
            ],
            [
                "361f8fd7ec11f9f5"
            ]
        ]
    },
    {
        "id": "31905112341eb7ef",
        "type": "trigger",
        "z": "8629a72a0ca72980",
        "name": "",
        "op1": "n_0",
        "op2": "true",
        "op1type": "global",
        "op2type": "bool",
        "duration": "-250",
        "extend": false,
        "overrideDelay": false,
        "units": "ms",
        "reset": "",
        "bytopic": "all",
        "topic": "topic",
        "outputs": 1,
        "x": 2320,
        "y": 280,
        "wires": [
            [
                "fb998dd55c469317"
            ]
        ]
    },
    {
        "id": "f8d2ef5d3138d759",
        "type": "change",
        "z": "8629a72a0ca72980",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "reset",
                "pt": "msg",
                "to": "true",
                "tot": "bool"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 160,
        "y": 360,
        "wires": [
            [
                "a6edf6eff849eca9"
            ]
        ]
    },
    {
        "id": "a6edf6eff849eca9",
        "type": "link out",
        "z": "8629a72a0ca72980",
        "name": "",
        "mode": "link",
        "links": [
            "79e28f92ba769367",
            "9b1bfcae34a4940e",
            "a2d96e793404fceb",
            "fc76837d8f74d88b",
            "15acfdac8aed5a21",
            "7e811bd3132ea220",
            "e4c7b1b03e48f97e",
            "40d9bb0215433f2f"
        ],
        "x": 295,
        "y": 360,
        "wires": []
    },
    {
        "id": "85461dad2a1f67a6",
        "type": "switch",
        "z": "8629a72a0ca72980",
        "name": "",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "true"
            },
            {
                "t": "false"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 150,
        "y": 240,
        "wires": [
            [
                "8026e1f1e2416997",
                "b103c489cf26ca08"
            ],
            [
                "f8d2ef5d3138d759",
                "46b9a5ad4dbca955"
            ]
        ]
    },
    {
        "id": "9b1bfcae34a4940e",
        "type": "link in",
        "z": "8629a72a0ca72980",
        "name": "",
        "links": [
            "a6edf6eff849eca9"
        ],
        "x": 435,
        "y": 300,
        "wires": [
            [
                "5370289c6c0aa34e"
            ]
        ]
    },
    {
        "id": "79e28f92ba769367",
        "type": "link in",
        "z": "8629a72a0ca72980",
        "name": "",
        "links": [
            "a6edf6eff849eca9"
        ],
        "x": 595,
        "y": 140,
        "wires": [
            [
                "4a439ecae84edcd0"
            ]
        ]
    },
    {
        "id": "fc76837d8f74d88b",
        "type": "link in",
        "z": "8629a72a0ca72980",
        "name": "",
        "links": [
            "a6edf6eff849eca9"
        ],
        "x": 1075,
        "y": 420,
        "wires": [
            [
                "8634caf6e8a05a88"
            ]
        ]
    },
    {
        "id": "40d9bb0215433f2f",
        "type": "link in",
        "z": "8629a72a0ca72980",
        "name": "",
        "links": [
            "a6edf6eff849eca9"
        ],
        "x": 2025,
        "y": 460,
        "wires": [
            [
                "37b57fa7ccec558d"
            ]
        ]
    },
    {
        "id": "e4c7b1b03e48f97e",
        "type": "link in",
        "z": "8629a72a0ca72980",
        "name": "",
        "links": [
            "a6edf6eff849eca9"
        ],
        "x": 1945,
        "y": 220,
        "wires": [
            [
                "361f8fd7ec11f9f5"
            ]
        ]
    },
    {
        "id": "7e811bd3132ea220",
        "type": "link in",
        "z": "8629a72a0ca72980",
        "name": "",
        "links": [
            "a6edf6eff849eca9"
        ],
        "x": 1395,
        "y": 560,
        "wires": [
            [
                "9b9b115feb674651"
            ]
        ]
    },
    {
        "id": "15acfdac8aed5a21",
        "type": "link in",
        "z": "8629a72a0ca72980",
        "name": "",
        "links": [
            "a6edf6eff849eca9"
        ],
        "x": 1155,
        "y": 480,
        "wires": [
            [
                "365f5d32e30a3c30"
            ]
        ]
    },
    {
        "id": "a2d96e793404fceb",
        "type": "link in",
        "z": "8629a72a0ca72980",
        "name": "",
        "links": [
            "a6edf6eff849eca9"
        ],
        "x": 435,
        "y": 520,
        "wires": [
            [
                "75dd94aeac976f71"
            ]
        ]
    },
    {
        "id": "46b9a5ad4dbca955",
        "type": "change",
        "z": "8629a72a0ca72980",
        "name": "gate close",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "close",
                "tot": "str"
            },
            {
                "t": "set",
                "p": "topic",
                "pt": "msg",
                "to": "control",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 330,
        "y": 160,
        "wires": [
            [
                "800ecc58e6121e0f"
            ]
        ]
    },
    {
        "id": "b103c489cf26ca08",
        "type": "change",
        "z": "8629a72a0ca72980",
        "name": "gate open",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "open",
                "tot": "str"
            },
            {
                "t": "set",
                "p": "topic",
                "pt": "msg",
                "to": "control",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 280,
        "y": 120,
        "wires": [
            [
                "800ecc58e6121e0f"
            ]
        ]
    },
    {
        "id": "800ecc58e6121e0f",
        "type": "link out",
        "z": "8629a72a0ca72980",
        "name": "",
        "mode": "link",
        "links": [
            "7d5a131b578f47b8"
        ],
        "x": 475,
        "y": 140,
        "wires": []
    },
    {
        "id": "fb998dd55c469317",
        "type": "gate",
        "z": "8629a72a0ca72980",
        "name": "",
        "controlTopic": "control",
        "defaultState": "open",
        "openCmd": "open",
        "closeCmd": "close",
        "toggleCmd": "toggle",
        "defaultCmd": "default",
        "statusCmd": "status",
        "persist": false,
        "storeName": "memory",
        "x": 1350,
        "y": 40,
        "wires": [
            []
        ]
    },
    {
        "id": "7d5a131b578f47b8",
        "type": "link in",
        "z": "8629a72a0ca72980",
        "name": "",
        "links": [
            "800ecc58e6121e0f"
        ],
        "x": 1195,
        "y": 20,
        "wires": [
            [
                "fb998dd55c469317"
            ]
        ]
    },
    {
        "id": "b64cdd37aa8b0cdb",
        "type": "debug",
        "z": "139f82fa75f5e56b",
        "name": "debug 2",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 780,
        "y": 1920,
        "wires": []
    },
    {
        "id": "16d5da905f4af80e",
        "type": "function",
        "z": "139f82fa75f5e56b",
        "name": "function 1",
        "func": "// declareing variables\n{\n    // variables for rpm\n\n    var n_2 = global.get('n_2');\n    var n_0 = global.get('n_2');\n    var n_2_high = global.get('n_2_high');\n    var n_2_low = global.get('n_2_low');\n    var delta_n = global.get('delta_n');\n\n    // variables for time\n\n    var t_1 = global.get('t_1');\n    var t_2 = global.get('t_2');\n    var startTime = global.get('startTime');\n    var elapsedTime = global.get('elapsedTime');\n    var delayTime = global.get('delayTime');\n\n    // variables for cycles\n\n    var N = global.get('N');\n    var N_temp = global.get('N_temp');\n    var n_rot_isNull = global.get('n_rot_isNull'); // cycle end\n    var n_rot_isNull_1 = global.get('n_rot_isNull_1'); // measurement end\n}\n\n// Functions for in- and decreasing the message value\n{\n    function decrease() {\n        return msg.payload - 10;\n    }\n\n    function increase() {\n        return msg.payload + 25;\n    }\n\n    function forTimeout() {\n        return msg;\n    }\n    function sleep(ms) {\n        return new Promise(resolve => setTimeout(resolve, ms));\n    }\n}\n\n// Main part\n\nif (msg.start == true){\n    msg.payload = n_0;\n if ( msg.payload > n_2 && elapsedTime < t_1 ){\n     msg.payload = msg.payload;\n }\n else if (msg.payload > n_2 && elapsedTime >= t_1){\n     msg.payload = msg.payload - 10;\n     }\n else if (msg.payload == n_2){\n     msg.payload = msg.payload;\n }\n}\n\n// End\n\n// not so important\nelse if(msg.start == false){\n    msg.payload == null;\n    msg.reset = true;\n}\nelse {\n    msg.payload == null;\n    msg.reset = true;\n}\n\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 780,
        "y": 1980,
        "wires": [
            [
                "c88df23dd0655298",
                "b64cdd37aa8b0cdb",
                "d3a6e8ebb9c9e7f3"
            ]
        ]
    },
    {
        "id": "cf532d6d9cadb43a",
        "type": "inject",
        "z": "139f82fa75f5e56b",
        "name": "",
        "props": [
            {
                "p": "start",
                "v": "true",
                "vt": "bool"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "x": 550,
        "y": 1900,
        "wires": [
            [
                "16d5da905f4af80e",
                "f4bb722b208eb49f"
            ]
        ]
    },
    {
        "id": "c7b6940381ae3f8a",
        "type": "inject",
        "z": "139f82fa75f5e56b",
        "name": "",
        "props": [
            {
                "p": "start",
                "v": "false",
                "vt": "bool"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "x": 550,
        "y": 2080,
        "wires": [
            [
                "16d5da905f4af80e"
            ]
        ]
    },
    {
        "id": "d3a6e8ebb9c9e7f3",
        "type": "delay",
        "z": "139f82fa75f5e56b",
        "name": "",
        "pauseType": "delay",
        "timeout": "250",
        "timeoutUnits": "milliseconds",
        "rate": "1",
        "nbRateUnits": "1",
        "rateUnits": "second",
        "randomFirst": "1",
        "randomLast": "5",
        "randomUnits": "seconds",
        "drop": false,
        "allowrate": false,
        "outputs": 1,
        "x": 790,
        "y": 2040,
        "wires": [
            [
                "16d5da905f4af80e"
            ]
        ]
    },
    {
        "id": "c88df23dd0655298",
        "type": "ui_chart",
        "z": "139f82fa75f5e56b",
        "name": "",
        "group": "a165f6af9a832d0d",
        "order": 2,
        "width": "12",
        "height": "6",
        "label": "n with function",
        "chartType": "line",
        "legend": "false",
        "xformat": "HH:mm:ss",
        "interpolate": "linear",
        "nodata": "",
        "dot": false,
        "ymin": "0",
        "ymax": "2000",
        "removeOlder": 1,
        "removeOlderPoints": "",
        "removeOlderUnit": "60",
        "cutout": 0,
        "useOneColor": false,
        "useUTC": false,
        "colors": [
            "#1f77b4",
            "#aec7e8",
            "#ff7f0e",
            "#2ca02c",
            "#98df8a",
            "#d62728",
            "#ff9896",
            "#9467bd",
            "#c5b0d5"
        ],
        "outputs": 1,
        "useDifferentColor": false,
        "className": "",
        "x": 1000,
        "y": 1980,
        "wires": [
            []
        ]
    },
    {
        "id": "f4bb722b208eb49f",
        "type": "link out",
        "z": "139f82fa75f5e56b",
        "name": "link out 1",
        "mode": "link",
        "links": [
            "0dd30885cb3d67b6",
            "7495d1d98fe8842e",
            "d1bceda32e640c39"
        ],
        "x": 705,
        "y": 1840,
        "wires": []
    },
    {
        "id": "37fdf3eb8cbacbc1",
        "type": "subflow:8629a72a0ca72980",
        "z": "139f82fa75f5e56b",
        "name": "n_rotor_cycle",
        "x": 780,
        "y": 1660,
        "wires": [
            [
                "22188dc3fda59f14",
                "f586c9039cb10d26"
            ]
        ]
    },
    {
        "id": "ddd61ee6f422b79b",
        "type": "inject",
        "z": "139f82fa75f5e56b",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "true",
        "payloadType": "bool",
        "x": 550,
        "y": 1580,
        "wires": [
            [
                "37fdf3eb8cbacbc1"
            ]
        ]
    },
    {
        "id": "c8e5c81a7fda188a",
        "type": "inject",
        "z": "139f82fa75f5e56b",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "false",
        "payloadType": "bool",
        "x": 550,
        "y": 1760,
        "wires": [
            [
                "37fdf3eb8cbacbc1"
            ]
        ]
    },
    {
        "id": "22188dc3fda59f14",
        "type": "debug",
        "z": "139f82fa75f5e56b",
        "name": "debug 1",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 780,
        "y": 1600,
        "wires": []
    },
    {
        "id": "f586c9039cb10d26",
        "type": "ui_chart",
        "z": "139f82fa75f5e56b",
        "name": "",
        "group": "a165f6af9a832d0d",
        "order": 2,
        "width": "12",
        "height": "6",
        "label": "n with nodes",
        "chartType": "line",
        "legend": "false",
        "xformat": "HH:mm:ss",
        "interpolate": "linear",
        "nodata": "",
        "dot": false,
        "ymin": "0",
        "ymax": "2000",
        "removeOlder": 1,
        "removeOlderPoints": "",
        "removeOlderUnit": "60",
        "cutout": 0,
        "useOneColor": false,
        "useUTC": false,
        "colors": [
            "#1f77b4",
            "#aec7e8",
            "#ff7f0e",
            "#2ca02c",
            "#98df8a",
            "#d62728",
            "#ff9896",
            "#9467bd",
            "#c5b0d5"
        ],
        "outputs": 1,
        "useDifferentColor": false,
        "className": "",
        "x": 1010,
        "y": 1660,
        "wires": [
            []
        ]
    },
    {
        "id": "a165f6af9a832d0d",
        "type": "ui_group",
        "name": "RPM and Actuator",
        "tab": "fb3632c55fdc7e80",
        "order": 3,
        "disp": true,
        "width": "24",
        "collapse": false,
        "className": ""
    },
    {
        "id": "fb3632c55fdc7e80",
        "type": "ui_tab",
        "name": "Main",
        "icon": "dashboard",
        "order": 2,
        "disabled": false,
        "hidden": false
    }
]

Welcome to the forum @BVviktor

Can you describe in words what the signal generator should do, please?

It should do something like this in steps:

  1. START
  2. Hold n_0 rpm till time t_1
  3. After t_1 start decreasing
  4. When it dropped to n_2, hold it for like 3 sec
  5. After that start increasing back to n_0
  6. When at n_0, hold that again for 3 sec approximately
  7. STOP

So all you need is a simple ramp/hold profile generator. Have a look at node-red-contrib-ramp-thermostat. Ignore the fact that it has thermostat in the name and use the profile feature there.

I think my problem is a little bit more complicated. I need milliseconds precision
because of the frequency drive and track the current time.

I will try to figure it out myself. Thank you for response and for welcoming me!

If you really want millisecond precision then you will probably need to look at a microcontroller based solution rather than Node-RED. As Node-RED is running on top of a multi-tasking operating system there are other processes and applications beyond our control that may affect precise timings.

1 Like

Maybe we will switch over to another solution, the millisecond precision is needed for the CAN HAT (10 ms). We will use a separate arduino or something, maybe an external python script. Thank you for
the help!

It would certainly be easy enough to build a signal generator using an Arduino or ESP I would think. Certainly an ESP32 has RTOS onboard and can create accurate timings at least to a ms level I believe. You could always add a crystal oscillator circuit for additional accuracy if needed if my poor memory of electronics serves me correctly.

I don't usually reply to threads marked "solved," but I'll make an exception this time. Rather than build a microcontroller solution from scratch, you might consider something like this https://www.amazon.com/dp/B07HKHW98L/ref=cm_sw_r_api_i_0PXQRBD30DSJ7G0B7C5J_0?th=1
It may not be exactly what you need, but if it is it would save a lot of effort.

As far as I can tell, that only appears to do on/off PWM and not the ramps the OP wanted

You may be right. The manual says that the frequency and duty cycle can be set by UART (TTL), but there's no way to tell how quickly or smoothly it responds to parameter changes.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.