I want to make use of the clock of rpi. How can I do it? On an arduino it would have been as easy as setting up an TCCR and the respective pin would give the required clock signal. I require two clock signals for my circuit,44.1 KHz and 16 MHz. If it is at all possible, how can it be done?

I know GPIO4 can be used as GPCLK0 in an alternate mode but only that about it. Any suggestion would be appreciated. Thank you.


Command Line http://abyz.me.uk/rpi/pigpio/pigs.html#HC

C and Python equivalents are available.

HC g cf - Set hardware clock frequency

This command sets the hardware clock associated with GPIO g to
frequency cf. Frequencies above 30MHz are unlikely to work.

Upon success nothing is returned. On error a negative status
code will be returned.


$ pigs hc 4 5000 # start a 5 KHz clock on GPIO 4 (clock 0)

$ pigs hc 5 5000000 # start a 5 MHz clcok on GPIO 5 (clock 1)
ERROR: need password to use hardware clock 1

The same clock is available on multiple GPIO. The latest
frequency setting will be used by all GPIO which share
a clock.

The GPIO must be one of the following.

4   clock 0 All models
5   clock 1 All models but A and B (reserved for system use)
6   clock 2 All models but A and B
20  clock 0 All models but A and B
21  clock 1 All models but A and B (Rev. 2) (reserved for system use)

32  clock 0 Compute module only
34  clock 0 Compute module only
42  clock 1 Compute module only (reserved for system use)
43  clock 2 Compute module only
44  clock 1 Compute module only (reserved for system use)

Access to clock 1 is protected by a password as its use will
likely crash the Pi. The password is given by or'ing
0x5A000000 with the GPIO number.
  • Thank you for your reply! But please can you mention what does it mean by 'All models but A and B.'? Will these commands still start a clock on pin 6 and 20 since others as it mentions are reserved for system use and I would not want to crash my pi? – cr0ssb0w Jun 27 '16 at 6:09
  • All models but A and B means A+, B+, Pi Zero, Pi2B, Pi3B, and the Compute Module. Clock 1 is used for Ethernet timing. Don't use clock 1 unless you know what you are doing. Clock 0 and 2 are safe. You can also use the two hardware PWM channels to create a clock (see the similar HP command). – joan Jun 27 '16 at 7:23
  • The library works well. Thank you. But I was only able to generate clock signals up to 5 MHz. The DSO would also verify it. But anything above 5 MHz, the DSO would not show it (shows some arbitrary data) even though the library you provided says it is capable of producing up to 30 MHz. Is there an issue with frequencies above 5Mhz? – cr0ssb0w Jun 28 '16 at 18:47
  • Not that I am aware of. The same maths is used for all frequencies so I doubt it would suddenly go wrong at 5 MHz. What command are you using? – joan Jun 28 '16 at 19:00
  • $ pigs hc 4 6000000 #for 6 MHz – cr0ssb0w Jun 28 '16 at 19:13

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.