PWM (Pulse Width Modulation)

This function block allows users to generate an artificial pulse width modulation signal, useful for controlling the timing of digital signals based on either time intervals or sample counts.

📥 Inputs

This function block does not have any input sockets.

📤 Outputs

Boolean This output indicates the current state of the PWM signal, toggling between True and False.

🕹️ Controls

Interval A labeled input field where you can set the total interval duration for the PWM signal. This defines how long one complete cycle (up and down) will take.

Up Duration A labeled input field to specify the duration for which the signal will remain at a high state (True) within the total interval.

Time Mode A toggle switch that allows you to choose between time-based signaling (on) or sample-based signaling (off).

🎨 Features

Versatile Duration Options Users can choose to define PWM behavior based on either time intervals or sample counts, providing flexibility for various applications.

Real-time State Updates The output state is updated continuously based on the specified intervals and the toggled state settings.

📝 Usage Instructions

  1. Set Interval: Enter the desired total interval by using the Interval control.

  2. Set Up Duration: Specify how long you want the signal to be high during that interval using the Up Duration control.

  3. Toggle Mode: Switch between time mode and sample mode using the Time Mode switch depending on your application needs.

  4. Evaluate: Upon running the block, the output will indicate the current state of the PWM signal.

📊 Evaluation

When executed, this function block outputs a boolean signal that fluctuates based on the parameters set for total duration and up duration, simulating a PWM signal.

💡 Tips and Tricks

Adjusting Signal Frequency

To adjust the frequency of the PWM signal, change the Interval, which directly impacts how quickly the signal toggles between states.

Using Sample Count for Consistency

If you require repetitive and consistent behavior in a controlled environment, opt for the sample mode, and use fixed sample counts to ensure predictable timing.

Monitoring State Changes

Connect the output of this function block to any visualization tool to monitor how the PWM output state changes over time or samples.

🛠️ Troubleshooting

No Output Observed

Check that the Interval and Up Duration fields are set correctly. If Up Duration is equal to or longer than Interval, the output may remain high.

Unexpected Behavior in Time Mode

Ensure that the Time Mode switch is set correctly. If it's activated but output behavior proves erratic, check if the system’s clock is functioning correctly.

Error in Sample Mode

Verify that your Interval value is not set below 1, as this can lead to division errors or unstable operation in sample mode. Adjust accordingly.

Last updated