macca
Posts: 118
Joined: Tue Oct 16, 2012 9:14 am

PWM data/range/clock relationship

Mon Sep 15, 2014 8:55 am

Hi,

I'm experimenting with audio pwm output using the source code provided by krom (PeterLemon) as the base for a port to C, it is working very well, however I can't understand the relationship between the pwm clock, range and data. For example I see that 12, 13 and 14 bit 44100/mono output are all using the same clock divisor $2000 and the same range value $2C48 which doesn't seems right to me. The 8 bit audio example uses a different range $1B4 so I was expecting that also 12, 13 and 14 bit uses different ranges. Reading the BCM2835 ARM Peripherals documentation isn't of much help because the values looks wrong to me (also the clock source looks wrong, the code says it uses PLLC but the instruction has CM_SRC_PLLCPER + CM_SRC_OSCILLATOR = $05 + $01 = $06 PLLD), but indeed it is working right so I must be missing something.

Can someone explain me that relationship ? What I would like to do is parametrize the code so the user can choose the audio parameters (sample rate, width, mono/stereo) and the code do the calculations needed to set the correct clock and range parameters.

User avatar
joan
Posts: 14079
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: PWM data/range/clock relationship

Mon Sep 15, 2014 9:10 am

PLLC may be a typo. Probably best not to use it if you may overclock.

Clock sources.

Code: Select all

0     0 Hz     Ground
1     19.2 MHz oscillator 
2     0 Hz     testdebug0
3     0 Hz     testdebug1
4     0 Hz     PLLA
5     1000 MHz PLLC (changes with overclock settings)
6     500 MHz  PLLD
7     216 MHz  HDMI auxiliary
8-15  0 Hz     Ground

User avatar
DexOS
Posts: 876
Joined: Wed May 16, 2012 6:32 pm
Contact: Website

Re: PWM data/range/clock relationship

Wed Sep 17, 2014 5:26 pm

Me and krom work on audio together, and our work was based on work by Joeboy, which is in C, so that may help you.
https://github.com/Joeboy/pixperiments/ ... pi/audio.c
Batteries not included, Some assembly required.

macca
Posts: 118
Joined: Tue Oct 16, 2012 9:14 am

Re: PWM data/range/clock relationship

Thu Sep 18, 2014 3:43 pm

That's a bit of a help, however, if I understand it correctly, it is not possible to get 44100Hz 16bit with pwm, and with 16bits range the sample rate drops considerably.

For what I want to do, 14 bits is enough, I don't think that parametrizing the code is worth the effort.

Thanks for your help.

Return to “Bare metal, Assembly language”