EduardH
Posts: 32
Joined: Fri Sep 04, 2015 8:10 am

GPIO4 and GPIO5

Fri Feb 09, 2018 5:54 pm

Good evening,

I want to use the rpi zero for generating two square waves. Speed between 500 kHz and 1700 kHz. No problem using GPIO4 (pin 7). With only a few lines bare metal assembler it works fine. I used the information from page 102 in the BCM2835 Peripheral manual.

Why doesn’t the same method work with GPIO5 ?. (gpclk1, pin 29) I configured GPIO5 as alternative function 0, in my case a second general purpose clock. I used twice an integer division from PLL C (1000 MHz) to come as close as possible to the desired frequency without having too much jitter.

GPIO4 works very nice for driving external circuits. Is it possible to use a rpi for generation a second square wave with another frequency?

Best regards,

Eduard

EduardH
Posts: 32
Joined: Fri Sep 04, 2015 8:10 am

Re: [solved] GPIO4 and GPIO6 instead of GPIO5

Sat Feb 10, 2018 9:45 am

Good morning,

My question about generating two independently selectable frequencies is solved. Using GPIO5 for the second output was a bad idea. The system seems to use the signal behind GPIO5 for its own. There is one line telling that in this text: https://raspberrypi.stackexchange.com/q ... ose-clocks

Instead of using GPIO5, I did the same using GPIO6. To obtain frequencies with low jitter I used integer division from the rpi zero PLLC clock. (1000MHz). Maybe later on I'll take a look at division by a floating point number. As soon as the external hardware has been soldered I will examine the jitter more close. Integer division seems to be fine.

Perhaps it can be useful, please find the code snippet here:

Code: Select all

.section .init
.globl _start
_start:

ldr r0,=0x20200000
ldr r1,=0x104000     /* GPIO4 and GPIO6 alt function 0 = gpioclk */
str r1, [r0, #0]

ldr r0,=0x20101070
ldr r1,=0x5A000015     /* GPIO 4 clock source = PLLC, 1000 MHz */
str r1, [r0, #0]

ldr r0,=0x20101074
ldr r1,=0x5A437000     /* clock divisor = 1079, GPIO4 = 927 kHz */
str r1, [r0, #0]

ldr r0,=0x20101080
ldr r1,=0x5A000015     /* GPIO 6 clock source = PLLC, 1000 MHz */
str r1, [r0, #0]

ldr r0,=0x20101084
ldr r1,=0x5A71D000     /* clock divisor = 1821, GPIO6 = 549 kHz */
str r1, [r0, #0]

loop$: 
nop
b loop$

Because the problem is solved this tread may be closed.

Best regards,

Eduard

Return to “Bare metal, Assembly language”

Who is online

Users browsing this forum: No registered users and 4 guests