2

I spent quite some time, but I wasn't able to find the answer (and found other interesting sources like changing pwm frequency 1 and changing the frequency 2), and I lack the equipment to find out by myself.

I'm on a Raspberry Model B, using NodeJS along with wiring-pi. To initialize and setup PWM on Pin12 = WiringPiPin1 = GPIO1 = BCM18 = the hardware-PWM-enabled-PIN I'm using the following code:

var wpi = require('wiring-pi'); 

var wiringPiMotorPin = 1;
wpi.wiringPiSetup();
wpi.pinMode(wiringPiMotorPin, wpi.modes.PWM_OUTPUT);
var motorState = 0;

// target state ranges from 0-1024
var setMotor = function(targetState) {
    if (motorState != targetState) {
        wpi.pwmWrite(wiringPiMotorPin, targetState);
        motorState = targetState;
    }
};

So I didn't change anything to the PWM-divider using e.g. pwmSetClock. What is 'default' settings for duty cycle/frequency of the hardware-PWM? I need to know, because I need to setup a RC-lowpass-filter (PWM-frequency is audible from the connected motor).

Thank you very much in advance.

Boern
  • 192
  • 1
  • 10

3 Answers3

3

Based on RyanO suggestion, I setup pi-gpio with the commands

cd /opt/
sudo mkdir piscope
cd piscope
sudo wget abyz.me.uk/rpi/pigpio/pigpio.zip
sudo unzip pigpio.zip
cd PIGPIO
sudo make
sudo make install

and then setup piscope with the commands

cd /opt/piscope
sudo wget abyz.me.uk/rpi/pigpio/piscope.tar
sudo tar xvf piscope.tar
cd PISCOPE
sudo make hf
sudo make install

and then started pi-gpio-deamon and piscope with

sudo pigpiod
piscope

After some zooming and with a PWM value of 256 (with 1024 being the max-value) I ended up with the following image:

piscope

which indicates a duty cycle of 20us. The frequency should be (in case the duty cycle doesn't depend on the value) therefore 50000Hz = 50kHz

Boern
  • 192
  • 1
  • 10
2

Apologies if this isnt the correct format for presenting this information, I'm new to StackExchange.

While I dont have the short answer you're looking for (default duty cycle and frequency), I've been working on some software PWM and, likewise, dont have the equipment to validate the output of the GPIO's.

I came across this software which acts as a logic analyser, run on the pi, and should allow you to work out the answer for yourself:

http://abyz.me.uk/rpi/pigpio/piscope.html

I've not got round to trying it out for myself, but I hope it helps.

RyanO
  • 21
  • 3
-1

I doubt there is an easy answer. You may need to look at the wiringPi source code and the wrapper you are using.

If the gpio is in balanced rather than mark/space mode (pwmSetMode) there will be no fixed PWM update frequency. It will vary with dutycycle, clock divider, and range.

If the gpio is in mark/space the update frequency will be the source clock frequency (probably 19200000) divided by the clock divider (pwmSetClock) divided by the range (pwmSetRange).

You'll need to check the defaults in the various wrappers you are using.

joan
  • 71,852
  • 5
  • 76
  • 108