In this tutorial we are going to read the Duty Cycle of a PWM signal using Visuino. For a PWM source we are going to use a PWM generator connected to the Arduino interrupt digital pin [2],
We are going to measure the pulse width of the HIGH and LOW then use this formula
TotalDuration = highDuration + lowDuration;
DutyCycle = 100.0 * highDuration / totalDuration
to get the Duty Cycle in percentage.
Watch the video!
Select "DivideByValue1" and in the properties window select "Value" and click on the pin icon and select "Float SinkPin"Select "MultiplyByValue1" and in the properties window set "Value" to 100
We are going to measure the pulse width of the HIGH and LOW then use this formula
TotalDuration = highDuration + lowDuration;
DutyCycle = 100.0 * highDuration / totalDuration
to get the Duty Cycle in percentage.
On the schematic you can see that we split the digital pulses using "MultiSource1", First signal we take it directly to "PulseMeter1" to get the pulse period when it is HIGH, Second signal we invert it using "Inverter1" and we take it to "PulseMeter2" to get a pulse period when its LOW, we convert both periods to analog values and we sum them to get the total length using "Add1", then we use "DivideByValue1" to divide HIGH pulse period / Sum of both periods, and we multiply all at the end by 100 using "MultiplyByValue1"
If you power the Arduino module and click connect in the "Serial" tab, you will be able to see the Duty Cycle of the Input PWM signal.
Congratulations! You have completed your project with Visuino. Also attached is the Visuino project, that I created for this tutorial, you can download it and open it in Visuino: https://www.visuino.com