3

My target is to code a GUI in Java where with which the user can output a PWM signal over one of the Hardware-PWM Pins of the Raspberry 3. Doing so, the user should be able to select the length of a whole pulse (in ms), the length of the duty cycle (in ms) and how often the pulse is repeated.

To code this, I used the Pi4J library (http://pi4j.com) which is based on WiringPi. When trying to actually create a PWM signal, I noticed that there are three main functions:

pwmSetRange(int x) pwmSetClock(int x) Setpwm(int x)

As far as I understood these functions correctly, setRange basically sets the possible single steps for the duty cycle while setclock sets the divisor for the frequency and setpwm sets the duty cycle.

But how can I configure these methods correctly depending on the user input?

And also what I noticed: Referencing to an article I read, the PWM frequency gets calculated using following formula: frequency = 19.2e6 Hz / pwmClock / pwmRange while for clock values up to 4095 and for range up to 4096 are accepted. Did I understand it correctly that with the Pi's hardware PWM only frequencies from around 1.2Hz up to 1920Hz are possible?

Jas On
  • 51
  • 7

0 Answers0