diff --git a/RaspberryPiZeroW_bcm2835/bcm2835-02ma.png b/RaspberryPiZeroW_bcm2835/bcm2835-02ma.png new file mode 100755 index 0000000000000000000000000000000000000000..bc76709bd3807c695ee8f92dc7abf19f0a210550 Binary files /dev/null and b/RaspberryPiZeroW_bcm2835/bcm2835-02ma.png differ diff --git a/RaspberryPiZeroW_bcm2835/bcm2835-06ma.png b/RaspberryPiZeroW_bcm2835/bcm2835-06ma.png new file mode 100755 index 0000000000000000000000000000000000000000..403d034aaf44ad4fa0f14f0e216e59c38cd98045 Binary files /dev/null and b/RaspberryPiZeroW_bcm2835/bcm2835-06ma.png differ diff --git a/RaspberryPiZeroW_bcm2835/bcm2835-16ma.png b/RaspberryPiZeroW_bcm2835/bcm2835-16ma.png new file mode 100755 index 0000000000000000000000000000000000000000..27bc4163efb2857fc64b20a6a9d8ead19d26ddec Binary files /dev/null and b/RaspberryPiZeroW_bcm2835/bcm2835-16ma.png differ diff --git a/RaspberryPiZeroW_bcm2835/index.html b/RaspberryPiZeroW_bcm2835/index.html new file mode 100644 index 0000000000000000000000000000000000000000..d692fc842e130f50a3a8f8c134d6d9ebdba09bd1 --- /dev/null +++ b/RaspberryPiZeroW_bcm2835/index.html @@ -0,0 +1,72 @@ +<html> +<head> +<style> +pre code { + background-color: #eee; + border: 1px solid #999; + display: block; + padding: 20px; +} +</style> + + +</head> +<body> + +<h1>RaspberryPi Zero W with BMC2835</h1> + +<figure> +<img src='bcm2835-06ma.png'> +<figcaption>Ring oscillator with 6mA pad current.</figcaption> +</figure> + +<p>This ring oscillator uses the <a href='http://www.airspayce.com/mikem/bcm2835/index.html'>BCM2835 library</a> from Mike McCauley. The code is available <a href='ring.c'>here</a>, or visible below.</p> + +<pre> +<code> +//build: +// gcc -o ring ring.c -l bcm2835 +//run: +// sudo ./ring +#include <bcm2835.h> +#include <stdio.h> +#define PIN_OUT RPI_GPIO_P1_11 +#define PIN_IN RPI_GPIO_P1_15 + +int main(int argc, char **argv) +{ + if (!bcm2835_init()) + return 1; + + //set changing pad current can change ringing characteristics on pulses + bcm2835_gpio_set_pad(BCM2835_PAD_GROUP_GPIO_0_27, BCM2835_PAD_DRIVE_6mA); + + //this block is supposed to prevent kernel swapping + //I didn't get it to compile... + //struct sched_param sp; + //memset(&sp, 0, sizeof(sp)); + //sp.sched_priority = sched_get_priority_max(SCHED_FIFO); + //sched_setscheduler(0, SCHED_FIFO, &sp); + //mlockall(MCL_CURRENT | MCL_FUTURE); + + bcm2835_gpio_fsel(PIN_OUT, BCM2835_GPIO_FSEL_OUTP); + bcm2835_gpio_fsel(PIN_IN , BCM2835_GPIO_FSEL_INPT); + //bcm2835_gpio_set_pud(PIN_IN, BCM2835_GPIO_PUD_UP); + while (1) + bcm2835_gpio_write(PIN_OUT, 1-bcm2835_gpio_lev(PIN_IN) ); + bcm2835_close(); + return 0; +} +</code> +</pre> + +<p>We can change the pad current to improve the ringing of the pulses:</p> +<figure> +<img src='bcm2835-16ma.png'> +<img src='bcm2835-02ma.png'> +<figcaption>A) 16mA pad current, B) 2 mA pad current</figcaption> +</figure> + +</body> + +</html> \ No newline at end of file diff --git a/RaspberryPiZeroW_bcm2835/ring.c b/RaspberryPiZeroW_bcm2835/ring.c new file mode 100644 index 0000000000000000000000000000000000000000..320b448a61dae30dd7abb723b7f978f8677ee07f --- /dev/null +++ b/RaspberryPiZeroW_bcm2835/ring.c @@ -0,0 +1,34 @@ +//build: +// gcc -o ring ring.c -l bcm2835 +//run: +// sudo ./ring +#include <bcm2835.h> +#include <stdio.h> +#define PIN_OUT RPI_GPIO_P1_11 +#define PIN_IN RPI_GPIO_P1_15 + +int main(int argc, char **argv) +{ + if (!bcm2835_init()) + return 1; + + //set changing pad current can change ringing characteristics on pulses + bcm2835_gpio_set_pad(BCM2835_PAD_GROUP_GPIO_0_27, BCM2835_PAD_DRIVE_6mA); + + //this block is supposed to prevent kernel swapping + //I didn't get it to compile... + //struct sched_param sp; + //memset(&sp, 0, sizeof(sp)); + //sp.sched_priority = sched_get_priority_max(SCHED_FIFO); + //sched_setscheduler(0, SCHED_FIFO, &sp); + //mlockall(MCL_CURRENT | MCL_FUTURE); + + bcm2835_gpio_fsel(PIN_OUT, BCM2835_GPIO_FSEL_OUTP); + bcm2835_gpio_fsel(PIN_IN , BCM2835_GPIO_FSEL_INPT); + //bcm2835_gpio_set_pud(PIN_IN, BCM2835_GPIO_PUD_UP); + while (1) + bcm2835_gpio_write(PIN_OUT, 1-bcm2835_gpio_lev(PIN_IN) ); + bcm2835_close(); + return 0; +} +