fivdi / pigpio

Fast GPIO, PWM, servo control, state change notification and interrupt handling with Node.js on the Raspberry Pi
MIT License
948 stars 89 forks source link

configureClock go above 10 microSeonds sample rate? #90

Closed bodtx closed 4 years ago

bodtx commented 4 years ago

according to the doc you cannot go below 1 microseconds

as I can see on my oscilloscope I cannot go below approximatly 1/(0.2×10⁻3) = 5000 5Khz with pigpio.configureClock(1, pigpio.CLOCK_PCM).

how could I go to 20kHz (to control motors, which is a good frequency)?

I have already one motor on the hardware pwm pin.

fivdi commented 4 years ago

What frequency does the oscilloscope see on GPIO17 if the below program is run. It should see approximately 20kHz.

const pigpio = require('pigpio');
const Gpio = pigpio.Gpio;

pigpio.configureClock(1, pigpio.CLOCK_PCM);

const led = new Gpio(17, {mode: Gpio.OUTPUT});

led.pwmFrequency(20000);
led.pwmRange(50);
led.pwmWrite(25);

setTimeout(_ => {}, 1e6);
fivdi commented 4 years ago

To the best of my knowledge the information needed has been provided here so I'll go ahead and close the issue,

bodtx commented 4 years ago

Sorry for responding late, after testing to the oscilloscope, it works! 🏅

When monitoring the cpu it was at 25% approximately as the doc says. I've tried to lower the configureClock to 5 or so but it was impossible to reach the 20KHz.

maybe you should add a word in the doc about pwmFrequency pwmRange ?

fivdi commented 4 years ago

Sorry for responding late, after testing to the oscilloscope, it works! 🏅

No problem.

maybe you should add a word in the doc about pwmFrequency pwmRange ?

The documentation for pwmFrequency is here. As can be seen in the table, a frequency of 20kHz is possible when the sampling rate is 1us or 2us. The table also shows that the maximum frequency at a sampling rate of 5us is 8kHz.

The documentation for pwmRange is here.

What can be added to the documentation to improve things?