Variable Pulse Generator — Control Systems/Discontinuities
Control_Systems/Discontinuities/Variable_Pulse_Generator · 2 input / 1 output port(s) at insert · exports to Python, MATLAB, Java, Rust, C, C++, VHDL, Verilog, SystemVerilog, PLC Structured Text
Description#
The block's own DESCRIPTION_HTML, rendered verbatim — the same text the config dialog's info panel and the library navigator show. Fix a wrong sentence in the block's .cpp (R-D9), never here.
Variable Pulse Generator
Control Systems / Discontinuities
A pulse train whose duty cycle and period both arrive on input ports – the PWM block with its period freed from the configuration. Both inputs are read once at the start of each period and held, with nPeriod = round(T / Ts) samples in the cycle:
- the output is 1 for the first floor(duty · nPeriod) samples of the period and 0 for the rest;
- the phase then wraps against the latched period, so a period that changes mid-cycle takes effect only at the next boundary – 0.2 s followed by 0.3 s gives cycles of 0.2, 0.2, then 0.3.
A duty outside [0,1] is clamped. Applied entry by entry, and here that means each entry runs its own independent generator, with its own phase and its own period.
Ports
- Input 1 – dc – the duty cycle, a fraction in [0,1]. Its size is the block's output size.
- Input 2 – T – the period, in seconds. Rounded to a whole number of samples, and never below one sample.
- Output – the pulse train, of the SAME size as dc, carrying 1 or 0 per entry.
Both inputs must carry the same signal size; a mismatch is reported and the run is stopped rather than broadcast.
Parameters
- Sampling Time (s) – zero or less inherits the solver's rate; a positive value runs the block at that period. It converts the period signal into a sample count and is the resolution of the pulse: the high time can only ever be a whole number of samples.
There are no other parameters: everything this block needs comes in on a port.
Code export
All ten targets: Python, MATLAB, Java, Rust, C, C++, VHDL, Verilog, SystemVerilog and PLC Structured Text. Only the sampling period is baked in as a constant; the duty and the period are read from signals. The exported state is the phase counter plus the latched period and duty, one set per entry. Every target evaluates the same phase + 1 ≤ duty · nPeriod test, so none can drift from the others on a rounding convention – on the three HDL targets that comparison is done entirely in Q-format, with the phase scaled up rather than the product scaled down, so no division is ever emitted.
Turning the period into a sample count in hardware needs a fixed-point to
whole-number conversion, which the generated Fx package provides as
fx_to_int – an arithmetic shift by the fraction width, i.e.
floor(), the same rounding the software targets get.
One caveat specific to the HDL targets. The period arrives as a signal, so an HDL port delivers it already quantized to the Q16.16 format. One quantum is about 1.5×10−5, which at a 0.01 s rate is 1.5×10−3 of a sample – enough to move round(T / Ts) by a whole sample if the period lands within that of a half-sample boundary. That would not shift the output slightly; it would change the cycle length, and the core would then run out of step with the reference for the rest of the run. Drive this block with periods that are clean multiples of the sampling time and the three HDL exports are bit-exact. PWM has no such caveat at all, because its period is a configuration value resolved to an exact sample count at export time.
Simulink bridge
Import and export, mapped to
simulink/Discontinuities/Variable Pulse Generator. There are no
parameters to map in either direction; the block's whole configuration is its
wiring, and the dc, T port order is what has to line up.
"Sampling Time (s)" goes to SampleTime, as on every block. Two
Simulink parameters are always written and have no ICore counterpart:
RunAtFixedTimeIntervals is fixed to on, without which
the Simulink block refuses to run under a fixed-step solver at all, and
AllowZeroPulseWidth is fixed to on, because ICore has
nothing to reject – a zero duty simply holds the output low for the
period, where Simulink would otherwise stop the run with an error.
Notes
- Stateful: a phase counter, a latched period and a latched duty per entry.
- Discrete by nature – the output is a function of the sample index, so the block always runs at its own rate rather than being pushed through a continuous solver's stages.
- Both inputs are read only on the sample that opens a period. Feeding either a signal that changes faster than the period is not an error, but everything between boundaries is discarded.
- A period below one sample is raised to one sample rather than stalling the generator.
- Not linear, and so deliberately carries no state space.
Code facts#
| Fact | Value |
|---|---|
| registered type | Control_Systems/Discontinuities/Variable_Pulse_Generator |
| family | Control_Systems/Discontinuities |
| solver environment class | ICoreBlock_0_Control_Systems_1_Discontinuities_2_Variable_Pulse_Generator |
| source | src/ICoreSDK/ICoreBlockLibrary/Blocks/Control_Systems/Discontinuities/Variable_Pulse_Generator/ICoreBlock_0_Control_Systems_1_Discontinuities_2_Variable_Pulse_Generator.cpp |
| header | src/ICoreSDK/ICoreBlockLibrary/Blocks/Control_Systems/Discontinuities/Variable_Pulse_Generator/ICoreBlock_0_Control_Systems_1_Discontinuities_2_Variable_Pulse_Generator.h |
| default size on canvas | 80 × 80 px |
| ports at insert | 2 in, 1 out |
| code generators implemented | Python, MATLAB, Java, Rust, C, C++, VHDL, Verilog, SystemVerilog, PLC Structured Text |
Ports#
| # | Direction | Signal type | Description label |
|---|---|---|---|
| 1 | in | ICoreDouble | dc |
| 2 | in | ICoreDouble | T |
| 3 | out | ICoreDouble | — |
Ports the constructor creates. A block whose port list changes with its configuration adds or removes ports at load time; the count above is the one a freshly inserted block has.
Configuration variables#
No config variable beyond the Sampling Time (s) every block carries.
Every block also carries Sampling Time (s) from ICoreBlockSolverEnvironment: zero or less inherits the solver's rate, a positive value runs the block at that period.
Simulink bridge#
| support | Support::Both |
| Simulink path | simulink/Discontinuities/Variable Pulse Generator |
| port-count rule | PortsParam::None |
SampleTime parameter | yes |
| always set | RunAtFixedTimeIntervals = on, AllowZeroPulseWidth = on |
Caveat (shown to the user): the duty cycle and the period arrive on ports (dc, T)
Catalog contract: src/ICoreSDK/ICoreCoder/ICoreCommandSystem/SimulinkBridge/ICoreSimulinkBlockCatalog.h
Description vs code#
The lists agree. check_block_descriptions.py finds no disagreement between the description's Ports, Parameters, Code export and Simulink bridge lists and the code's.
The verdict above is
tools/docs/check_block_descriptions.py(P7.1), which compares LISTS. It cannot read a sentence: "stateless" on a block with a state, an initial-value semantic the recursion does not implement, a "not synthesizable" caveat the HDL banner contradicts. That is the agent audit (P7.3) on BLOCK_DESCRIPTION_AUDIT.md, and this tool's green is not a substitute for one.
File banner (developer view)#
The top comment of the block's .cpp — the maths, the realization and the export strategy, addressed to whoever changes it. It must not contradict the description above (P7.5).
Variable Pulse Generator block — pulse train whose duty AND period arrive on signals The PWM block with its period freed from the configuration. At each period boundary both inputs are LATCHED:
nPeriod = round(T / Ts) (at least 1) duty = clamp(dc, 0, 1) output = 1 while phase + 1 <= duty * nPeriod, else 0 phase advances and wraps against the LATCHED nPeriod
Verified against the R2026a block, including that a period change mid-cycle takes effect only at the next boundary. As in PWM, the comparison is floor-free by construction.
Stateful, per entry: phase, latched period and latched duty. Same per-language state contract as Backlash. Discrete by nature.
Sample results#
The same rig also ran:
| Stimulus | What it is | Output range |
|---|---|---|
impulse | Impulse: one sample of 1 at k = 5, 0 elsewhere (Repeating Sequence Stair) | 0 … 1 |
ramp | Ramp: slope 1 from t = 0 | 0 … 1 |
sine | Sine Wave: amplitude 1, 2 rad/s, no phase, no bias | 0 … 1 |
table | Repeating Sequence Stair: [-2 -1 -0.5 0 0.5 1 2 3], one entry per sample | 0 … 1 |
Plotted: step — Step: 0 -> 1 at t = 1 s
Category dynamic · sample time 0.1 · 60 steps · commit ccf005c8 · produced by docsSample --out <folder> --steps 60 · data docs/generated/samples/Control_Systems__Discontinuities__Variable_Pulse_Generator.json · the SVG is generated from those numbers by tools/docs/plot_svg.py, so it is a run and not a drawing (R-D10).