Main Content

PWM Frequency and Duty Measurement

This example shows how to measure PWM signal frequency and duty using Simulink® Desktop Real-Time™. The measured signal is connected to gate pins of two counter inputs of your data acquisition board. The first Counter Input block is configured to measure signal duty by measuring the time between rising and falling edge of the signal. The other Counter Input block is configured to measure signal period by measuring the time between two rising edges of the signal. Both the counters use internal on-board clock as the clock source. PWM frequency and duty are then computed based on these values.

Note: To run this model, you must have a supported data acquisition board connected to your computer.

Run Model in Connected IO Mode

This model is pre-set to be used with the National Instruments™ PCIe-6323 board. You can use it with any board from the PCIe-63xx series. To change the board, open both the Counter Input blocks and select your data acquisition board. You may need to register the board by clicking the Install new board button first.

Alternatively, you can also use any board from the PCI-62xx series or the PCI-60xx series. For these boards, please change the Counter base frequency from 100 MHz to 80 MHz or 20 MHz, respectively.

  1. Connect your PWM signal to both CTR 0 GATE and CTR 1 GATE input pins. To measure both PWM frequency and duty, two counter channels are required.

  2. To switch to Connected IO mode if needed, on the Desktop Real-Time tab, select Mode > Connected IO.

  3. To start the real-time execution, click Run in Real-Time.

Run Model in Run in Kernel Mode

This model is pre-set to be used with the National Instruments PCIe-6323 board. You can use it with any board from the PCIe-63xx series. To change the board, open both the Counter Input blocks and select your data acquisition board. You may need to register the board by clicking the Install new board button first.

Alternatively, you can also use any board from the PCI-62xx series or the PCI-60xx series. For these boards, please change the Counter base frequency from 100 MHz to 80 MHz or 20 MHz, respectively.

  1. Connect your PWM signal to both CTR 0 GATE and CTR 1 GATE input pins. To measure both PWM frequency and duty, two counter channels are required.

  2. To switch to Run in Kernel mode if needed, on the Desktop Real-Time tab, select Mode > Run in Kernel.

  3. To start the real-time execution, click Run in Real Time.

The model builds, connects to Run in Kernel mode, and starts.

Open the Model

warning('off','sldrt:blkgui:boardnotonlist');
open_system('sldrtex_pwmmeasure');

Close Open Scopes

close_system(find_system(gcs ,'BlockType', 'Scope'));

Clean Up Model

clear
close all
bdclose all

See Also