17
PiXtend Application-Note: PiXtend with CODESYS – Demo Project PiXtend with CODESYS – Demo Project Description of the PiXtend Demo Project Structure Qube Solutions UG (haftungsbeschränkt) Arbachtalstr. 6, 72800 Eningen, GERMANY http://www.qube-solutions.de/ http://www.pixtend.de www.pixtend.de Copyright by Qube Solutions UG (haftungsbeschränkt) 1 / 17 Date 18/08/2016, V1.3

PiXtend Application-Note€¦ · PiXtend Application-Note: PiXtend with CODESYS – Demo Project 1. Introduction This Application Note describes the PiXtend CODESYS Demo Project provided

Embed Size (px)

Citation preview

PiXtend Application-Note: PiXtend with CODESYS – Demo Project

PiXtend with CODESYS – Demo Project

Description of the PiXtend Demo Project Structure

Qube Solutions UG (haftungsbeschränkt)

Arbachtalstr. 6, 72800 Eningen, GERMANY

http://www.qube-solutions.de/

http://www.pixtend.de

www.pixtend.de Copyright by Qube Solutions UG (haftungsbeschränkt) 1 / 17

Date 18/08/2016, V1.3

PiXtend Application-Note: PiXtend with CODESYS – Demo Project

Table of Contents1. Introduction........................................................................................................................3

1.1 General Notes..............................................................................................................31.1.1 Copyright of Text and Pictures:............................................................................31.1.2 Warning................................................................................................................31.1.3 Applications for PiXtend.......................................................................................4

1.2 Disclaimer....................................................................................................................42. Prerequisites......................................................................................................................43. Demo Project Structure......................................................................................................5

3.1 SPI Master Configuration.............................................................................................63.2. Task Configuration......................................................................................................73.3 Main program PLC_PRG_CFC...................................................................................83.4 PIXTConfig.................................................................................................................103.5 Visualization...............................................................................................................13

3.4.1 Access to Input/Output Variables.......................................................................133.4.2 Config-Popups....................................................................................................143.4.3 Combo Boxes.....................................................................................................16

www.pixtend.de Copyright by Qube Solutions UG (haftungsbeschränkt) 2 / 17

PiXtend Application-Note: PiXtend with CODESYS – Demo Project

1. IntroductionThis Application Note describes the PiXtend CODESYS DemoProject provided by Qube Solutions UG. The demo project containsprogram code and a web visualization to demonstrate the usage ofmost of the PiXtend CODESYS Features.

This manual will help you to understand the composition and basicstructure of the PiXtend demo project. After reading this application note you will be able tounderstand how the different parts tie together and what is going on in the background.

The demo project can be used as a reference on how to implement relevant features into your own specific CODESYS project.

For your own projects, you can either modify the demo project to your liking and remove unneeded features, or create a blank Project. We recommend to create a blank Standard PiXtend project, as described in Application Note PiXtend with CODESYS – New Project and only implement the features you need for your application.

In this application note we will focus on the description of the demo project's core components and their interaction.

1.1 General Notes

1.1.1 Copyright of Text and Pictures:

Text and pictures marked with "(3S)" belong to 3S-Smart Systems GmbH in Kempten, Germany – www.codesys.comText and pictures marked with "(RPI)" belong to the Raspberry Pi Foundation – www.raspberrypi.orgText and pictures which are not marked, or marked with "(QS)" belong to Qube Solutions UG in Eningen, Germany – www.qube-solutions.de

1.1.2 Warning

PiXtend must not be used in safety critical systems.

Check prior to use the suitability of Raspberry Pi and PiXtend for your application and environment.

www.pixtend.de Copyright by Qube Solutions UG (haftungsbeschränkt) 3 / 17

PiXtend Application-Note: PiXtend with CODESYS – Demo Project

1.1.3 Applications for PiXtend

The PiXtend can be used for private and commercial projects, such as:

• Home Automation, Smart Home

• Evaluation of sub-systems, Proof of Concept, pre-series, series

• Learning and Teaching platform for control systems and automation

• Learning and Teaching platform for microcontroller hard- and software techniques

• HAM-Radio, DIY and Maker Applications

1.2 Disclaimer

Qube Solutions UG and 3S-Smart Software Solutions can not be held responsible for any potential harm or damage to software, hardware, equipment or connected components, caused by the usage of provided software, drivers or hardware products.

2. PrerequisitesThis manual assumes that you have successfully installed all required software components as described in application note PiXtend with CODESYS – Installation

For a better understanding of the underlying concepts we advise you to work through

application note PiXtend with CODESYS – Create Project first.

www.pixtend.de Copyright by Qube Solutions UG (haftungsbeschränkt) 4 / 17

PiXtend Application-Note: PiXtend with CODESYS – Demo Project

3. Demo Project StructureAs the demo project contains a variety of features it can seem a bit complex at first.Therefore we will look at the function of the different components one after the other.

Below we are going to introduce the main components of the demo project

1. SPI Master Configuration

2. Task Configuration

3. Main Program PLC_PRG_CFC

4. PIXTConfig

5. Visualization and VISUConfig

www.pixtend.de Copyright by Qube Solutions UG (haftungsbeschränkt) 5 / 17

PiXtend Application-Note: PiXtend with CODESYS – Demo Project

3.1 SPI Master Configuration

The Demo Project makes use of two SPI Devices. Both SPI Devices are located on the PiXtend board, but accessed via two separate Ports.

SPI Devices are used for the data exchange between the CODESYS Runtime on the Raspberry Pi, and the PiXtend Microcontroller / DAC.

The first SPI Device "PiXtend" allows access to the following features of the PiXtend:

• Digital Inputs

• GPIO Inputs

• Analog Inputs

• Temperature Inputs from DHT11/22 Sensors (via PiXtend GPIOs)

• Humidity Inputs from DHT11/22 Sensors (via PiXtend GPIOs)

• Digital Outputs

• Relay Outputs

• GPIO Outputs

• PWM Outputs

• Control Inputs / Auxiliary Functions

• Status Outputs

The “PiXtend” device always uses SPI-Port “dev/spidev0.0”

www.pixtend.de Copyright by Qube Solutions UG (haftungsbeschränkt) 6 / 17

PiXtend Application-Note: PiXtend with CODESYS – Demo Project

The second SPI device „PiXtend_DAC“ allows access to the two analog outputs. DAC stands for Digital-Analog-Converter.

A more detailed description of the PiXtend Digital-Analog-Converter can be found in Application Note PiXtend with CODESYS – Digital-Analog-Converter

The “PiXtend_DAC” device always uses SPI-Port “dev/spidev0.1”

3.2. Task Configuration

The task Configuration consists of the following 3 Tasks:

The „Main Task“ is called every 100 ms and executes the main program PLC_PRG_CFC.It is also used as the bus-cycle task for the SPI devices „PiXtend“ and „PiXtend_DAC“.

„Other Task“ is called every 300 ms and executes the program POU_RCPlug, which can be used to control 433MHz radio controlled power plugs (if connected) .

„VISU_TASK“ is responsible for the visualization.

Note: If no DHT11/22 sensors are connected and used with PiXtend, the cycle time (bus cycle) can be reduced to 25 ms (for the device "PiXtend"). This can especially be interesting when rapid control (closed loop) is to be realized. Each DHT11/22 sensor extends the minimum cycle time (the "PiXtend" device) to about 20-25 ms.

However, the device "PiXtend_DAC" can operate with a cycle time of 1 ms. It is then advisable but to create a separate task for the DAC.

www.pixtend.de Copyright by Qube Solutions UG (haftungsbeschränkt) 7 / 17

PiXtend Application-Note: PiXtend with CODESYS – Demo Project

3.3 Main program PLC_PRG_CFC

The main program PLC_PRG_CFC is the core component of the demo project and gets called every 100ms by the main task.

The permanent assignment of constant „TRUE“ sets the xEnable Bit.

It also sets the Raspberry Pi GPIO Bit 24 which physically enables the SPI communicationbetween the Raspberry Pi and the PiXtend devices.

Finally it sets the microcontroller Control Bit RequestRunState to activate continuous exchange of process data with the PiXtend microcontroller.

The main program contains an instance of the function block PiXtendConfiguration, which is used to configure the PiXtend hardware parameters.

In contrast to the TestProject (as described in PiXtend with CODESYS – Create Project) we chose a different approach for the DemoProject in order to simplify access to the PiXtend configuration bytes and bits:

Here we are using the global variable pixtConf, which is defined as a struct of type PIXT_CONF in the global variable list GVL.

www.pixtend.de Copyright by Qube Solutions UG (haftungsbeschränkt) 8 / 17

PiXtend Application-Note: PiXtend with CODESYS – Demo Project

In the demo project it is possible to change PiXtend hardware parameters on the fly, using the config pop-ups of the WebVisu.

As soon as a config pop-up is closed, the GVL.xUpdateConfig Bit gets set, which triggers the function Block PiXtendConfiguration to update the relevant PiXtend Control Bytes according to the selected settings.

Settings that can be changed from the WebVisu are i.e. the data direction of GPIOs, the sample rate of analog inputs, and more.. More details can be found in the Visualization Chapter (Config-Popups).

www.pixtend.de Copyright by Qube Solutions UG (haftungsbeschränkt) 9 / 17

PiXtend Application-Note: PiXtend with CODESYS – Demo Project

3.4 PIXTConfig

The PIXTConfig folder contains a collection of structs, unions, and the function block PiXtendConfiguration which allow easy bit- and byte wise access to all PiXtend configuration bytes. No changes will be necessary here, we only explain the composition and function.

www.pixtend.de Copyright by Qube Solutions UG (haftungsbeschränkt) 10 / 17

PiXtend Application-Note: PiXtend with CODESYS – Demo Project

The PIXT_CONF struct contains all PiXtend control-bytes as Unions:

The following explanation uses the union PIXT_CONFU_UC as an example:

To access the whole byte at once, one can use pixtConf.byUc_Ctrl.Data, which is simply a BYTE. This Byte can be used directly in the IO mapping section of the PiXtend Device.

For bitwise access, one can use pixtConf.byUc_Ctrl.Bits to access single bits by their respective name, without the need to know which bit number it is. All this is defined in the PIXT_CONF_UC struct.

www.pixtend.de Copyright by Qube Solutions UG (haftungsbeschränkt) 11 / 17

PiXtend Application-Note: PiXtend with CODESYS – Demo Project

Of course the same principle applies to all the rest of the configuration bytes. The demo project can be used as a reference.

More detailed information about the meaning of the configuration bytes can be found in a separate application note: PiXtend – Control and Status Bytes

www.pixtend.de Copyright by Qube Solutions UG (haftungsbeschränkt) 12 / 17

PiXtend Application-Note: PiXtend with CODESYS – Demo Project

3.5 Visualization

The Visualization contains a variety of control elements to control and monitor most of the PiXtend's Inputs and Outputs.

3.4.1 Access to Input/Output Variables

To visualize in- and output states one can directly access the corresponding variable from the GVL (Global Variable List):

www.pixtend.de Copyright by Qube Solutions UG (haftungsbeschränkt) 13 / 17

PiXtend Application-Note: PiXtend with CODESYS – Demo Project

The GVL contains one entry for each input/output which is mapped directly to the PiXtend device:

3.4.2 Config-Popups

To open a config pop-up, we use a „Button“ control element which opens a dialog (here ConfigGPIO) OnMouseClick.

ConfigGPIO has been created as a Visualization of type „Dialog“ with fixed size.

www.pixtend.de Copyright by Qube Solutions UG (haftungsbeschränkt) 14 / 17

PiXtend Application-Note: PiXtend with CODESYS – Demo Project

A mouse click on the „OK“ button inside the ConfigGPIO dialog closes the dialog on the event OnMouseClick and executes the following ST-code OnMouseUp: GVL.xUpdateConfig:=TRUE; This update flag in return triggers the main programs function block fbPixtendConfiguration to update the values of the GPIO control bytes according to the new settings.

www.pixtend.de Copyright by Qube Solutions UG (haftungsbeschränkt) 15 / 17

PiXtend Application-Note: PiXtend with CODESYS – Demo Project

3.4.3 Combo Boxes

The struct GVL.visuConfig is used to populate strings in Combo Boxes and to read back the selected item.

GPIO0_State is of type INT and can hold either the value 0,1,2 or 3, depending on which item is currently selected: „Input“, „Output“, „DHT11“ or „DHT22“.

The function block PiXtendConfiguration in the main program checks the value of GPIO0_State and sets the corresponding bit(s) in pixtConf, after the config dialog is closedand xUpdate is set.

www.pixtend.de Copyright by Qube Solutions UG (haftungsbeschränkt) 16 / 17

PiXtend Application-Note: PiXtend with CODESYS – Demo Project

We hope you have fun using the PiXtend with CODESYS and are successful with your projects.

We are always interested in your feedback. If you use PiXtend in one of your projects please mention PiXtend and our URL www.pixtend.de somewhere.

www.pixtend.de Copyright by Qube Solutions UG (haftungsbeschränkt) 17 / 17