This example shows how to use MATLAB System block to generate Pulse Width Modulation (PWM) signals based on the input period and duty cycle signals by using controllable sample time and setNumTicksUntilNextHit.
In this example, MATLAB System block registers a controllable sample time so that it can schedule the next hit while changing the output value. In this example, the MATLAB System block has two input ports and one output port. The first input port is the duty cycle signal and the second input port is the period signal. The MATLAB System block has two block parameters: the amplitude of the generated PWM signal and the resolution of the controllable sample time.
In this example, the MATLAB System block demonstrates the use of the function: * createSampleTime(obj, 'Type', 'Controllable', 'TickTime', obj.Resolution) to \register a controllable sample time in getSampleTimeImpl method. The resolution must be a positive finite integer that defines the fundamental step size that the MATLAB System block can schedule the next hit for this sample time.
MATLAB System Block demonstrates the use of the method: * setNumTicksUntilNextHit(obj, numTicks) to schedule the next hit of the controllable sample time. The next hit happens after t = t_current + numTicks * resolution. numTicks must be a positive integer. The MATLAB System block can use this method to schedule the execution of the controllable sample time in setupImpl and stepImpl.