sarfata / pi-blaster

PWM on the Raspberry pi - done properly (in hardware, stable)
846 stars 130 forks source link

Change PWM Frequency tp 25kHz? #107

Open Ch3fk0ch88 opened 6 years ago

Ch3fk0ch88 commented 6 years ago

Hy, on which way i can cahnge the PWM Frequency to 25kHz? I found nothing in the internet....

Thanks

sarfata commented 6 years ago

The README gives some explanation: https://practicingruby.com/articles/tricks-for-working-with-text-and-files but it seems a bit outdated.

For 25kHz, you will need a period of 40us. If you change CYCLE_TIME_US in the source code to 4 instead of 1000 you should get a 25kHz PWM. Be aware however that you will only have 4 steps to adjust the duty rate of the PWM, roughly: 25%, 50%, 75%, 100%.

To improve this, you can reduce SAMPLE_US and set it to 2us (or maybe even 1us) and you will get 40us/2us = 20 (or 40) steps for your PWM.

Let me know how that works for you!

sarfata commented 6 years ago

After the changes in the code, the startup code shows:

pi@raspberrypi:~/pi-blaster $ sudo ./pi-blaster -D
MBox Board Revision: 0x10
DMA Channels Info: 0x7f35, using DMA Channel: 14
Using hardware:                   PWM
Number of channels:                32
PWM frequency:               25000 Hz
PWM steps:                         20
Maximum period (100  %):         40us
Minimum period (5.000%):          2us
DMA Base:                  0x20007000
Initialised, Reading /dev/pi-blaster.

I will try to hook up a oscilloscope and confirm everything still works but it should ;)

Ch3fk0ch88 commented 6 years ago

So, i tried it but i get no PWM Signal^^ Have to make a resetup, seems that something is worng.

Ch3fk0ch88 commented 6 years ago

So, i tested it again but i dont get a signal with the changed pi-blaster.c

sarfata commented 6 years ago

Yes I have done some tests too and I it does not work when there are less than 200 samples (cycles period divided by time unit).

So right now the highest frequency available is 1/200us so 5kHz.

I am pretty sure it’s a bug in pi-blaster somewhere but I have not figured where yet.

On Fri, Oct 5, 2018 at 11:00 PM Ch3fk0ch88 notifications@github.com wrote:

So, i tested it again but i dont get a signal with the changed pi-blaster.c

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/sarfata/pi-blaster/issues/107#issuecomment-427497429, or mute the thread https://github.com/notifications/unsubscribe-auth/AAvi_TLcK4Wm64r9cirardR8hgI_nY0rks5uh8hngaJpZM4XIp_2 .

Ch3fk0ch88 commented 6 years ago

Ok, Let me know when u find a solution.

Thanks

Ch3fk0ch88 commented 5 years ago

Hello, It's been a while, have you found the bug by now?

sarfata commented 5 years ago

No sorry. I have not been working on this project.

prunes-git commented 4 years ago

I am also having this issue, although the fans I'm controlling appear to work at 5khz their spec sheet says 21k to 28k. I have also had a play and confirmed the minimum 200 samples is still the issue.

sarfata commented 4 years ago

Would be great if someone could do a PR to fix this. I would gladly review and merge it.