MATLAB Examples

PWM Frequency and Duty Measurement

The example model "sldrtex_pwmmeasure" 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.

How to run this model in Normal Mode:

  1. 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 using the Install new board button first.
  2. 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.
  3. 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.
  4. Double-click the orange button to switch to Normal Mode if needed.
  5. Start the real-time execution using Simulation->Run.

How to run this model in External Mode:

  1. 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 using the Install new board button first.
  2. 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.
  3. 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.
  4. Double-click the orange button to switch to External Mode if needed.
  5. Start the real-time execution using Simulation->Run. The model will automatically build, connect to Simulink in External Mode and start.

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