What is the register used for setting a divisor on the PWM clock on the BCM2835? I looked at the data sheet (Raspberry-Pi-BCM2835-ARM-Peripherals) - but couldn't find this information.

But this information must be available somewhere, because going through the wiringPi code, I find:

#define BCM2708_PERI_BASE   0x20000000
#define CLOCK_BASE  (BCM2708_PERI_BASE + 0x00101000)
#define PWMCLK_DIV  41
clk = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, CLOCK_BASE) ;
*(clk + PWMCLK_DIV) = BCM_PASSWORD | (divisor << 12) ;

I don't know where 0x00101000 and 41 are coming from. Could you point me to documentation that explains the above?


I don't remember where the location of the PWM and PCM clocks is documented. The peripherals document does give the locations of GPCLK0/1/2.

All the clocks are accessed from the clock peripheral. The normally used ones are at these offsets from the base register (0x20101000).

#define CLK_GP0_CTL 28
#define CLK_GP0_DIV 29
#define CLK_GP1_CTL 30
#define CLK_GP1_DIV 31
#define CLK_GP2_CTL 32
#define CLK_GP2_DIV 33

#define CLK_PCM_CTL 38
#define CLK_PCM_DIV 39

#define CLK_PWM_CTL 40
#define CLK_PWM_DIV 41

The operation of the clocks is described from page 105 of the peripherals document. That explains the registers.

More example code at Minimal clock access.


More info about PWM/PCM clocks at clocks addendum

Another useful source is the eLinux errata

  • Thanks. Where did you get the base register value 0x20101000 from? I couldn't find that in the data sheet.
    – M-V
    Nov 24 '14 at 7:33
  • Honestly I don't remember. Probably just someones post. The kernel sources for the Pi would be one way of finding these values. I added more info to my post.
    – joan
    Nov 24 '14 at 8:56
  • I had seen the errata and page 105. The latter talks only about GP0, GP1, GP2 - no mention of PCM and PWM clocks. I wish this information was easier to find.
    – M-V
    Nov 24 '14 at 10:25
  • The clocks addendum has the information. The 0x7e1010a0 CM_PWMCT register address is 0x7e000000 + 0x101000 + 41*sizeof(int)
    – M-V
    Nov 25 '14 at 6:12
  • Found the complete BCM2835 register information (thanks to my pal Ravi).
    – M-V
    Nov 25 '14 at 23:47

You could use wiringpi C library, which provides software pwm channels, I use it to drive some LEDs.

  • I am trying to understand the hardware PWM pins. I already got it to work. What I am looking for is the register information, which I can't seem to find in the specs.
    – M-V
    Nov 24 '14 at 8:48
  • 1
    @marko-frelih You'd probably be better off using hardware timed PWM from the likes of pigpio. Less likely to get visible glitches.
    – joan
    Nov 24 '14 at 9:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.