LabVIEW BCM2835 Library for Raspberry Pi

77
LabVIEW BCM2835 Library for Raspberry Pi Revision: Issue 1.1 Date: 29/09/2016 Author: Derek Murray Revision History Rev Description of Change Author Active Date Issue 1.0 First Issue Derek Murray 28/09/2016 Issue 1.1 Updated some figures Derek Murray 29/09/2016

Transcript of LabVIEW BCM2835 Library for Raspberry Pi

Page 1: LabVIEW BCM2835 Library for Raspberry Pi

LabVIEW BCM2835 Library for Raspberry Pi

Revision: Issue 1.1

Date: 29/09/2016

Author: Derek Murray

Revision History

Rev Description of Change Author Active Date

Issue 1.0 First Issue Derek

Murray 28/09/2016

Issue 1.1 Updated some figures Derek

Murray 29/09/2016

Page 2: LabVIEW BCM2835 Library for Raspberry Pi

LabVIEW BCM2835 Library for Raspberry Pi

29/09/2016 Page 2 of 77 Issue 1.1

Contents

1 Introduction ............................................................................................................................... 5

1.1 LabVIEW and MakerHub LINX Compatibility ............................................................................. 5

1.2 Prerequisite Software .............................................................................................................. 6

1.3 Palette Details ......................................................................................................................... 6

1.3.1 GPIO Palette ............................................................................................................................. 7

1.3.2 PWM Palette ............................................................................................................................. 8

1.3.3 SPI Palette ................................................................................................................................. 8

1.3.4 I2C Palette................................................................................................................................. 9

1.3.5 Timing Palette ......................................................................................................................... 10

1.4 Examples............................................................................................................................... 10

1.5 Points to Note and Known Limitations ................................................................................... 10

2 BCM2835 Library Installation .................................................................................................... 12

2.1 Copy the Linux Shared Object to the Raspberry Pi .................................................................. 15

3 Install the BCM2835 Examples .................................................................................................. 28

3.1 Run the PWM-1Channel Project as a Test ............................................................................... 32

3.1.1 Run the PWM-1Channel Program using an LED ..................................................................... 40

4 Examples.................................................................................................................................. 41

4.1 Blink (GPIO Example) ............................................................................................................. 42

4.1.1 VI Documentation ................................................................................................................... 43

4.2 Set-Clear Multi (GPIO Example) ............................................................................................. 44

4.2.1 VI Documentation ................................................................................................................... 45

4.3 Write Multi (GPIO Example) ................................................................................................... 46

4.3.1 VI Documentation ................................................................................................................... 47

4.4 Write Mask (GPIO Example) ................................................................................................... 48

4.4.1 VI Documentation ................................................................................................................... 49

4.5 High Detect (GPIO Example) .................................................................................................. 50

4.5.1 VI Documentation ................................................................................................................... 51

4.6 Low Detect (GPIO Example) ................................................................................................... 52

4.6.1 VI Documentation ................................................................................................................... 53

4.7 High Detect Multi (GPIO Example) ......................................................................................... 54

4.7.1 VI Documentation ................................................................................................................... 55

4.8 Low Detect Multi (GPIO Example) .......................................................................................... 56

4.8.1 VI Documentation ................................................................................................................... 57

4.9 PWM 1-Channel (PWM Example) ........................................................................................... 58

4.9.1 VI Documentation ................................................................................................................... 59

4.10 PWM 2-Channel (PWM Example) ........................................................................................... 60

4.10.1 VI Documentation ............................................................................................................... 61

4.11 High-Speed Clock (PWM Example) ......................................................................................... 62

Page 3: LabVIEW BCM2835 Library for Raspberry Pi

LabVIEW BCM2835 Library for Raspberry Pi

29/09/2016 Page 3 of 77 Issue 1.1

4.11.1 VI Documentation ............................................................................................................... 63

4.12 TowerSG92R-Servo (PWM Example) ...................................................................................... 65

4.12.1 VI Documentation ............................................................................................................... 66

4.13 PCF2129AT (I2C Example) ...................................................................................................... 67

4.13.1 VI Documentation ............................................................................................................... 68

4.14 PmodTMP3+PCF2129AT (I2C Example) ................................................................................... 70

4.14.1 VI Documentation ............................................................................................................... 71

4.15 MCP3008 (SPI Example) ......................................................................................................... 73

4.15.1 VI Documentation ............................................................................................................... 74

5 PWM Timing Details ................................................................................................................. 75

Page 4: LabVIEW BCM2835 Library for Raspberry Pi

LabVIEW BCM2835 Library for Raspberry Pi

29/09/2016 Page 4 of 77 Issue 1.1

Related Documents/Links

(Links valid in September 2016)

Install Guide for Raspberry Pi + LabVIEW 2014 + MakerHub -LINX

MakerHub Library

C library for Broadcom BCM2835 as used in Raspberry Pi

Broadcom BCM2835 Arm Peripherals Specification

FileZilla

RasClock Real-Time Clock Module

PCF2129AT: NXP Accurate RTC

PmodTMP3 Reference Module

TCN75A: Microchip Digital Temperature Sensor

MCP3004/3008: Microchip A/D Converter with SPI Serial Interface

TMP36: Analog Devices Low Voltage Temperature Sensor

Page 5: LabVIEW BCM2835 Library for Raspberry Pi

LabVIEW BCM2835 Library for Raspberry Pi

29/09/2016 Page 5 of 77 Issue 1.1

1 Introduction

The LabVIEW BCM2835 library expands the GPIO interface with the Raspberry Pi (RPi) 2/3 over and above what is available with the MakerHub LINX package. The original C library was created by Mike McCauley (and others) and can be found at this link. This library has been converted to a Linux shared object which is compatible with LabVIEW-LINX. The LabVIEW library is built using this shared object as a base, and it consists of a range of functions which interface with the shared object using Call Library Function Nodes.

Figure 1.1. BCM2835 Library GPIO and ALT modes

Figure 1.1 illustrates the GPIO and alternative modes that are available with the library; this is header J8 on the RPi 3. The functionality offered by the LabVIEW library is as follows:

All 26 GPIO pins are available as input/outputs, with the exception that GPIO2 and 3 (pins 3 and 5) cannot be configured as inputs with internal pull-down resistors because of the onboard I2C pull-up resistors.

When configured as inputs, the GPIOs can be configured with internal pull-up or internal pull-down resistors.

A 'Set-Clear Multi' VI is available to simultaneously set or clear a range of GPIOs.

A 'Write Multi' VI is available to simultaneously write 0 or 1 to a range of GPIOs.

Event detection is available on GPIOs configured as inputs, with options of high/low level detection, synchronous rising/falling edge detection, and asynchronous rising/falling edge detection.

The two PWM channels, 0 and 1, can be enabled, with two output pins available for both channels. PWM0 appears on pins 12 and 32; PWM1 appears on pins 33 and 35.

The SPI chip select signals SPI_CE0_N and SPI_CE1_N are available for use. (These are not useable on LINX)

I2C functionality is available, with similar functionality to LINX I2C.

1.1 LabVIEW and MakerHub LINX Compatibility

This library is designed to run on the MakerHub LINX Raspberry Pi userspace architecture (more details here), which is currently only compatible with LabVIEW 2014 32-bit. Thus, the library can only

Page 6: LabVIEW BCM2835 Library for Raspberry Pi

LabVIEW BCM2835 Library for Raspberry Pi

29/09/2016 Page 6 of 77 Issue 1.1

be used with LabVIEW 2014 32-bit. In developing the library, the LabVIEW 2014 Home Bundle was used, mainly because it is now marketed at a very low price for Makers. More details on obtaining this version of LabVIEW, and installing all related packages can be found in this document. Sourcing and installing the MakerHub LINX package is also covered in that document.

1.2 Prerequisite Software

The user should have the following software/packages already on the PC before installing the BCM2835 Library and examples (again, refer to this document):

LabVIEW 2014 SP1 (Home Bundle used in this document).

JKI VIPM (Version 2016.0.0 build 1986 used in this document)

Digilent MakerHub LINX (VIPM version 3.0.1.192)

1.3 Palette Details

A brief description of the palettes will be given in this section. A better understanding of the library functionality can be found in the Examples part of the document (Section 4).

When the library is installed, as will be detailed in Section 2, it can be found in the Addons menu on the block diagram (Figure 1.2).

Figure 1.2. BCM2835 Library in Addons menu

Three main VIs are found in this first palette (the sub-folders will be described later in the section):

Initialize: Opens the BCM2835 library. Must be called before accessing any other function in the

library. It will return an error if the library cannot be opened.

Init + Version: Identical to 'Initialize', except that it also returns the library version embedded in

the C-code("10050", which is version 1.5). Note that this version number has nothing to do with

the LabVIEW VIPM version number. This VI can be used instead of 'Initialize'.

Close: Must be used when the program ends to release the library and any resources.

Page 7: LabVIEW BCM2835 Library for Raspberry Pi

LabVIEW BCM2835 Library for Raspberry Pi

29/09/2016 Page 7 of 77 Issue 1.1

1.3.1 GPIO Palette

Figure 1.3. GPIO Palettes

The standard GPIO VIs are:

GPIO Function: Used to set a GPIO to input, output, or one of its ALT modes.

GPIO Pullup: Sets the internal pull-up resistor for a GPIO to pull-up, pull-down, or off.

Set-Clear GPIO: Sets (logic 1) or clears (logic 0) a single GPIO.

Write GPIO: Similar to Set-Clear GPIO, writes a '0' or '1' to a single GPIO.

GPIO Level: Reads back the level of a GPIO. Works whether the GPIO is an input or output.

1.3.1.1 GPIO Multi

Set-Clear Multi: Simultaneously sets or clears a range of selected GPIOs.

Write Multi: Simultaneously writes to a range of selected GPIOs. More flexible than 'Set-Clear Multi', as some GPIOs can be set high and others set low.

Write Mask: Similar to 'Write Multi', as it simultaneously writes to a range of selected GPIOs. It is however more complicated than 'Write Multi' though, as 'Set-Clear GPIO' or 'Set-Clear Multi' must be used to clear GPIOs. The 'Write Multi' VI is recommended over 'Write Mask'.

1.3.1.2 Event Detect

Set Event Detect: Sets the event detection mode on an input, with options of high/low level detection, synchronous rising/falling edge detection, and asynchronous rising/falling edge detection.

Check Event Status: Check whether the set event has been detected on a GPIO.

Page 8: LabVIEW BCM2835 Library for Raspberry Pi

LabVIEW BCM2835 Library for Raspberry Pi

29/09/2016 Page 8 of 77 Issue 1.1

Clear Event Status: Clears the GPIO event in the event status register.

Clear Event Detect: Clears the event detection mode on the GPIO. Use when ending the program to reset the pin back to normal.

Multi Check Event Status: Checks for detected events on a range of GPIOs.

Multi Clear Event Status: Clears the detected events for a range of GPIOs.

1.3.2 PWM Palette

Figure 1.4. PWM Palette

The PWM VIs are:

PWM Clock: Sets the PWM clock divider, which effectively sets the highest PWM frequency available and the resolution of the PWM signal.

Set PWM Pin: Sets the PWM channel/pin to use. Options are PWM0 on pins 12 and 32, and/or PWM1 on pins 33 and 35.

PWM Mode: Sets the PWM mode to 'Mark-space' or 'Balanced', and also includes a control to turn the PWM signal on or off. Note that only 'Mark-space' mode has been tested. Users are free to experiment with 'Balanced' mode.

PWM Set Timing Parameters: Sets the timing of the PWM signal in terms of frequency and duty-cycle, or period and duty-cycle.

1.3.3 SPI Palette

Figure 1.5. SPI Palette

The SPI VIs are:

SPI Open: Must be used before other SPI VIs to enable SPI functionality.

Page 9: LabVIEW BCM2835 Library for Raspberry Pi

LabVIEW BCM2835 Library for Raspberry Pi

29/09/2016 Page 9 of 77 Issue 1.1

SPI Configure: Configures SPI settings such as chip select, data mode, etc. Note that in terms of bit order, only 'MSB First' is supported in the library.

SPI Data Transfer: Used to transfer data between the RPi (SPI master) and a SPI slave device.

SPI Close: Use when the program is ending to release SPI resources.

1.3.4 I2C Palette

Figure 1.6. I2C Palette

The I2C VIs are:

I2C Open: Must be used before other I2C VIs to enable SPI functionality.

I2C Configure: Sets the slave device address and the I2C clock speed. The clock speeds available are 100kHz, 400kHz, 1MHz, 1.666MHz, and 1.689MHz. If only one slave device is used in the system, then this function only needs to be used once, at the start of the program. If more than one I2C slave devices are used, then this function needs to be used every time a different device is accessed. See the example "" for more details.

I2C Write: Writes a number of bytes to the I2C slave.

I2C Read: Reads a number of bytes from the I2C slave.

I2C Write-Read (Repeated Start): Implements I2C repeated start functionality. Current untested.

I2C Read (Repeated Start): Implements I2C read repeated start functionality. Current untested.

I2C Close: Use when the program is ending to release I2C resources.

Page 10: LabVIEW BCM2835 Library for Raspberry Pi

LabVIEW BCM2835 Library for Raspberry Pi

29/09/2016 Page 10 of 77 Issue 1.1

1.3.5 Timing Palette

Figure 1.7. Timing Palette

Two timing VI's are also included, although the accuracy is unverified, particularly for the microseconds function. Users are free to experiment with these timing functions. For example, the 'Delay msec' function may be used in place of the LabVIEW 'Wait ms' function,

Delay ms: Delays for the specified number of milliseconds.

Delay us: Delays for the specified number of microseconds.

1.4 Examples

Because the BCM2835 LabVIEW package is such a low level package, it is impractical to include examples with it. Instead, a companion package can be installed which will add a range of examples to the LabVIEW 2014 examples directory. Section 3 details the installation procedure for the examples, while Section 4 gives further details on each example. Table 1.1 lists the available examples.

1.5 Points to Note and Known Limitations

The SPI bit-order can only be set to MSB First.

The I2C Repeated Start functions are untested.

Where PWM/clock timings are given in the document, note that they are valid only for an unmodified, non-over-clocked RPi, where the base clock is 19.2MHz. Performing timing-related hardware or software modifications on your RPi may change the timing.

The PWM functionality on the RPi 3 (and probably RPi 2 as well) drives the audio jack J7. If you have any audio SW and/or drivers driving J7, then it is unlikely that you will be able to use the PWM functionality for other purposes.

Page 11: LabVIEW BCM2835 Library for Raspberry Pi

LabVIEW BCM2835 Library for Raspberry Pi

29/09/2016 Page 11 of 77 Issue 1.1

Example Project Library Function

Description

Blink GPIO Alternately sets an LED on or off.

bcm-Write Multi GPIO Shows how to write to a range of GPIOs simultaneously.

bcm-Write Mask GPIO Another method for writing to a range of GPIOs simultaneously.

bcm-Set Clear Multi GPIO Shows how to set/clear a range of GPIOs simultaneously.

bcm-High Detect GPIO Demonstrates high-level detect, synchronous rising edge detect, and asynchronous rising edge detect for a single pin.

bcm-Low Detect GPIO Demonstrates low-level detect, synchronous falling edge detect, and asynchronous falling edge detect for a single pin.

bcm-High Detect Multi GPIO Demonstrates high-level detect, synchronous rising edge detect, and asynchronous rising edge detect for a range of pins.

bcm-Low Detect Multi GPIO Demonstrates low-level detect, synchronous falling edge detect, and asynchronous falling edge detect for a range of pins.

PWM-1Channel PWM Shows how to enable PWM for a single channel (pin)

PWM-2Channel PWM Shows how to enable PWM for two channels

bcm-High Speed Clock PWM Shows how to set higher frequency signals (up to 4.8MHz) on a PWM pin.

TowerSG92R-Servo PWM Demonstrates how to drive a simple micro-servo using PWM functionality.

bcm-PCF2129AT I2C Shows how to control a single I2C device.

bcm-PmodTMP3+PCF2129AT I2C Shows how driving two I2C devices differs from using a single I2C device.

bcm-MCP3008 SPI Demonstrates basic SPI functionality.

Table 1.1 Example projects available for the LabVIEW BCM2835 Library

Page 12: LabVIEW BCM2835 Library for Raspberry Pi

LabVIEW BCM2835 Library for Raspberry Pi

29/09/2016 Page 12 of 77 Issue 1.1

2 BCM2835 Library Installation

In this section, the installation of the LabVIEW BCM2835 library is detailed. Start by downloading the VIP package, and saving to a dedicated location.

Figure 2.1. Download the JKI package

Figure 2.2. Click Install to continue

Double click the package when it downloads. Assuming JKI VIPM is installed, the dialog as shown in figure 2.2 should appear (the version number will be higher though). Click Install to continue.

Page 13: LabVIEW BCM2835 Library for Raspberry Pi

LabVIEW BCM2835 Library for Raspberry Pi

29/09/2016 Page 13 of 77 Issue 1.1

Figure 2.3. The installation runs...

Figure 2.4. The package should install without any errors

Page 14: LabVIEW BCM2835 Library for Raspberry Pi

LabVIEW BCM2835 Library for Raspberry Pi

29/09/2016 Page 14 of 77 Issue 1.1

Figure 2.5. The library should now be visible in JKI VIPM

Figure 2.6. The library installs to \vi.lib\dmBCM2835

The library will install to "C:\Program Files (x86)\National Instruments\LabVIEW 2014\vi.lib\dmBCM2835". Note the shared object file 'libLV_2835.so' in the directory; this is required in the next section.

Page 15: LabVIEW BCM2835 Library for Raspberry Pi

LabVIEW BCM2835 Library for Raspberry Pi

29/09/2016 Page 15 of 77 Issue 1.1

Figure 2.7. The library is in the Addons menu as shown

On the block diagram, the library can be found under 'Addons->dmBCM2835'.

2.1 Copy the Linux Shared Object to the Raspberry Pi

To use the library, the Linux shared object file 'libLV_2835.so' must be saved to a specific location on the Raspberry Pi. The procedure will be detailed in this section. First, an FTP client such as Filezilla should be installed on the host PC. Go to "https://filezilla-project.org/" to find the FileZilla client to download (Figure 2.8).

Page 16: LabVIEW BCM2835 Library for Raspberry Pi

LabVIEW BCM2835 Library for Raspberry Pi

29/09/2016 Page 16 of 77 Issue 1.1

Figure 2.8. Download the FileZilla Client

Figure 2.9. Save to the PC

Page 17: LabVIEW BCM2835 Library for Raspberry Pi

LabVIEW BCM2835 Library for Raspberry Pi

29/09/2016 Page 17 of 77 Issue 1.1

Figure 2.10. Double-click to install

Figure 2.11. Accept the License Agreement

Page 18: LabVIEW BCM2835 Library for Raspberry Pi

LabVIEW BCM2835 Library for Raspberry Pi

29/09/2016 Page 18 of 77 Issue 1.1

Figure 2.12. Click Next to continue

Figure 2.13. Click Next to continue

Page 19: LabVIEW BCM2835 Library for Raspberry Pi

LabVIEW BCM2835 Library for Raspberry Pi

29/09/2016 Page 19 of 77 Issue 1.1

Figure 2.14. Click Next to continue

Figure 2.15. Click Install to continue

Page 20: LabVIEW BCM2835 Library for Raspberry Pi

LabVIEW BCM2835 Library for Raspberry Pi

29/09/2016 Page 20 of 77 Issue 1.1

Figure 2.16. Click Finish, with 'Start FileZilla now' checked

Figure 2.17. When Filezilla runs, go to "File->Site Manager"

Page 21: LabVIEW BCM2835 Library for Raspberry Pi

LabVIEW BCM2835 Library for Raspberry Pi

29/09/2016 Page 21 of 77 Issue 1.1

Figure 2.18. Click on 'New Site'

Page 22: LabVIEW BCM2835 Library for Raspberry Pi

LabVIEW BCM2835 Library for Raspberry Pi

29/09/2016 Page 22 of 77 Issue 1.1

Figure 2.19. Enter the connection details

Enter the following details::

Host IP Address (192.168.1.15 in my case; yours will likely be different).

Protocol = SFTP.

Logon Type = Normal.

User = pi (assuming you haven't changed it).

Password = raspberry (assuming you haven't changed it). Name the site "RPi" or similar, to save entering these details every time you use FileZilla with the RPi. Click Connect to continue.

Page 23: LabVIEW BCM2835 Library for Raspberry Pi

LabVIEW BCM2835 Library for Raspberry Pi

29/09/2016 Page 23 of 77 Issue 1.1

Figure 2.20. Drag 'libLV_2835.so' on the right to the RPi on the left

The connection to the RPi should be established at this point:

On the left side (Local site) navigate to 'C:\Program Files (x86)\National Instruments\LabVIEW 2014\vi.lib\dmBCM2835'

On the right side (RPi), navigate to '/home/pi/Downloads'.

Drag the file 'libLV_2835.so' from the local PC to the RPi Downloads folder.

FileZilla can be closed when the file is copied.

Page 24: LabVIEW BCM2835 Library for Raspberry Pi

LabVIEW BCM2835 Library for Raspberry Pi

29/09/2016 Page 24 of 77 Issue 1.1

Figure 2.21. Log in to the RPi remotely if necessary, unless using a monitor/keyboard/mouse combination

Next, log into the RPi using either a remote client like PuTTY (see above), or directly if using a monitor/keyboard/mouse combination (simply open a terminal on the RPi). If using PuTTY, log in as "pi" and enter "raspberry" as the password (assuming you haven't changed these parameters from the default.

Figure 2.22. Open a terminal on the RPi

Page 25: LabVIEW BCM2835 Library for Raspberry Pi

LabVIEW BCM2835 Library for Raspberry Pi

29/09/2016 Page 25 of 77 Issue 1.1

Figure 2.23. Log in to the LabVIEW chroot

Enter the commands below to log into the LabVIEW chroot:

cd /

ls

sudo schroot -r -c lv

Page 26: LabVIEW BCM2835 Library for Raspberry Pi

LabVIEW BCM2835 Library for Raspberry Pi

29/09/2016 Page 26 of 77 Issue 1.1

Figure 2.24. Go to /home/pi/Downloads and copy the shared object to /usr/lib/

Go to '/home/pi/Downloads' to find the ' libLV_2835.so ' file copied using FileZilla. Check the file permissions and, if necessary, change the file permissions to executable:

cd /home/pi/Downloads

chmod 755 libLV_2835.so

Next, copy the shared object to /usr/lib/

cp libLV_2835.so /usr/lib/

Page 27: LabVIEW BCM2835 Library for Raspberry Pi

LabVIEW BCM2835 Library for Raspberry Pi

29/09/2016 Page 27 of 77 Issue 1.1

Figure 2.25. Check that the file is in /usr/lib/

Go to /usr/lib/ to verify that the file has been copied:

cd /usr/lib/

ls libLV* -all

Once satisfied that the file is in /usr/lib/, type 'exit', and 'exit' again to shut the terminal down. The BCM2835 LabVIEW library can now be used with this RPi.

Figure 2.26. Exit the LabVIEW chroot and close the terminal down

Page 28: LabVIEW BCM2835 Library for Raspberry Pi

LabVIEW BCM2835 Library for Raspberry Pi

29/09/2016 Page 28 of 77 Issue 1.1

3 Install the BCM2835 Examples

Because the BCM2835 LabVIEW package is such a low level package, it is impractical to include examples with it. Instead, a companion package can be installed which will add a range of examples to the LabVIEW 2014 examples directory. Table 3.1 lists the available examples; further details on each example can be found in Section 4.

When the examples are installed, they can be found at the following location:

C:\Program Files (x86)\National Instruments\LabVIEW 2014\examples\dmLabVIEW-RPi\dmExamples\bcm2835

Example Project Library Function

Description

Blink GPIO Alternately sets an LED on or off.

bcm-Write Multi GPIO Shows how to write to a range of GPIOs simultaneously.

bcm-Write Mask GPIO Another method for writing to a range of GPIOs simultaneously.

bcm-Set Clear Multi GPIO Shows how to set/clear a range of GPIOs simultaneously.

bcm-High Detect GPIO Demonstrates high-level detect, synchronous rising edge detect, and asynchronous rising edge detect for a single pin.

bcm-Low Detect GPIO Demonstrates low-level detect, synchronous falling edge detect, and asynchronous falling edge detect for a single pin.

bcm-High Detect Multi GPIO Demonstrates high-level detect, synchronous rising edge detect, and asynchronous rising edge detect for a range of pins.

bcm-Low Detect Multi GPIO Demonstrates low-level detect, synchronous falling edge detect, and asynchronous falling edge detect for a range of pins.

PWM-1Channel PWM Shows how to enable PWM for a single channel (pin)

PWM-2Channel PWM Shows how to enable PWM for two channels

bcm-High Speed Clock PWM Shows how to set higher frequency signals (up to 4.8MHz) on a PWM pin.

TowerSG92R-Servo PWM Demonstrates how to drive a simple micro-servo using PWM functionality.

bcm-PCF2129AT I2C Shows how to control a single I2C device.

bcm-PmodTMP3+PCF2129AT I2C Shows how driving two I2C devices differs from using a single I2C device.

bcm-MCP3008 SPI Demonstrates basic SPI functionality.

Table 3.1 Example projects available for the LabVIEW BCM2835 Library

Page 29: LabVIEW BCM2835 Library for Raspberry Pi

LabVIEW BCM2835 Library for Raspberry Pi

29/09/2016 Page 29 of 77 Issue 1.1

To install the examples, start by downloading the package "dmlabview_rpi_lib_dmlv_rpi-x.x.x.x.vip" to a suitable location (the VIP version will be different to the one shown below).

Figure 3.1. Download the examples package.

Once downloaded, double-click the package and JKI VIPM should open with it selected. Click Install.

Figure 3.2. Click Install to continue

Page 30: LabVIEW BCM2835 Library for Raspberry Pi

LabVIEW BCM2835 Library for Raspberry Pi

29/09/2016 Page 30 of 77 Issue 1.1

Figure 3.3. The package installs...

Figure 3.4. It should install without any errors

Page 31: LabVIEW BCM2835 Library for Raspberry Pi

LabVIEW BCM2835 Library for Raspberry Pi

29/09/2016 Page 31 of 77 Issue 1.1

Figure 3.5. It should appear in JKI VIPM (version number will be different)

Figure 3.6. Select 'Show Examples' to go to the examples folder

Page 32: LabVIEW BCM2835 Library for Raspberry Pi

LabVIEW BCM2835 Library for Raspberry Pi

29/09/2016 Page 32 of 77 Issue 1.1

Figure 3.7. The examples can be found in LabVIEW 2014\examples\dmLabVIEW-RPi\dmExamples\bcm2835

3.1 Run the PWM-1Channel Project as a Test

A new palette (called "dmLV-RPi") will be available in Addons; however, the examples cannot be run from this palette. Instead, select 'Show Examples' in VIPM to open the examples folder (Figure 3.6), or go directly to the examples using Windows Explorer (Figure 3.7). The directory is:

C:\Program Files (x86)\National Instruments\LabVIEW 2014\examples\dmLabVIEW-RPi\dmExamples\bcm2835

The PWM-1Channel project is a good example to try out if an oscilloscope or LED and resistor is available. The example can be found at "PWM/PWM1-Channel", following the path above. Double-click the project file , and the LabVIEW project should open up (Figure 3.9).

Page 33: LabVIEW BCM2835 Library for Raspberry Pi

LabVIEW BCM2835 Library for Raspberry Pi

29/09/2016 Page 33 of 77 Issue 1.1

Figure 3.8. Run the PWM-1Channel project as a simple test

Page 34: LabVIEW BCM2835 Library for Raspberry Pi

LabVIEW BCM2835 Library for Raspberry Pi

29/09/2016 Page 34 of 77 Issue 1.1

Figure 3.9. The PWM-1Channel project opens up. Right-click on the Raspberry Pi target and select Properties

The IP address of the Raspberry Pi must be changed to match the address of your own Raspberry Pi. Right-click on the Raspberry Pi target and select Properties.

Page 35: LabVIEW BCM2835 Library for Raspberry Pi

LabVIEW BCM2835 Library for Raspberry Pi

29/09/2016 Page 35 of 77 Issue 1.1

Figure 3.10. Change the IP Address

As shown above, change the IP address to suit. Also, change the name to either Raspberry Pi 3 B or Raspberry Pi 2 B as appropriate. (By default in MakerHub-LINX, the Raspberry Pi will be detected as a "2 B", even if a "3 B" is being used.

Page 36: LabVIEW BCM2835 Library for Raspberry Pi

LabVIEW BCM2835 Library for Raspberry Pi

29/09/2016 Page 36 of 77 Issue 1.1

Figure 3.11. Open the Main VI

Next, open up the Main VI. By default, the program is configured to output a 1ms, 0.5 duty-cycle signal on pin 12 (PWM0). To view the signal, connect up an oscilloscope to pin 12 (Figure 3.12) and run the program using the Run arrow as normal.

If you don't have an oscilloscope, then an LED-resistor combination can be used to test the PWM signal; go instead to Section 3.1.1 for more details.

Page 37: LabVIEW BCM2835 Library for Raspberry Pi

LabVIEW BCM2835 Library for Raspberry Pi

29/09/2016 Page 37 of 77 Issue 1.1

Figure 3.12. Connect an oscilloscope to pin 12

Page 38: LabVIEW BCM2835 Library for Raspberry Pi

LabVIEW BCM2835 Library for Raspberry Pi

29/09/2016 Page 38 of 77 Issue 1.1

Figure 3.13. The program is deployed when the Run arrow is clicked

Figure 3.14. Save the changes if prompted

Page 39: LabVIEW BCM2835 Library for Raspberry Pi

LabVIEW BCM2835 Library for Raspberry Pi

29/09/2016 Page 39 of 77 Issue 1.1

Figure 3.15. The program runs. The run-time options can be used to change the signal parameters

Above, we can see that the program is running without errors. The BCM2835 Library Status indicates that the library is opened, and the C-code version number is returned (10050 = ver 1.5). The PWM signal is viewed on an oscilloscope (Figure 3.16). The run-time parameters can also be changed.

Figure 3.16. View the signal on an oscilloscope

Page 40: LabVIEW BCM2835 Library for Raspberry Pi

LabVIEW BCM2835 Library for Raspberry Pi

29/09/2016 Page 40 of 77 Issue 1.1

3.1.1 Run the PWM-1Channel Program using an LED

Figure 3.17. Change the PWM period to 1000000us (1 second)

If an oscilloscope isn't available, an LED-resistor combination can be used to verify that the PWM signal is being output by the RPI. First, change the Initial and Loop PWM Periods to 1000000us i.e. 1 second, see above. The clock divider can also be changed to 512, although this setting does not really matter in this case. Connect a 220ohm resistor and LED to pin 12 as shown in Figure 3.18 and run the program. The LED should turn on and off every 500ms.

Figure 3.18. Connect LED and resistor to pin 12

Page 41: LabVIEW BCM2835 Library for Raspberry Pi

LabVIEW BCM2835 Library for Raspberry Pi

29/09/2016 Page 41 of 77 Issue 1.1

4 Examples

This section gives connection details and information on each example project. Before that, however, a brief description of the common steps in using the BCM2835 library is given, as shown in Figure 4.1. The steps are:

1. Open the MakerHub LINX connection.

2. Open the BCM2835 library using "Init+Version.vi". Abort the program if the library cannot be opened (or provide other suitable error handling).

3. Carry out some configuration, such I2C/SPI/PWM settings, or setting a pin to be an input/output.

4. Carry out run-time functionality in a While Loop (basic example). More advanced users will perhaps have several VIs running in parallel for run-time operation, or will be using much more complex architectures than the simple While Loop shown here.

5. Carry out some clean up when finishing the program, for example clearing GPIOs, or releasing I2C/SPI resources.

6. Close the BCM2835 library using Close.vi.

7. Release the MakerHub LINX resource.

Figure 4.1. Basic, repeatable steps in using the LabVIEW BCM2835 Library

The remainder of this section details each example project. Even if the user does not have the required components to build and run an example, the main aim of the examples is to show the VI's that are required for a particular application. The order of VI's can also be very important; for best results the user should use the VIs in the sequence shown in the examples.

One important point to note is that before running the Main VI in any project, the user will need to change the IP address to that used by their RPi (refer back to Figure 3.9 and Figure 3.10 in the previous section). Also, the user is of course free to change any of the default settings, such as pin assignment, I2C/SPI settings, etc, as desired. Some extra modification of the Main VI's may be required in that case; the level of LabVIEW experience of the user will dictate whether or not they should change an example from the default settings.

Page 42: LabVIEW BCM2835 Library for Raspberry Pi

LabVIEW BCM2835 Library for Raspberry Pi

29/09/2016 Page 42 of 77 Issue 1.1

4.1 Blink (GPIO Example)

The Blink project is a simple example which toggles an LED on and off. Figure 4.2 shows the default connections for the example. Connect a 220ohm resistor and LED in series with Pin 40 (GPIO21) and connect back to the RPI ground. Figure 4.3 shows the main VI front panel; use Ctrl + E to view the block diagram.

Figure 4.2. Default connection for the 'Blink' example

Figure 4.3. 'Blink' front panel

Page 43: LabVIEW BCM2835 Library for Raspberry Pi

LabVIEW BCM2835 Library for Raspberry Pi

29/09/2016 Page 43 of 77 Issue 1.1

4.1.1 VI Documentation

The details from the VI documentation are repeated below (use Ctrl + h to view the documentation of an open VI).

Simple LED Blink example showing basic use of BCM2835 GPIO functions. The user should connect an LED and 220ohm resistor to the desired output pin, and select the pin on the front panel. Two methods are given to toggle the GPIO: (1) Write 0/1 to the GPIO, and (2) Set or clear the GPIO.

The following steps are carried out in the VI:

1. The LINX connection is opened.

2. The BCM2835 library is opened, and the version read back. If there is an error at this point, the VI will abort.

3. The output pin/GPIO is configured to be an output.

4. The GPIO is set to 0/1 in alternate iterations of the While Loop.

5. The GPIO level is read back.

6. The BCM2835 Milliseconds Delay function is used to control the loop timing.

7. When the loop exits, the GPIO is cleared.

8. The BCM2835 library is closed.

9. The LINX resource is released.

Page 44: LabVIEW BCM2835 Library for Raspberry Pi

LabVIEW BCM2835 Library for Raspberry Pi

29/09/2016 Page 44 of 77 Issue 1.1

4.2 Set-Clear Multi (GPIO Example)

The 'Set-Clear Multi' project demonstrates how to set or clear multiple GPIOs at once. Figure 4.4 shows the default connections, where a logic analyzer is used to monitor pins 33, 35 and 37. The user could instead use LEDs (plus 220 ohm series resistors) to monitor the GPIO states. Figure 4.5 shows the main VI front panel; use Ctrl + E to view the block diagram.

Figure 4.4. Default connections for the 'Set-Clear Multi' example

Figure 4.5. 'Set-Clear Multi' front panel

Page 45: LabVIEW BCM2835 Library for Raspberry Pi

LabVIEW BCM2835 Library for Raspberry Pi

29/09/2016 Page 45 of 77 Issue 1.1

4.2.1 VI Documentation

The details from the VI documentation (Ctrl + h) are repeated below.

This example shows how to use the BCM2835 GPIO Set/Clear Multi function, where a range of pins can be simultaneously set or cleared. Three RPi pins are used in this case (33, 35, 37), and they can be monitored using LEDs, a logic analyzer, or even simply using the built-in GPIO Level function as shown in the example. (The Level function works whether the GPIO is an input or output).

This is a very simple example. First, the pins must be configured as outputs. Then they can all be set or cleared at the same time using the Set/Clear control. Finally, when the loop ends, the Clear function is again used to set the GPIO's back to low.

The following steps are carried out in the VI:

1. The LINX connection is opened.

2. The BCM2835 library is opened, and the version read back. If there is an error at this point, the VI will abort.

3. The output pins/GPIO are configured to be outputs.

4. Inside the loop, the pins can be set or cleared simultaneously.

5. The GPIO level is read back for each pin.

6. When the loop exits, all GPIO's are cleared.

7. The BCM2835 library is closed.

8. The LINX resource is released.

Page 46: LabVIEW BCM2835 Library for Raspberry Pi

LabVIEW BCM2835 Library for Raspberry Pi

29/09/2016 Page 46 of 77 Issue 1.1

4.3 Write Multi (GPIO Example)

The 'Write Multi' project demonstrates how to set or clear multiple GPIOs at once. It is more flexible than the 'Set-Clear Multi' method, as individual pins can be selected. Figure 4.6 shows the default connections, where a logic analyzer is used to monitor pins 33, 35 and 37. The user could instead use LEDs (plus 220 ohm series resistors) to monitor the GPIO states. Figure 4.7 shows the main VI front panel; use Ctrl + E to view the block diagram.

Figure 4.6. Default connection for the 'Write Multi' example

Figure 4.7. 'Write Multi' front panel

Page 47: LabVIEW BCM2835 Library for Raspberry Pi

LabVIEW BCM2835 Library for Raspberry Pi

29/09/2016 Page 47 of 77 Issue 1.1

4.3.1 VI Documentation

The details from the VI documentation (Ctrl + h) are repeated below.

This example shows how to use the BCM2835 GPIO Write Multi function. Three RPi pins are used in this case (33, 35, 37), and they can be monitored using LEDs, a logic analyzer, or even simply using the built-in GPIO Level function as shown in the example. (The Level function works whether the GPIO is an input or output).

First, the pins must be configured as outputs. Then they can be individually selected at run-time, and the 'Set State' value will be applied to the GPIO. If a pin is not selected, then the state setting will be ignored. Finally, when the loop ends, the Clear Multi VI is used to set the GPIO's back to low.

The following steps are carried out in the VI:

1. The LINX connection is opened.

2. The BCM2835 library is opened, and the version read back. If there is an error at this point, the VI will abort.

3. The output pins/GPIO are configured to be outputs.

4. Inside the loop, pins can be selected and the Set State value will be applied to them.

5. The GPIO level is read back for each pin.

6. When the loop exits, all GPIO's are cleared.

7. The BCM2835 library is closed.

8. The LINX resource is released.

Page 48: LabVIEW BCM2835 Library for Raspberry Pi

LabVIEW BCM2835 Library for Raspberry Pi

29/09/2016 Page 48 of 77 Issue 1.1

4.4 Write Mask (GPIO Example)

Like 'Write Multi', the 'Write Mask' project demonstrates how to set or clear multiple GPIOs at once. However, set GPIOs must be explicitly cleared, which makes it more cumbersome to use compared to 'Write Multi'. Figure 4.8 shows the default connections, where a logic analyzer is used to monitor pins 33, 35 and 37. The user could instead use LEDs (plus 220 ohm series resistors) to monitor the GPIO states. Figure 4.9 shows the main VI front panel; use Ctrl + E to view the block diagram.

Figure 4.8. Default connection for the 'Write Mask' example

Figure 4.9. 'Write Mask' front panel

Page 49: LabVIEW BCM2835 Library for Raspberry Pi

LabVIEW BCM2835 Library for Raspberry Pi

29/09/2016 Page 49 of 77 Issue 1.1

4.4.1 VI Documentation

The details from the VI documentation (Ctrl + h) are repeated below.

Example showing how to use the BCM2835 GPIO Write Mask function. Three RPi pins are used in this case (33, 35, 37), and they can be monitored using LEDs or a logic analyzer.

[Note: The GPIO Write Multi function is preferred over this function, as it is easier to use.]

First, the pins must be configured as outputs. Then the level can be set at run-time. However, once set, the Clear Multi VI must be used to clear the pin(s); they could also be cleared individually using the "Set-Clear GPIO.vi". Note also in the example that the GPIO may be set again in the next iteration of the loop, and so a 1 second delay is used in the Clear Multi case structure so that LEDs, for example, will show that the GPIO's have been cleared. Finally, when the loop ends, the Clear Multi VI is again used to set the GPIO's back to low.

The following steps are carried out in the VI:

1. The LINX connection is opened.

2. The BCM2835 library is opened, and the version read back. If there is an error at this point, the VI will abort.

3. The output pins/GPIO are configured to be outputs.

4. Inside the loop, the pins can be set high.

5. The GPIO level is read back for each pin.

6. GPIO's can be cleared using "Clear Multi.vi".

7. When the loop exits, all GPIO's are cleared.

8. The BCM2835 library is closed.

9. The LINX resource is released.

Page 50: LabVIEW BCM2835 Library for Raspberry Pi

LabVIEW BCM2835 Library for Raspberry Pi

29/09/2016 Page 50 of 77 Issue 1.1

4.5 High Detect (GPIO Example)

The 'High Detect' project demonstrates how to use high-level or rising-edge event detection on the RPi. The Event Detect Mode can be set to High-level Detect, Synchronous Rising Edge, or Asynchronous Rising Edge. Figure 4.10 shows the default connections for the example, where a pattern generator or switch connects to Pin 33 (GPIO13) on the RPi GPIO header. Figure 4.11 shows the main VI front panel.

Figure 4.10. Default connection for the 'High Detect' example

Figure 4.11. 'High Detect' front panel

Page 51: LabVIEW BCM2835 Library for Raspberry Pi

LabVIEW BCM2835 Library for Raspberry Pi

29/09/2016 Page 51 of 77 Issue 1.1

4.5.1 VI Documentation

The details from the VI documentation (Ctrl + h) are repeated below.

Example showing how to use BCM2835 Event Detection for a single pin. Pin 33 GPIO 13 is used in the example. The VI can be set up so that the pin detects a high level, synchronous rising edge or asynchronous rising edge. The pin to be used is first configured to be an input with internal pull-down resistor. Then the detection mode is set. Inside the loop, a check is made for the configured event, and if an event has been detected it is cleared. The GPIO level is then checked, but depending on how you trigger the event this might always be low. For example, if a pattern generator is used with a small pulse to trigger events, then the level will likely always be low by the time it is read.

When the loop ends, the Clear Event Detect VI should be used to clear the event detect mode on the pin. Note that this VI has a completely different function than the Clear Event Status VI used in the loop i.e. the two VI's should not be confused.

In testing the functionality, the RPi pin should be normally low, for example using a pattern generator or simple switch circuit. If not, the High Level Detect event will be triggered on every iteration of the loop.

The following steps are carried out in the VI:

1. The LINX connection is opened.

2. The BCM2835 library is opened, and the version read back. If there is an error at this point, the VI will abort.

3. The input pin/GPIO is configured to be an input with internal pull-down.

4. The input pin/GPIO is configured with the specified Event Detect Mode.

5. Inside the loop, a check is made for the configured event.

6. If an event is detected, it is cleared.

7. The GPIO level is read back for the pin, but it may always be low, as explained above.

8. When the loop exits, the event detect mode for the pin is cleared.

9. The BCM2835 library is closed.

10. The LINX resource is released.

Page 52: LabVIEW BCM2835 Library for Raspberry Pi

LabVIEW BCM2835 Library for Raspberry Pi

29/09/2016 Page 52 of 77 Issue 1.1

4.6 Low Detect (GPIO Example)

The 'Low Detect' project demonstrates how to use low-level or falling-edge event detection on the RPi. The Event Detect Mode can be set to High-level Detect, Synchronous Falling Edge, or Asynchronous Falling Edge. Figure 4.12 shows the default connections for the example, where a pattern generator or switch connects to Pin 33 (GPIO13) on the RPi GPIO header. Figure 4.13 shows the main VI front panel.

Figure 4.12. Default connection for the 'Low Detect' example

Figure 4.13. 'Low Detect' front panel

Page 53: LabVIEW BCM2835 Library for Raspberry Pi

LabVIEW BCM2835 Library for Raspberry Pi

29/09/2016 Page 53 of 77 Issue 1.1

4.6.1 VI Documentation

The details from the VI documentation (Ctrl + h) are repeated below.

Example showing how to use BCM2835 Event Detection for a single pin. Pin 33 GPIO 13 is used in the example. The VI can be set up so that the pin detects a low level, synchronous falling edge or asynchronous falling edge. The pin to be used is first configured to be an input with internal pull-up resistor. Then the detection mode is set. Inside the loop, a check is made for the configured event, and if an event has been detected it is cleared. The GPIO level is then checked, but depending on how you trigger the event this might always be high. For example, if a pattern generator is used with a small pulse to trigger events, then the level will likely always be high by the time it is read.

When the loop ends, the Clear Event Detect VI should be used to clear the event detect mode on the pin. Note that this VI has a completely different function than the Clear Event Status VI used in the loop i.e. the two VI's should not be confused.

In testing the functionality, the RPi pin should be normally high, for example using a pattern generator or simple switch circuit. If not, the Low Level Detect event will be triggered on every iteration of the loop.

The following steps are carried out in the VI:

1. The LINX connection is opened.

2. The BCM2835 library is opened, and the version read back. If there is an error at this point, the VI will abort.

3. The input pin/GPIO is configured to be an input with internal pull-up.

4. The input pin/GPIO is configured with the specified Event Detect Mode.

5. Inside the loop, a check is made for the configured event.

6. If an event is detected, it is cleared.

7. The GPIO level is read back for the pin, but it may always be high, as explained above.

8. When the loop exits, the event detect mode for the pin is cleared.

9. The BCM2835 library is closed.

10. The LINX resource is released.

Page 54: LabVIEW BCM2835 Library for Raspberry Pi

LabVIEW BCM2835 Library for Raspberry Pi

29/09/2016 Page 54 of 77 Issue 1.1

4.7 High Detect Multi (GPIO Example)

The 'High Detect Multi' project demonstrates how to use high-level or rising-edge event detection on multiple RPi pins. The Event Detect Mode can be set to High-level Detect, Synchronous Rising Edge, or Asynchronous Rising Edge. Figure 4.14 shows the default connections for the example, where a pattern generator or switches connect to Pins 33, 35 and 37 on the RPi GPIO header. Figure 4.15 shows the main VI front panel.

Figure 4.14. Default connection for the 'High Detect Multi' example

Figure 4.15. 'High Detect Multi' front panel

Page 55: LabVIEW BCM2835 Library for Raspberry Pi

LabVIEW BCM2835 Library for Raspberry Pi

29/09/2016 Page 55 of 77 Issue 1.1

4.7.1 VI Documentation

The details from the VI documentation (Ctrl + h) are repeated below.

Example showing how to use BCM2835 Event Detection for multiple pins. Pin 33 GPIO 13, pin 35 GPIO 19, and pin 37 GPIO 26 are used in the example. The VI can be set up so that the pins detects a high level, synchronous rising edge or asynchronous rising edge. The pins are first configured to be inputs with internal pull-down resistors. Then the detection mode is set. Inside the loop, a check is made for any configured events, and if an event has been detected it is cleared. The GPIO level is then checked, but depending on how you trigger the event this might always be low. For example, if a pattern generator is used with a small pulse to trigger events, then the level will likely always be low by the time it is read.

When the loop ends, the Clear Event Detect VI should be used to clear the event detect mode on the pins. Note that this VI has a completely different function than the Clear Event Status VI used in the loop i.e. the two VI's should not be confused.

In testing the functionality, the RPi pins should be normally low, for example using a pattern generator or simple switch circuit. If not, the High Level Detect event will be triggered on every iteration of the loop.

The following steps are carried out in the VI:

1. The LINX connection is opened.

2. The BCM2835 library is opened, and the version read back. If there is an error at this point, the VI will abort.

3. The input pins/GPIO's are configured to be inputs with internal pull-down resistor.

4. The input pin/GPIO is configured with the specified Event Detect Mode.

5. Inside the loop, a check is made for the configured events.

6. If any event is detected, it is cleared.

7. The GPIO level is read back for the pin, but it may always be low, as explained above.

8. When the loop exits, the event detect mode for the pins are cleared.

9. The BCM2835 library is closed.

10. The LINX resource is released.

Page 56: LabVIEW BCM2835 Library for Raspberry Pi

LabVIEW BCM2835 Library for Raspberry Pi

29/09/2016 Page 56 of 77 Issue 1.1

4.8 Low Detect Multi (GPIO Example)

The 'Low Detect Multi' project demonstrates how to use low-level or falling-edge event detection on multiple RPi pins. The Event Detect Mode can be set to Low-level Detect, Synchronous Falling Edge, or Asynchronous Falling Edge. Figure 4.16 shows the default connections for the example, where a pattern generator or switches connect to Pins 33, 35 and 37 on the RPi GPIO header. Figure 4.17 shows the main VI front panel.

Figure 4.16. Default connection for 'Low Detect Multi' example

Figure 4.17. 'Low Detect Multi' front panel

Page 57: LabVIEW BCM2835 Library for Raspberry Pi

LabVIEW BCM2835 Library for Raspberry Pi

29/09/2016 Page 57 of 77 Issue 1.1

4.8.1 VI Documentation

The details from the VI documentation (Ctrl + h) are repeated below.

Example showing how to use BCM2835 Event Detection for multiple pins. Pin 33 GPIO 13, pin 35 GPIO 19, and pin 37 GPIO 26 are used in the example. The VI can be set up so that the pins detect a low level, synchronous falling edge or asynchronous falling edge. The pins are first configured to be inputs with internal pull-up resistors. Then the detection mode is set. Inside the loop, a check is made for any configured events, and if an event has been detected it is cleared. The GPIO level is then checked, but depending on how you trigger the event this might always be high. For example, if a pattern generator is used with a small pulse to trigger events, then the level will likely always be high by the time it is read.

When the loop ends, the Clear Event Detect VI should be used to clear the event detect mode on the pins. Note that this VI has a completely different function to the Clear Event Status VI used in the loop i.e. the two VI's should not be confused.

In testing the functionality, the RPi pins should be normally high, for example using a pattern generator or simple switch circuit. If not, the Low Level Detect event will be triggered on every iteration of the loop.

The following steps are carried out in the VI:

1. The LINX connection is opened.

2. The BCM2835 library is opened, and the version read back. If there is an error at this point, the VI will abort.

3. The input pins/GPIO's are configured to be inputs with internal pull-up resistor.

4. The input pin/GPIO is configured with the specified Event Detect Mode.

5. Inside the loop, a check is made for the configured events.

6. If any event is detected, it is cleared.

7. The GPIO level is read back for the pin, but it may always be high, as explained above.

8. When the loop exits, the event detect mode for the pins are cleared.

9. The BCM2835 library is closed.

10. The LINX resource is released.

Page 58: LabVIEW BCM2835 Library for Raspberry Pi

LabVIEW BCM2835 Library for Raspberry Pi

29/09/2016 Page 58 of 77 Issue 1.1

4.9 PWM 1-Channel (PWM Example)

The PWM-1Channel project demonstrates how to enable PWM operation for a single PWM channel on the RPi. The default configuration is to enable PWM0 and output it on pin12/GPIO 18, as shown in Figure 4.18. Note that the signal also appears on Pin 32. The default timing parameters are 1ms with a 50% duty-cycle. Figure 4.19 shows the main VI front panel. Refer also to Section 5 for more details on clock frequencies available using the PWM functionality.

Figure 4.18. Default connection for the 'PWM 1-Channel' example

Figure 4.19. 'PWM 1-Channel' front panel

Page 59: LabVIEW BCM2835 Library for Raspberry Pi

LabVIEW BCM2835 Library for Raspberry Pi

29/09/2016 Page 59 of 77 Issue 1.1

4.9.1 VI Documentation

The details from the VI documentation (Ctrl + h) are repeated below.

Example showing how to use the BCM2835 PWM functionality. On the RPi 3, two PWM channels are available (0 and 1), and each channel appears on two RPi pins. The PWM pin/GPIO mapping is:

PWM0: Pin 12/GPIO 18

PWM0: Pin 32/GPIO 12

PWM1: Pin 33/GPIO 13

PWM1: Pin 35/GPIO 19

Note that if a channel is enabled, the PWM output automatically appears on both relevant pins e.g. if you set up a PWM0 signal on Pin 12, it will also appear on pin 32. This means that four PWM signals can be generated, with two different duty-cycles and periods on each channel. (Example: you can have a 1kHz signal with 50% duty-cycle on pins 12 and 32, and a 10kHz signal with 25% duty-cycle on pins 33 and 35).

In this example, only one PWM channel is enabled (giving identical outputs on two pins, as just described).

The following steps are carried out in the VI (users should follow this flow, particularly the set-up steps, for reliable operation):

1. The LINX connection is opened.

2. The BCM2835 library is opened, and the version read back. If there is an error at this point, the VI will abort.

3. The PWM Clock Divider is set, effectively setting the PWM resolution. This VI should always be called first. Note that if it is called during PWM operation, the results can be very erratic.

4. The PWM pin is set next.

5. The initial period and duty-cycle is set next.

6. The PWM mode is set (Mark-space) and the PWM output is also enabled with this VI. Note that the 'Balanced' mode of operation has not been tested.

7. During run-time (i.e. in the While Loop), the period and duty-cycle can be changed, and the PWM output can be turned on or off.

8. When the loop exits, the PWM output is turned off.

9. The BCM2835 library is closed.

10. The LINX resource is released.

One final important point to note is that the PWM functionality on the RPi 3 (and probably RPi 2 as well) drives the audio jack J7. If you have any audio SW and/or drivers driving J7, then it is unlikely that you will be able to use the PWM functionality for other purposes.

Page 60: LabVIEW BCM2835 Library for Raspberry Pi

LabVIEW BCM2835 Library for Raspberry Pi

29/09/2016 Page 60 of 77 Issue 1.1

4.10 PWM 2-Channel (PWM Example)

The PWM-1Channel project demonstrates how to enable PWM operation for both PWM channels on the RPi. The default configuration is to enable PWM0 on pin12/GPIO 18, and PWM1 on pin 33/GPIO 13 as shown in Figure 4.20. Note that the signals also appears on pin 32 (PWM0) and pin 19 (PWM1). The default timing parameters are 1ms with a 50% duty-cycle for PWM0, and 0.5ms with a 25% duty-cycle for PWM1. Figure 4.21 shows the main VI front panel. Refer also to Section 5 for more details on clock frequencies available using the PWM functionality.

Figure 4.20. Default connection for the 'PWM 2-Channel' example

Figure 4.21. 'PWM 2-Channel' front panel

Page 61: LabVIEW BCM2835 Library for Raspberry Pi

LabVIEW BCM2835 Library for Raspberry Pi

29/09/2016 Page 61 of 77 Issue 1.1

4.10.1 VI Documentation

The details from the VI documentation (Ctrl + h) are repeated below.

Example showing how to use the BCM2835 PWM functionality to enable PWM0 and PWM1. Each channel appears on two RPi pins. The PWM pin/GPIO mapping is:

PWM0: Pin 12/GPIO 18

PWM0: Pin 32/GPIO 12

PWM1: Pin 33/GPIO 13

PWM1: Pin 35/GPIO 19

Note that if a channel is enabled, the PWM output automatically appears on both relevant pins e.g. if you set up a PWM0 signal on Pin 12, it will also appear on pin 32. This means that four PWM signals can be generated, with two different duty-cycles and periods on each channel. (Example: you can have a 1kHz signal with 50% duty-cycle on pins 12 and 32, and a 2kHz signal with 25% duty-cycle on pins 33 and 35; this is the default in this example).

The following steps are carried out in the VI:

1. The LINX connection is opened.

2. The BCM2835 library is opened, and the version read back. If there is an error at this point, the VI will abort.

3. The PWM Clock Divider is set, effectively setting the PWM resolution. This VI should always be called first. Note that if it is called during PWM operation, the results can be very erratic.

4. The PWM pins are set next.

5. The initial period and duty-cycle is set next; both PWM signals start with the same settings in the example.

6. The PWM mode is set (Mark-space) and the PWM outputs are also enabled with this VI. Note that the 'Balanced' mode of operation has not been tested.

7. During run-time (i.e. in the While Loop), the period and duty-cycle of each channel can be changed, and the PWM outputs can be turned on or off.

8. When the loop exits, the PWM outputs are turned off.

9. The BCM2835 library is closed.

10. The LINX resource is released.

One final important point to note is that the PWM functionality on the RPi 3 (and probably RPi 2 as well) drives the audio jack J7. If you have any audio SW and/or drivers driving J7, then it is unlikely that you will be able to use the PWM functionality for other purposes.

Page 62: LabVIEW BCM2835 Library for Raspberry Pi

LabVIEW BCM2835 Library for Raspberry Pi

29/09/2016 Page 62 of 77 Issue 1.1

4.11 High-Speed Clock (PWM Example)

The 'High-Speed Clock' project is really just a repeat of the 'PWM 1-Channel' running at higher frequencies. The default configuration enables PWM0 and outputs it on pin12/GPIO 18, as shown in Figure 4.22. Note that the signal also appears on Pin 32. The default timing parameters are 4.8MHz with a 50% duty-cycle. Figure 4.23 shows the main VI front panel. Refer also to Section 5 for more details on clock frequencies available using the PWM functionality.

Figure 4.22. Default connection for the 'High-Speed Clock' example

Figure 4.23. 'High-Speed Clock' front panel

Page 63: LabVIEW BCM2835 Library for Raspberry Pi

LabVIEW BCM2835 Library for Raspberry Pi

29/09/2016 Page 63 of 77 Issue 1.1

4.11.1 VI Documentation

The details from the VI documentation (Ctrl + h) are repeated below.

Example showing how to use the BCM2835 PWM functionality to output a high-speed clock. The PWM pin/GPIO mapping is:

PWM0: Pin 12/GPIO 18

PWM0: Pin 32/GPIO 12

PWM1: Pin 33/GPIO 13

PWM1: Pin 35/GPIO 19

The "PWM Clock.vi" function is important in setting as high a clock speed as possible. It sets the maximum possible frequency (fmax) for the PWM, using the formula "fmax (MHz) = 19.2/(2*N)", where N is the PWM Clock Divider input to the VI. Allowed clock divider values are: 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048. This gives the following possible max frequencies and associated periods:

Clock Divider (N)

Max Freq. Period Resolution

2 4.8MHz 208.3ns 104.16ns

4 2.4MHz 416.6ns 208.3ns

8 1.2MHz 833.3ns 416.6ns

16 600kHz 1.667us 833.3ns

32 300kHz 3.333us 1.667us

64 150kHz 6.667us 3.333us

128 75kHz 13.33us 6.667us

256 37.5kHz 26.67us 13.33us

512 18.75kHz 53.33us 26.67us

1024 9.375kHz 106.6us 53.33us

2048 4.6875kHz 213.3us 106.6us

Table 4.1 Maximum frequencies available for each PWM clock divider setting, N

Other (lower) clock frequencies are then available for all divider settings. The "PWM Clock" VI should be called first when setting up the RPi for PWM operation. Note that changing the input clock divider during PWM operation will result in unpredictable behavior. Thus it should be set just once, when configuring the RPi for PWM operation, as stated. (Alternatively, the PWM could be switched off using "PWM Mode", and the clock reconfigured).

Note also that the above timings are valid for an unmodified, non-over-clocked RPi, where the base clock is 19.2MHz. Performing timing-related hardware or software modifications on your RPi may change the timing.

The general flow is detailed next (users should follow this flow for reliable operation).

1. The LINX connection is opened.

2. The BCM2835 library is opened, and the version read back. If there is an error at this point, users should abort their program, or provide other relevant error handling.

3. The PWM Clock VI is used to set the PWM clock divider and max frequency, as detailed above.

4. The PWM pin is set.

5. The initial PWM timing is set.

Page 64: LabVIEW BCM2835 Library for Raspberry Pi

LabVIEW BCM2835 Library for Raspberry Pi

29/09/2016 Page 64 of 77 Issue 1.1

6. Inside the while loop, the PWM timing can be changed and the output switched on or off.

7. When the loop exits, the PWM output is disabled.

8. The BCM2835 library is closed.

9. The LINX resource is released.

Page 65: LabVIEW BCM2835 Library for Raspberry Pi

LabVIEW BCM2835 Library for Raspberry Pi

29/09/2016 Page 65 of 77 Issue 1.1

4.12 TowerSG92R-Servo (PWM Example)

This example shows how to use the PWM signal to drive a micro servo. The Tower Pro SG92R is used in the project. This has a default pulse period of 20ms and pulse widths of 0.5ms (for 0 degrees) and 2.4ms (for 180 degrees). The RPi should not be used to supply the 5V power to the servo; instead an external 5V supply with a 1A current capacity should be used, as shown in Figure 4.24. The signal wire (yellow on the tested servo) connects to the RPi PWM output. Figure 4.25 shows the main VI front panel. Refer also to Section 5 for more details on clock frequencies available using the PWM functionality.

Figure 4.24. Default connection for the 'Tower Pro SG92R-Servo' example

Figure 4.25. TowerSG92R-Servo front panel

Page 66: LabVIEW BCM2835 Library for Raspberry Pi

LabVIEW BCM2835 Library for Raspberry Pi

29/09/2016 Page 66 of 77 Issue 1.1

4.12.1 VI Documentation

Example showing how to use the BCM2835 PWM functionality to drive a micro-servo. The Tower Pro SG92R is used in the example. This servo can rotate between 0 degrees and 180 degrees, with corresponding pulse widths of 0.5ms to 2.4ms. The servo pulse period is 20ms. PWM0 (pin 12, GPIO 18) is used by default in the example, but the other PWM pins could also be used.

To power the servo, an external 5V supply should be used (generally on the SG92R servo, red = 5V, brown = GND). The GND connection must also connect to the RPI GND. Finally, the relevant PWM pin connects to the yellow wire to control the servo. (These connections are correct on the servo used by the author; check your own servo specification for connection information).

The "Set Timing Parameters" VI requires an input in terms of duty-cycle to control the PWM signal. The conversion is carried out as follows:

1. Minimum setting = 0 degrees: Pulse period = 20ms and pulse width = 0.5ms. Duty-cycle = 0.5/20 = 0.025.

2. Maximum setting = 180 degrees: Pulse period = 20ms and pulse width = 2.4ms. Duty-cycle = 2.4/20 = 0.12.

3. Use 'y = mx + c', where y = duty-cycle, x = servo position in degrees and c = zero-intercept.

m = (0.12-0.025)/(180-0) = 0.00052778 /degree

c = duty-cycle zero-intercept = 0.025

y = duty-cycle = (0.0052778*servo position in degrees) + 0.025

One thing to be aware of is that the servo timings of 0.5ms and 2.4ms are the nominal values and will likely differ slightly for different servos, even of the same type (i.e. SG92R). If possible, use an oscilloscope with your servo to determine the max and min timings, and change the calculations above as necessary.

The Servo Position controls have been configured to allow a minimum input of 0 (degrees) and a maximum input of 180 (degrees), with an increment of 1 (degree). This can be changed by right-clicking on the controls and selecting 'Data Entry'. The resolution of the PWM signal can also be changed by stopping the VI and changing the PWM Clock Divider control.

The following steps are carried out in the VI (users should follow this flow, particularly the set-up steps, for reliable operation):

1. The LINX connection is opened.

2. The BCM2835 library is opened, and the version read back. If there is an error at this point, the VI will abort.

3. The PWM Clock Divider is set, effectively setting the PWM resolution. This VI should always be called first. Note that if it is called during PWM operation, the results can be very erratic.

4. The PWM pin is set next.

5. The initial pulse period and duty-cycle is set next. In the example, the default is to set the servo position to 90 degrees.

6. The PWM mode is set (Mark-space) and the PWM output is also enabled with this VI. Note that the 'Balanced' mode of operation has not been tested.

7. During run-time (i.e. in the While Loop), the servo position can be changed.

8. When the loop exits, the PWM output is turned off.

9. The BCM2835 library is closed.

10. The LINX resource is released.

Page 67: LabVIEW BCM2835 Library for Raspberry Pi

LabVIEW BCM2835 Library for Raspberry Pi

29/09/2016 Page 67 of 77 Issue 1.1

4.13 PCF2129AT (I2C Example)

The PCF2129AT project demonstrates how to use the BCM2835 I2C functionality to control a single I2C device, in this case the RasClock real-time clock, which uses the NXP PCF2129AT RTC. Figure 4.26 shows the connections for the example. Figure 4.27 shows the main VI front panel.

Figure 4.26. Default connection for the 'PCF2129AT' example

Page 68: LabVIEW BCM2835 Library for Raspberry Pi

LabVIEW BCM2835 Library for Raspberry Pi

29/09/2016 Page 68 of 77 Issue 1.1

Figure 4.27. 'PCF2129AT' Main VI front panel

4.13.1 VI Documentation

The details from the VI documentation (Ctrl + h) are repeated below.

Example showing the general flow in using the I2C functionality of the BCM2835 library. The example uses the RasClock timer module, which uses the NXP PCF2129AT Real-time clock.

The general flow in using the I2C functionality is detailed next (users should follow this flow for reliable operation):

1. The LINX connection is opened.

2. The BCM2835 library is opened, and the version read back. If there is an error at this point, users should abort their program, or provide other relevant error handling.

3. The BCM2835 I2C functionality is enabled (I2C Open.vi), and the I2C slave address and clock speed is set using "I2C Configure.vi". If there is only one I2C device in the system, then this configuration VI needs to be called only once. If using more than one device, the configuration VI needs to be used every time the user wants to access another module, in order to update the slave address and I2C speed. See the example "PmodTMP3+PCF2129AT'lvproj" for more details. In terms of I2C clock speed, five settings are provided: 100kHz, 400kHz, 1MHz, 1.666MHz, and 1.689MHz (max supported). Check your I2C device datasheet for details on supported clock speeds.

Page 69: LabVIEW BCM2835 Library for Raspberry Pi

LabVIEW BCM2835 Library for Raspberry Pi

29/09/2016 Page 69 of 77 Issue 1.1

4. Once I2C Open and I2C Configure is called, the I2C device can be accessed/controlled via I2C. In this example, the following takes place:

(a) If 'the Set Time' option is selected, the PCF2129AT time will be set.

(b) Inside the While loop, options are available to read and write data to/from the device, Also the time is read back.

5. When the loop exits, I2C operation is ended (I2C Close).

6. The BCM2835 library is closed.

7. The LINX resource is released.

Page 70: LabVIEW BCM2835 Library for Raspberry Pi

LabVIEW BCM2835 Library for Raspberry Pi

29/09/2016 Page 70 of 77 Issue 1.1

4.14 PmodTMP3+PCF2129AT (I2C Example)

The 'PmodTMP3+PCF2129AT' project demonstrates how to use the BCM2835 I2C functionality to control more than one I2C device. Two devices are used in the example: the RasClock real-time clock, which uses the NXP PCF2129AT RTC, and the PmodTMP3 temperature sensor. Figure 4.28 shows the connections for the example. Figure 4.29 shows the main VI front panel.

Figure 4.28. Default connection for PmodTMP3+PCF2129AT example

Page 71: LabVIEW BCM2835 Library for Raspberry Pi

LabVIEW BCM2835 Library for Raspberry Pi

29/09/2016 Page 71 of 77 Issue 1.1

Figure 4.29. PmodTMP3+PCF2129AT front panel

4.14.1 VI Documentation

The details from the VI documentation (Ctrl + h) are repeated below.

Example showing the general flow in using the I2C functionality of the BCM2835 library, where more than one I2C devices is used in the system. The example uses the RasClock timer module, which uses the NXP PCF2129AT Real-time clock, and the PmodTMP3 temperature sensor module.

The general flow is detailed next (users should follow this flow for reliable operation). The main difference between using one and more than one I2C device is that "I2C Configure.vi" must be used every time the user wants to access another device.

1. The LINX connection is opened.

2. The BCM2835 library is opened, and the version read back. If there is an error at this point, users should abort their program, or provide other relevant error handling.

3. The BCM2835 I2C functionality is enabled (I2C Open.vi).

4. In this example, the PmodTMP3 is configured for use.

5. Also specific to this example, in the While loop the following takes place:

(a) I2C Configure is called to set access to the PmodTMP3 device. The resolution is set, and the temperature is read back.

Page 72: LabVIEW BCM2835 Library for Raspberry Pi

LabVIEW BCM2835 Library for Raspberry Pi

29/09/2016 Page 72 of 77 Issue 1.1

(b) I2C Configure is called to set access to the PCF2129AT RTC, and the time is read back.

6. When the loop exits, I2C operation is ended (I2C Close).

7. The BCM2835 library is closed.

8. The LINX resource is released.

Page 73: LabVIEW BCM2835 Library for Raspberry Pi

LabVIEW BCM2835 Library for Raspberry Pi

29/09/2016 Page 73 of 77 Issue 1.1

4.15 MCP3008 (SPI Example)

The BCM2835 SPI functionality is demonstrated in this example, where an MCP3008 ADC is connected to the RPI. Figure 4.30 shows the default connections, where an analog signal is connected to the ADC in differential mode. A suitable DC source should be used to supply the analog stimulus to the ADC; the author used the Analog Out functionality of an NI USB-6289 DAQ, but a simple sensor like the TMP36 temperature sensor could also be used (that sensor would give a voltage of between 700mV and 800mV at normal ambient temperature). Figure 4.31 shows the Main VI front panel.

Figure 4.30. Default connection for the 'MCP3008' example

Page 74: LabVIEW BCM2835 Library for Raspberry Pi

LabVIEW BCM2835 Library for Raspberry Pi

29/09/2016 Page 74 of 77 Issue 1.1

Figure 4.31. 'MCP3008' Main VI front panel

4.15.1 VI Documentation

The details from the VI documentation (Ctrl + h) are repeated below.

This simple example shows how to use the MCP3008 ADC with the BCM2835 Library on RPi (tested on RPi 3). The steps in the example are:

1. Open LINX Resource.

2. Initialize the BCM2835 Library and read the library version.

3. Open SPI connection.

4. Configure the SPI parameters. Defaults are:

a. Mode = Mode 0.

b. Chip-select = CS0 (pin 24 on RPi 3 header).

c. CS Polarity = Active Low

d. Clock Divider = 256 => 976.6kHz SPI frequency.

e. Bit order = MSB (default, cannot be changed in BCM2835 library)

4. While Loop which uses the sub-vi 'bcm-MCP3008:Read Voltage.vi' to read the converted voltage. (Read the help for the sub-vi for more details).

5. Ends SPI operation when the While Loop ends.

6. Closes the BCM2835 Library.

7. Closes the LINX connection when the program ends.

Page 75: LabVIEW BCM2835 Library for Raspberry Pi

LabVIEW BCM2835 Library for Raspberry Pi

29/09/2016 Page 75 of 77 Issue 1.1

5 PWM Timing Details

The maximum clock frequency in MHz, fmax, that can be set at a given clock divider, N, is given by the formula:

The period is then given by the standard formula:

The resolution in microseconds for each clock divider setting, N, can be found with the following simple formula:

Table 5.1 shows the maximum frequencies, equivalent periods, and resolutions at each clock divider setting.

Clock Divider (N)

Max Freq. Period Resolution

2 4.8MHz 208.3ns 104.16ns

4 2.4MHz 416.6ns 208.3ns

8 1.2MHz 833.3ns 416.6ns

16 600kHz 1.667us 833.3ns

32 300kHz 3.333us 1.667us

64 150kHz 6.667us 3.333us

128 75kHz 13.33us 6.667us

256 37.5kHz 26.67us 13.33us

512 18.75kHz 53.33us 26.67us

1024 9.375kHz 106.6us 53.33us

2048 4.6875kHz 213.3us 106.6us

Table 5.1 Maximum frequencies available for each PWM clock divider setting, N

Lower frequencies are then obviously available for each divider setting. Tables 5.2 to 5.6 show the clock frequencies and duty-cycles available for N = 2, 4, 8, 16 and 32, obtained by experimentation (Similar tables could be obtained for all other dividers). Also, only the first nine clocks are displayed for each divider, but again this could be expanded with further experimentation. A main point to note from the testing is that at the maximum frequency, only a single duty-cycle of 0.5 is available, with more duty-cycle points becoming available the further away one gets from the maximum frequency.

Page 76: LabVIEW BCM2835 Library for Raspberry Pi

LabVIEW BCM2835 Library for Raspberry Pi

29/09/2016 Page 76 of 77 Issue 1.1

Test Point

Freq. Available Duty-cycles for N = 2

1 4.8MHz 0.5

2 3.6MHz 0.334 0.667

3 2.4MHz 0.25 0.5 0.75

4 1.92MHz 0.2 0.4 0.6 0.8

5 1.6MHz 0.167 0.334 0.5 0.667 0.833

6 1.37MHz 0.143 0.286 0.429 0.571 0.714 0.857

7 1.2MHz 0.125 0.25 0.375 0.5 0.625 0.75 0.875

8 1.067MHz 0.111 0.222 0.333 0.444 0.556 0.667 0.778 0.889

9 960kHz 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9

etc etc etc

Table 5.2 Frequencies and Duty-cycles available for N = 2 (first 9 settings)

Test Point

Freq. Available Duty-cycles for N = 4

1 2.4MHz 0.5

2 1.6MHz 0.334 0.667

3 1.2MHz 0.25 0.5 0.75

4 960kHz 0.2 0.4 0.6 0.8

5 800kHz 0.167 0.334 0.5 0.667 0.833

6 686kHz 0.143 0.286 0.429 0.571 0.714 0.857

7 600kHz 0.125 0.25 0.375 0.5 0.625 0.75 0.875

8 560kHz 0.111 0.222 0.333 0.444 0.556 0.667 0.778 0.889

9 480kHz 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9

etc etc etc

Table 5.3 Frequencies and Duty-cycles available for N = 4 (first 9 settings)

Test Point

Freq. Available Duty-cycles for N = 8

1 1.2MHz 0.5

2 800kHz 0.334 0.667

3 600kHz 0.25 0.5 0.75

4 480kHz 0.2 0.4 0.6 0.8

5 400kHz 0.167 0.334 0.5 0.667 0.833

6 343kHz 0.143 0.286 0.429 0.571 0.714 0.857

7 300kHz 0.125 0.25 0.375 0.5 0.625 0.75 0.875

8 267kHz 0.111 0.222 0.333 0.444 0.556 0.667 0.778 0.889

9 240kHz 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9

etc etc etc

Table 5.4 Frequencies and Duty-cycles available for N = 8 (first 9 settings)

Page 77: LabVIEW BCM2835 Library for Raspberry Pi

LabVIEW BCM2835 Library for Raspberry Pi

29/09/2016 Page 77 of 77 Issue 1.1

Test Point

Freq. Available Duty-cycles for N = 16

1 600kHz 0.5

2 400kHz 0.334 0.667

3 300kHz 0.25 0.5 0.75

4 240kHz 0.2 0.4 0.6 0.8

5 200kHz 0.167 0.334 0.5 0.667 0.833

6 171kHz 0.143 0.286 0.429 0.571 0.714 0.857

7 150kHz 0.125 0.25 0.375 0.5 0.625 0.75 0.875

8 133kHz 0.111 0.222 0.333 0.444 0.556 0.667 0.778 0.889

9 120kHz 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9

etc etc etc

Table 5.5 Frequencies and Duty-cycles available for N = 16 (first 9 settings)

Test Point

Freq. Available Duty-cycles for N = 32

1 300kHz 0.5

2 200kHz 0.334 0.667

3 150kHz 0.25 0.5 0.75

4 120kHz 0.2 0.4 0.6 0.8

5 100kHz 0.167 0.334 0.5 0.667 0.833

6 85.7kHz 0.143 0.286 0.429 0.571 0.714 0.857

7 75kHz 0.125 0.25 0.375 0.5 0.625 0.75 0.875

8 66.7kHz 0.111 0.222 0.333 0.444 0.556 0.667 0.778 0.889

9 60kHz 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9

etc etc etc

Table 5.6 Frequencies and Duty-cycles available for N = 32 (first 9 settings)