Fast PWM

Let’s create a PWM output via fast outputs.

One of the “features” of PRU programs is you can’t just call TIME() and get “current time”. On the other hand, PRU programs are highly predictable, and PRU cores have no other work to do except user program. For instance PRU core does not have overhead like “TCP processing”. That is why you can think of PRU cycle to have exact duration.

If you have Hardella IDE opened, you can either open code sample in the IDE, or you can create a new project with this code (File > New > Project > Fast counter).

PWM output is trivial if you use standard library:

PWM program

PWM period (period) and PWM value (value) come from the main PLC program.

On the other hand, PWM is quite trivial: it just counts the number of calls and assigns the value to Q depending on the PWM value.

PWM block source code

Updated:

Leave a Comment