ndzied1
Lifetime Supporting Member
Here is an example of a PWM type simulator in free software. CoDeSys.
The PWM in this example is 10hz and is outputting the PWM equivalent of a Sine wave with a 5 second period.
I used a function generator to create a sine wave with the period I would want the lights to pulse at and scale that sine wave to 0 to 1.0.
Then I run a timer that resets itself every cycle (10Hz -> 100ms timer). I then create a number from 0 to 1.0 by dividing the elapsed time of the timer by the total time of the timer. So this number represents a fraction of the elapsed time. i.e., when the number is 0.3, 30% of the period has passed. When the number is 0.75, 75% of the period has passed etc.
Lastly, compare the current percentage of the PWM period to the sine wave percentage. If the PWM period percentage is <= the Sine wave percentage then turn the output on, otherwise, turn it off.
Here's a little video...
https://youtu.be/rDETvu1tuDE
The PWM in this example is 10hz and is outputting the PWM equivalent of a Sine wave with a 5 second period.
I used a function generator to create a sine wave with the period I would want the lights to pulse at and scale that sine wave to 0 to 1.0.
Then I run a timer that resets itself every cycle (10Hz -> 100ms timer). I then create a number from 0 to 1.0 by dividing the elapsed time of the timer by the total time of the timer. So this number represents a fraction of the elapsed time. i.e., when the number is 0.3, 30% of the period has passed. When the number is 0.75, 75% of the period has passed etc.
Lastly, compare the current percentage of the PWM period to the sine wave percentage. If the PWM period percentage is <= the Sine wave percentage then turn the output on, otherwise, turn it off.
Here's a little video...
https://youtu.be/rDETvu1tuDE