Chacha71
Posts: 1
Joined: Wed Sep 18, 2019 6:41 pm
Location: France

Audio PWM frequency configuration on a Raspberry Pi 3b+

Wed Sep 18, 2019 10:04 pm

Hello,
I'm currently working on a project that involves transmitting audio information from a Raspberry Pi 3b+ using a PWM signal, to another device, but using a carrier frequency of ~40kHz.

I had no trouble redirecting the audio to the GPIO pin 18, but now I'm stuck with the frequency that is too high (I could measure around 800kHz).
I've been trying to lower it with different C libraries (bcm2835.h and wiringPi), and using a direct configuration in /sys/class/pwm/pwmchip0/pwm0/period, but the audio information was always detached from the PWM.

Since this is hardware PWM, the next idea that came to my mind was to write a device tree overlay fragment to alter the values of the right PLLs and clocks... but I have no idea how to do that nor where to fetch the correct information in the datasheets and documentation (the only significant info I could find was this post by Avian who had retro-engineered the general-purpose clock generation mechanism).

During my experiments with wiringPi I could notice that some really slight duty-cycle variation was present when VLC was running, even when no audio was being played.
I first thought that this could still be linked to the music, but it appeared to be some kind of noise (the amplitude didn't vary with the volume).

Finally after more reflexion I also started to fear that the black magic process that encodes the sound in the PWM may be optimized for 800kHz, and would dysfunction with different clock settings.


My question is probably easier to guess than to solve: does a method exist to lower the hardware PWM frequency but to still be able to use the audio information with it?


(This post is my last attempt at finding a solution to change the frequency through software manipulation before using an external TL494 IC to do the work electronically, so don't worry for the project, I still have a fallback solution ^^)

Return to “Advanced users”