You are on page 1of 53

2017

Experiment using MicroDAQ-
Data acquisition tool

M.Mohamed Ibrahim
Tenet Technetronics
13-MAY-17
Tenet Technetronics 1
Application Notes

Contents

CHAP 1: Getting Started with MicroDAQ ………………………………….2

CHAP 2: Model Execution ………………………………………….10

CHAP 3: Function Generator ………………………………………….18

CHAP 4: A/D Converter ………………………………………….25

CHAP 5: Pulse Width Modulation ………………………………………….33

CHAP 6: Encoder ………………………………………….38

CHAP 7: C/C++ code integration tool ………………………………………….44

Tenet Technetronics | R&D LAB

2514/U, 7th Opp:B.B.M.P. Swimming Pool, 8th A Main Rd, Hampi Nagar, RPC Layout, Vijaya Nagar, Bengaluru-560104
Ph. No: 080-26722726., Website: www.tenettech.com, Email: info@tenettech.com
Tenet Technetronics 2
Application Notes

CHAP 1: Getting Started with MicroDAQ

1.1 MicroDAQ
MicroDAQ is an ideal platform for developers, scientists and geeks
involved in real-time measurement and control development. The platform
supports design flows from popular model based tools like SCILAB, MATLAB, and
LABVIEW. The user has the choice to either go with a complete open source
software toolchain or with the existing access to proprietary tools in the house.

Figure 1: MicroDAQ

1.2 MicroDAQ Toolbox
MicroDAQ toolbox combines Scilab/XCos environment with Embedded
Solutions MicroDAQ real-time control measurement system equipped with TI
C6000 DSP. Module extends Scilab by allowing user to automatically generate
DSP applications directly from XCos scheme. User can use custom XCos blocks
which gives access to MicroDAQ hardware (ADC, DAC, DIO, PWM, UART,
Quadrature Encoder). Generated DSP application utilizes SYS/BIOS real-time
operating system combined with code generated from XCos scheme.

Libraries of blocks allow seamless to create Models/Diagrams in either
XCOS/SIMULINK/NI Labview and also create optimized C-Code, Compile and
link with the target compiler and download it for deployment. In addition to this
the platform allows for high frequency real-time data acquisition to capture or
tune parameters from the hardware in real-time.
Tenet Technetronics | R&D LAB

2514/U, 7th Opp:B.B.M.P. Swimming Pool, 8th A Main Rd, Hampi Nagar, RPC Layout, Vijaya Nagar, Bengaluru-560104
Ph. No: 080-26722726., Website: www.tenettech.com, Email: info@tenettech.com
Tenet Technetronics 3
Application Notes

1.3 Hardware employed:
 MicroDAQ E1100
 Power adopter – 5V 2A
 USB CABLE
 Ethernet cable

1.4 Software employed:
 SCILAB 5.5
 Code composer studio 5.5

1.5 MicroDAQ E1100:
The MicroDAQ E1100/E2200 is a DSP real-time control measurement device
designed to solve complex problems. This device combines TI C6000
fixes/floating point DSP core and an ARM9 core. The MicroDAQ E1100 is
equipped with up to 8 channel analog input with a sample rate of upto 166
KSPS.

Tenet Technetronics | R&D LAB

2514/U, 7th Opp:B.B.M.P. Swimming Pool, 8th A Main Rd, Hampi Nagar, RPC Layout, Vijaya Nagar, Bengaluru-560104
Ph. No: 080-26722726., Website: www.tenettech.com, Email: info@tenettech.com
Tenet Technetronics 4
Application Notes

Figure 2: Front view of MicroDAQ E1100

Figure 3: Rear view of MicroDAQ E1100

Tenet Technetronics | R&D LAB

2514/U, 7th Opp:B.B.M.P. Swimming Pool, 8th A Main Rd, Hampi Nagar, RPC Layout, Vijaya Nagar, Bengaluru-560104
Ph. No: 080-26722726., Website: www.tenettech.com, Email: info@tenettech.com
Tenet Technetronics 5
Application Notes

1.6 MicroDAQ E1100 Specification
 upto 456MHz CPU

 upto 32GB user memory

 Ethernet

 Wi-Fi

 USB2.0

 32 DIO lines

 8 analog inputs

 8 analog outputs

 Matlab/Simulink, LabVIEW, Scilab support

1.7 Steps to configuration
Step1: Unpack MicroDAQ and connect device to your PC. Use included 5V DC
power supply and Ethernet cable to connect device to host PC. During
MicroDAQ power up procedure D1, D2 LEDs are used to indicate state of device
boot sequence.

 D2 On - MicroDAQ bootloader initialization done
 D1 On - MicroDAQ Linux initialization done
 D1, D2 Off - MicroDAQ firmware initialization done

Step 2:

Data exchange between MicroDAQ and host PC is done with Ethernet or Wi-Fi.
Connect the device using Ethernet.

Step 3:

Tenet Technetronics | R&D LAB

2514/U, 7th Opp:B.B.M.P. Swimming Pool, 8th A Main Rd, Hampi Nagar, RPC Layout, Vijaya Nagar, Bengaluru-560104
Ph. No: 080-26722726., Website: www.tenettech.com, Email: info@tenettech.com
Tenet Technetronics 6
Application Notes

Connect the USB Port of the MicroDAQ device to the host PC. Microdaq device
will discovered as the USB storage device.

Step 4:

Open the USB storage device and open network.txt file. Configure the IP
address.

Default IP settings would be

 Ethernet - 10.10.1.1
 Wi-Fi - 10.10.2.1

If you want setup host PC with MicroDAQ default IP settings you should use the
following IP address and network mask settings for your host PC:

 Ethernet IP address range: 10.10.1.2 - 10.10.1.254
 Ethernet network mask: 255.255.255.0
 Wi-Fi IP address range: 10.10.2.1 - 10.10.2.254
 Wi-Fi network mask: 255.255.255.0

Step for setting the IP address (windows 7) for Ethernet port

Control panel -> Network and sharing center -> Access type (Local area
connections) ->Properties -> Internet protocol version 4

Tenet Technetronics | R&D LAB

2514/U, 7th Opp:B.B.M.P. Swimming Pool, 8th A Main Rd, Hampi Nagar, RPC Layout, Vijaya Nagar, Bengaluru-560104
Ph. No: 080-26722726., Website: www.tenettech.com, Email: info@tenettech.com
Tenet Technetronics 7
Application Notes

Figure 4

Set IP address from 10.10.1.2 - 10.10.1.254 and subnet mask as 255.255.255.0 and
press ok

Step 5: open cmd window then command ping 10.10.1.2 and check whether
we are getting reply.

Figure 5

Step 6: Open web browser and type the LAN IP address.

Tenet Technetronics | R&D LAB

2514/U, 7th Opp:B.B.M.P. Swimming Pool, 8th A Main Rd, Hampi Nagar, RPC Layout, Vijaya Nagar, Bengaluru-560104
Ph. No: 080-26722726., Website: www.tenettech.com, Email: info@tenettech.com
Tenet Technetronics 8
Application Notes

Figure 6

Reboot your MicroDAQ. We done with hardware connections and established
the connection between the host PC and MicroDAQ.

Step 7: Open Scilab and install MicroDAQ from atoms toolbox

Step 8: Configuring toolbox with 'microdaq_setup' setup wizard

 Make sure MicroDAQ device is connected and IP connection is valid.
 Execute 'microdaq_setup' command from Scilab
 Provide external components (CCS5 root directory, compiler, XDCTools,
SYS/BIOS) install paths
 Example directory structure (same for Linux) with standard CCS5
installation:
o Code Composer Studio 4/5 install path → C:\ti\ccsv5
o C6000 compiler install path →
C:\ti\ccsv5\tools\compiler\c6000_7.4.4
o XDCTools install path → C:\ti\xdctools_3_25_03_72
o SYS/BIOS RTOS install path → C:\ti\bios_6_35_04_50
 Give MicroDAQ IP address and detect the MicroDAQ and click OK

Tenet Technetronics | R&D LAB

2514/U, 7th Opp:B.B.M.P. Swimming Pool, 8th A Main Rd, Hampi Nagar, RPC Layout, Vijaya Nagar, Bengaluru-560104
Ph. No: 080-26722726., Website: www.tenettech.com, Email: info@tenettech.com
Tenet Technetronics 9
Application Notes

Figure 7

Tenet Technetronics | R&D LAB

2514/U, 7th Opp:B.B.M.P. Swimming Pool, 8th A Main Rd, Hampi Nagar, RPC Layout, Vijaya Nagar, Bengaluru-560104
Ph. No: 080-26722726., Website: www.tenettech.com, Email: info@tenettech.com
Tenet Technetronics 10
Application Notes

CHAP 2: Model Execution

2.1 Execution Mode:

Generally MicroDAQ runs in two modes,

1. Standalone mode

2. Ext mode

These modes can be used in different ways and on a different model
development stages.

2.2 Standalone Mode:

When Standalone mode is selected generated application can contain single
TI-RTOS task (clock function) which is executed on the DSP with selected sample
rate. Generated model is executed periodically and there is no communication
with Xcos like in Ext mode. MicroDAQ palette provides blocks which can be
used to access Standalone application parameters. In order to change
Standalone parameters during its execution 'MEM read' block and
mdaq_mem_set() function can be used. In case when user wants to download
data from Standalone application 'MEM Write' and mdaq_mem_get() function
can be a solution. The Standalone application generated from XCos diagram
can be uploaded on MicroDAQ and will create independent control-
measurement system.

Figure 1: Standalone Mode

Tenet Technetronics | R&D LAB

2514/U, 7th Opp:B.B.M.P. Swimming Pool, 8th A Main Rd, Hampi Nagar, RPC Layout, Vijaya Nagar, Bengaluru-560104
Ph. No: 080-26722726., Website: www.tenettech.com, Email: info@tenettech.com
Tenet Technetronics 11
Application Notes

2.2 Steps Involved in Standalone Mode:

Step 1: MicroDAQ blocks are used to access the MicroDAQ hardware.
MicroDAQ bocks are available in XCOS palette browser under MicroDAQ
palette.

Figure 2: MicroDAQ Palette

Step 2: Objective is to create an XCOS model using MicroDAQ LED blocks (see
Figure 3). Pick all the blocks specified in the fig 2, set the appropriate parameters
and make the connections as shown in the diagram.

Tenet Technetronics | R&D LAB

2514/U, 7th Opp:B.B.M.P. Swimming Pool, 8th A Main Rd, Hampi Nagar, RPC Layout, Vijaya Nagar, Bengaluru-560104
Ph. No: 080-26722726., Website: www.tenettech.com, Email: info@tenettech.com
Tenet Technetronics 12
Application Notes

Figure 3:LED_XCOS Model

Step 3: Now, we need to change the mode of MicroDAQ. Select SETUP Block
and make changes as shown in Figure 4.

Tenet Technetronics | R&D LAB

2514/U, 7th Opp:B.B.M.P. Swimming Pool, 8th A Main Rd, Hampi Nagar, RPC Layout, Vijaya Nagar, Bengaluru-560104
Ph. No: 080-26722726., Website: www.tenettech.com, Email: info@tenettech.com
Tenet Technetronics 13
Application Notes

Figure 4: Setup block settings

Step 4: Select Tools  MicroDAQ build model (See Figure 5)

Tenet Technetronics | R&D LAB

2514/U, 7th Opp:B.B.M.P. Swimming Pool, 8th A Main Rd, Hampi Nagar, RPC Layout, Vijaya Nagar, Bengaluru-560104
Ph. No: 080-26722726., Website: www.tenettech.com, Email: info@tenettech.com
Tenet Technetronics 14
Application Notes

Figure 5: Build model

Step 5: After build model, select Tools  MicroDAQ load model (see Figure 6)

Figure 6: Load Model

Tenet Technetronics | R&D LAB

2514/U, 7th Opp:B.B.M.P. Swimming Pool, 8th A Main Rd, Hampi Nagar, RPC Layout, Vijaya Nagar, Bengaluru-560104
Ph. No: 080-26722726., Website: www.tenettech.com, Email: info@tenettech.com
Tenet Technetronics 15
Application Notes

Step 6: Select Tools  MicroDAQ upload model (See Figure 7)

Figure 7: Upload Model

Step 7: After upload model (See Figure 8), Application will be stored in a MicroDAQ
nonvolatile memory.

Figure 8: Scilab Message

Step 8: Let us connect power source and see how our standalone DSP
application works (see Figure 9,10).

Tenet Technetronics | R&D LAB

2514/U, 7th Opp:B.B.M.P. Swimming Pool, 8th A Main Rd, Hampi Nagar, RPC Layout, Vijaya Nagar, Bengaluru-560104
Ph. No: 080-26722726., Website: www.tenettech.com, Email: info@tenettech.com
Tenet Technetronics 16
Application Notes

Figure 9: Power up_MicroDAQ

Figure 10:Output_D1 LED Blinks

Tenet Technetronics | R&D LAB

2514/U, 7th Opp:B.B.M.P. Swimming Pool, 8th A Main Rd, Hampi Nagar, RPC Layout, Vijaya Nagar, Bengaluru-560104
Ph. No: 080-26722726., Website: www.tenettech.com, Email: info@tenettech.com
Tenet Technetronics 17
Application Notes

2.3 Ext Mode:

During control or measurement application development often user wants to
have live application data access to verify if model works as expected or it
needs to be modified. MicroDAQ toolbox for Scilab provides integrated way
which allows access to live DSP data without external tools. User can use
standard XCos sinks (e.g Scope, To workspace) block to view data for real-time
application running on MicroDAQ DSP. When user selects Ext mode generated
application will be constructed from two tasks. Same as in Standalone mode Ext
mode application have real-time task which executes code generated from
model and additional low priority task which is taking care of TCP/IP
communication with Xcos. Model code runs as a high priority real-time task, idle
task on the other hand has the lowest profity and it is executed only when
model real-time execution is done. Dedicated MicroDAQ drivers delegates
TCP/IP handling from DSP to ARM core which increase processing capabielities
and improve real-time processing.

Figure 11: Ext Mode

In Ext mode user can use execution profiling feature to measure model
execution times.

Tenet Technetronics | R&D LAB

2514/U, 7th Opp:B.B.M.P. Swimming Pool, 8th A Main Rd, Hampi Nagar, RPC Layout, Vijaya Nagar, Bengaluru-560104
Ph. No: 080-26722726., Website: www.tenettech.com, Email: info@tenettech.com
Tenet Technetronics 18
Application Notes

CHAP 3: Function Generator

3.1 Introduction

Function generator is a signal source that has capability of producing different
waveforms as its output signal. The most common waveforms are Sine, Square,
Triangular & Sawtooth. Function generators are used in the development, test and
repair of electronic equipment.

We can control and configure function generator directly from SCILAB_XCOS using
MicroDAQ Toolbox. We can create the waveforms in SCILAB_XCOS and use the toolbox
to upload them to the instrument. We can also build graphical interfaces to verify
device performance, compare real-world data to models created in SCILAB_XCOS
and automate the tests.

3.2 Uses of function generator:

Designing, testing, troubleshooting and repairing electronic or electroacoustic devices,
systems and equipment.

3.3 Blocks required:

Designation Representation Sub palette

Sine wave generator MicroDAQ/mdaq_sinus

Square wave generator MicroDQA/mdaq_square

Configures Xcos model
MicroDAQ/mdaq_setup
for MicroDAQ

Reads signal data from MicroDAQ/mdaq_signal
MicroDAQ DSP

Tenet Technetronics | R&D LAB

2514/U, 7th Opp:B.B.M.P. Swimming Pool, 8th A Main Rd, Hampi Nagar, RPC Layout, Vijaya Nagar, Bengaluru-560104
Ph. No: 080-26722726., Website: www.tenettech.com, Email: info@tenettech.com
Tenet Technetronics 19
Application Notes

application

User defined
Super block
function/super_f

Clock MicroDAQ/Sources/clock_c

Visualization MicroDAQ/sinks/cscope

3.4 Steps involved in Function generator

Step 1: To generate sine and square waveforms in Scilab/XCOS using MicroDAQ
toolbox. Select MicroDAQ  Sine wave generator block & MicroDAQ  Square wave
generator.

Step 2: Make connection between the required blocks and then simulate the diagram
to get a sine and square waveform.

Sine wave generator:

Tenet Technetronics | R&D LAB

2514/U, 7th Opp:B.B.M.P. Swimming Pool, 8th A Main Rd, Hampi Nagar, RPC Layout, Vijaya Nagar, Bengaluru-560104
Ph. No: 080-26722726., Website: www.tenettech.com, Email: info@tenettech.com
Tenet Technetronics 20
Application Notes

Sine waveform output:

Tenet Technetronics | R&D LAB

2514/U, 7th Opp:B.B.M.P. Swimming Pool, 8th A Main Rd, Hampi Nagar, RPC Layout, Vijaya Nagar, Bengaluru-560104
Ph. No: 080-26722726., Website: www.tenettech.com, Email: info@tenettech.com
Tenet Technetronics 21
Application Notes

Square wave generator:

Tenet Technetronics | R&D LAB

2514/U, 7th Opp:B.B.M.P. Swimming Pool, 8th A Main Rd, Hampi Nagar, RPC Layout, Vijaya Nagar, Bengaluru-560104
Ph. No: 080-26722726., Website: www.tenettech.com, Email: info@tenettech.com
Tenet Technetronics 22
Application Notes

Square waveform output:

Example 1: Sine wave generator

Tenet Technetronics | R&D LAB

2514/U, 7th Opp:B.B.M.P. Swimming Pool, 8th A Main Rd, Hampi Nagar, RPC Layout, Vijaya Nagar, Bengaluru-560104
Ph. No: 080-26722726., Website: www.tenettech.com, Email: info@tenettech.com
Tenet Technetronics 23
Application Notes

Purpose of Gain & Workspace Block:

Gain Block:

In this example Gain is used to product the amplitude of sine wave.

Workspace Block:

This block is used to put simulated data in the scilab workspace. Each sampling time,
both dates and values of input are recorded. Records are available after the simulation
in Scilab's workspace as variable.time and variable.values where variable is the name
given in the Scilab variable name field.

OUTPUT:

Tenet Technetronics | R&D LAB

2514/U, 7th Opp:B.B.M.P. Swimming Pool, 8th A Main Rd, Hampi Nagar, RPC Layout, Vijaya Nagar, Bengaluru-560104
Ph. No: 080-26722726., Website: www.tenettech.com, Email: info@tenettech.com
Tenet Technetronics 24
Application Notes

After simulation,

In scilab console window

Type A.time & A.values

Where, A variable name

Tenet Technetronics | R&D LAB

2514/U, 7th Opp:B.B.M.P. Swimming Pool, 8th A Main Rd, Hampi Nagar, RPC Layout, Vijaya Nagar, Bengaluru-560104
Ph. No: 080-26722726., Website: www.tenettech.com, Email: info@tenettech.com
Tenet Technetronics 25
Application Notes

CHAP 4: A/D Converter

4.1 Purpose of DAC & ADC Blocks.

 DAC  Digital to Analog Converter

Figure 1: DAC Block

This block is used to set Analog Output (AO) in MicroDAQ hardware.
Select analog output type by providing Converter parameters
accordingly to MicroDAQ hardware configuration. (See Figure 2)

Figure 2: DAC Configuration
Tenet Technetronics | R&D LAB

2514/U, 7th Opp:B.B.M.P. Swimming Pool, 8th A Main Rd, Hampi Nagar, RPC Layout, Vijaya Nagar, Bengaluru-560104
Ph. No: 080-26722726., Website: www.tenettech.com, Email: info@tenettech.com
Tenet Technetronics 26
Application Notes

 ADC  Analog to Digital Converter

Output 1 16 Bit raw ADC Value ; Output 2  Measured value in volts

Figure 3: ADC Block

This block is used to read Analog Input (AI) in MicroDAQ hardware.
Select analog input type by providing Converter parameters accordingly
to MicroDAQ hardware configuration. (See Figure 4)

Figure 4: ADC Configuration

Tenet Technetronics | R&D LAB

2514/U, 7th Opp:B.B.M.P. Swimming Pool, 8th A Main Rd, Hampi Nagar, RPC Layout, Vijaya Nagar, Bengaluru-560104
Ph. No: 080-26722726., Website: www.tenettech.com, Email: info@tenettech.com
Tenet Technetronics 27
Application Notes

4.2 Steps Involved:

Method 1:

Step 1: MicroDAQ blocks are used to access the MicroDAQ hardware.
MicroDAQ bocks are available in XCOS palette browser under MicroDAQ
palette.

Figure 5: MicroDAQ Palette

Step 2: Objective is to create an XCOS model using MicroDAQ DAC and ADC
blocks (see Figure 6). Pick all the blocks specified in the fig 6b, set the
appropriate parameters and connect as shown in the diagram.

Figure 6a: Super block _Analog Demo
Tenet Technetronics | R&D LAB

2514/U, 7th Opp:B.B.M.P. Swimming Pool, 8th A Main Rd, Hampi Nagar, RPC Layout, Vijaya Nagar, Bengaluru-560104
Ph. No: 080-26722726., Website: www.tenettech.com, Email: info@tenettech.com
Tenet Technetronics 28
Application Notes

Figure 6b: MicroDAQ – Analog Demo

Note:

Sine block gives an output in volts to DAC Block, so we are giving an analog sine wave
as input to DAC block. Connect MicroDAQ AO1 pin and GND to CRO. Now you can
visualize the generated Sine wave in CRO (See figure 7).

Figure 7: Sine wave as input in volts to DAC

Tenet Technetronics | R&D LAB

2514/U, 7th Opp:B.B.M.P. Swimming Pool, 8th A Main Rd, Hampi Nagar, RPC Layout, Vijaya Nagar, Bengaluru-560104
Ph. No: 080-26722726., Website: www.tenettech.com, Email: info@tenettech.com
Tenet Technetronics 29
Application Notes

Step 3: Connect potentiometer as analog input through the pin AI1in MicroDAQ
(see Figure 8).

Figure 8: Potentiometer connection

Step 4: Connect LED to analog output pin AO1 in MicroDAQ (See Figure 9).
Simulate the model. Now the output plots for ADC & DAC Blocks are displayed
(see Figure 10).

During positive half cycle of sine wave LED glows and negative half cycle LED
turns off.

Tenet Technetronics | R&D LAB

2514/U, 7th Opp:B.B.M.P. Swimming Pool, 8th A Main Rd, Hampi Nagar, RPC Layout, Vijaya Nagar, Bengaluru-560104
Ph. No: 080-26722726., Website: www.tenettech.com, Email: info@tenettech.com
Tenet Technetronics 30
Application Notes

Figure 9: Connection diagram

Figure 10: Output
Tenet Technetronics | R&D LAB

2514/U, 7th Opp:B.B.M.P. Swimming Pool, 8th A Main Rd, Hampi Nagar, RPC Layout, Vijaya Nagar, Bengaluru-560104
Ph. No: 080-26722726., Website: www.tenettech.com, Email: info@tenettech.com
Tenet Technetronics 31
Application Notes

Figure 11: MicroDAQ_ Analog_demo.

Method 2:

Step1: Replace the input of the ADC, potentiometer with sine wave as input by
shorting the pins AI1 and AO1 in the MicroDAQ hardware module.

Step 2: Now simulate the model observe for changes in graph as shown in figure.

Figure 11: Connection diagram

Tenet Technetronics | R&D LAB

2514/U, 7th Opp:B.B.M.P. Swimming Pool, 8th A Main Rd, Hampi Nagar, RPC Layout, Vijaya Nagar, Bengaluru-560104
Ph. No: 080-26722726., Website: www.tenettech.com, Email: info@tenettech.com
Tenet Technetronics 32
Application Notes

Figure 12: Connection diagram

Figure 12: Output graph

Tenet Technetronics | R&D LAB

2514/U, 7th Opp:B.B.M.P. Swimming Pool, 8th A Main Rd, Hampi Nagar, RPC Layout, Vijaya Nagar, Bengaluru-560104
Ph. No: 080-26722726., Website: www.tenettech.com, Email: info@tenettech.com
Tenet Technetronics 33
Application Notes

CHAP 5: Pulse Width Modulation

5.1 Introduction

Generally Pulse Width Modulation is prominently used in controlling & communication
applications. Here, we are using this technique to changing the light intensity of led.

This block controls MicroDAQ PWM modules. One of three PWM modules can be
selected (PWM1, PWM2, PWM3), PWM period is defined with 1us resolution, 'Polarity'
parameters allow to generate inverted PWM waveform. Blocks input parameter range
is 0-100 (duty in %).

5.2 PWM Block:

Step 1: MicroDAQ blocks are used to access the MicroDAQ hardware.
MicroDAQ blocks are available in XCOS palette browser under MicroDAQ
palette.

Tenet Technetronics | R&D LAB

2514/U, 7th Opp:B.B.M.P. Swimming Pool, 8th A Main Rd, Hampi Nagar, RPC Layout, Vijaya Nagar, Bengaluru-560104
Ph. No: 080-26722726., Website: www.tenettech.com, Email: info@tenettech.com
Tenet Technetronics 34
Application Notes

Figure 1: MicroDAQ Palette

Step 2: Objective is to create an XCOS model using MicroDAQ PWM blocks (see
Figure 2a). Pick all the blocks specified in the fig 2b, set the appropriate
parameters and connect as shown in the diagram.

Figure 2a: Super Block_PWM Demo

Tenet Technetronics | R&D LAB

2514/U, 7th Opp:B.B.M.P. Swimming Pool, 8th A Main Rd, Hampi Nagar, RPC Layout, Vijaya Nagar, Bengaluru-560104
Ph. No: 080-26722726., Website: www.tenettech.com, Email: info@tenettech.com
Tenet Technetronics 35
Application Notes

Figure 2b: MicroDAQ_PWM Demo

Figure 2c: Output

Tenet Technetronics | R&D LAB

2514/U, 7th Opp:B.B.M.P. Swimming Pool, 8th A Main Rd, Hampi Nagar, RPC Layout, Vijaya Nagar, Bengaluru-560104
Ph. No: 080-26722726., Website: www.tenettech.com, Email: info@tenettech.com
Tenet Technetronics 36
Application Notes

Figure 3a: PWM input is 95

Figure 3b: Output

Tenet Technetronics | R&D LAB

2514/U, 7th Opp:B.B.M.P. Swimming Pool, 8th A Main Rd, Hampi Nagar, RPC Layout, Vijaya Nagar, Bengaluru-560104
Ph. No: 080-26722726., Website: www.tenettech.com, Email: info@tenettech.com
Tenet Technetronics 37
Application Notes

Figure 4a: PWM input is 10

Figure 4b: Output

Tenet Technetronics | R&D LAB

2514/U, 7th Opp:B.B.M.P. Swimming Pool, 8th A Main Rd, Hampi Nagar, RPC Layout, Vijaya Nagar, Bengaluru-560104
Ph. No: 080-26722726., Website: www.tenettech.com, Email: info@tenettech.com
Tenet Technetronics 38
Application Notes

CHAP 6: Encoder

6.1 Introduction
Encoders are used to translate rotary or linear motion into a digital signal. Usually this is
for the purpose of monitoring or controlling motion parameters such as speed, rate,
direction, distance or position.

Here, we can use MicroDAQ Encoder Block to count rotation of DC motor directly from
SCILAB_XCOS. We can also build graphical interfaces to verify device performance,
compare real-world data to models created in SCILAB_XCOS.

6.2 DC Motor with Encoder
This gear motor is a powerful 12V brushed DC motor with a 29:1 metal gearbox and an
integrated quadrature encoder that provides a resolution of 64 counts per revolution of
the motor shaft, which corresponds to 1920 counts per revolution of the gearbox's
output shaft. These units have a 0.61"-long, 6 mm-diameter D-shaped output shaft.

Figure 1: DC Motor with Encoder

This powerful brushed DC gear motor is available in six different gear ratios and features
an integrated quadrature encoder with 64 counts per revolution (CPR) of the motor
shaft.

Tenet Technetronics | R&D LAB

2514/U, 7th Opp:B.B.M.P. Swimming Pool, 8th A Main Rd, Hampi Nagar, RPC Layout, Vijaya Nagar, Bengaluru-560104
Ph. No: 080-26722726., Website: www.tenettech.com, Email: info@tenettech.com
Tenet Technetronics 39
Application Notes

6.3 Encoder
A two-channel Hall Effect encoder is used to sense the rotation of a magnetic disk on a
rear protrusion of the motor shaft. The quadrature encoder provides a resolution of 64
counts per revolution of the motor shaft, which corresponds to 1920 counts per
revolution of the gearbox’s output shaft.

The motor/encoder has six color-coded, 11" (28 cm) leads terminated by a 1×6 female
header with a 0.1″ pitch, as shown in the Figure 2.

The Hall sensor requires an input voltage, Vcc, between 3.5 and 20 V and draws a
maximum of 10 Ma. The A and B outputs are square waves from 0 V to Vcc
approximately 90° out of phase. The frequency of the transitions tells you the speed of
the motor, and the order of the transitions tells you the direction.

Figure 2: Encoder

The following table describes the wire functions:

Wire color Function

Red motor power (connects to one motor terminal)

Black motor power (connects to the other motor terminal)

Green encoder GND

Tenet Technetronics | R&D LAB

2514/U, 7th Opp:B.B.M.P. Swimming Pool, 8th A Main Rd, Hampi Nagar, RPC Layout, Vijaya Nagar, Bengaluru-560104
Ph. No: 080-26722726., Website: www.tenettech.com, Email: info@tenettech.com
Tenet Technetronics 40
Application Notes

Blue encoder Vcc (3.5 – 20 V)

Yellow encoder A output

White encoder B output

Table 1: Wire functions

6.4 MicroDAQ_Encoder Block:
Encoder block reads MicroDAQ quadrature encoder. 'Init position' parameter allows to
set initial value of quadrature encoder position register.

This block can be used in host simulation mode and for code generation.

Figure 3: Encoder Block

Figure 4: Encoder Block Parameter
Tenet Technetronics | R&D LAB

2514/U, 7th Opp:B.B.M.P. Swimming Pool, 8th A Main Rd, Hampi Nagar, RPC Layout, Vijaya Nagar, Bengaluru-560104
Ph. No: 080-26722726., Website: www.tenettech.com, Email: info@tenettech.com
Tenet Technetronics 41
Application Notes

Step 1: MicroDAQ blocks are used to access the MicroDAQ hardware. MicroDAQ
bocks are available in XCOS palette browser under MicroDAQ palette.

Figure 5: MicroDAQ Palette

Step 2: Objective is to count rotation of DC motor using MicroDAQ Encoder
block (see Figure 6a). Pick all the blocks specified in the fig 6b, set the
appropriate parameters and connect as shown in the diagram.

Figure 6a

Tenet Technetronics | R&D LAB

2514/U, 7th Opp:B.B.M.P. Swimming Pool, 8th A Main Rd, Hampi Nagar, RPC Layout, Vijaya Nagar, Bengaluru-560104
Ph. No: 080-26722726., Website: www.tenettech.com, Email: info@tenettech.com
Tenet Technetronics 42
Application Notes

Figure 6b

MicroDAQ Function key block is used to read function key state.

Figure 6c

Set DIO Config block parameter as shown Figure 6c.

Tenet Technetronics | R&D LAB

2514/U, 7th Opp:B.B.M.P. Swimming Pool, 8th A Main Rd, Hampi Nagar, RPC Layout, Vijaya Nagar, Bengaluru-560104
Ph. No: 080-26722726., Website: www.tenettech.com, Email: info@tenettech.com
Tenet Technetronics 43
Application Notes

Step 3: Give hardware connections are shown in Figure 7.

Figure 7: Hardware Connection diagram

Note:

Here, we use gear motor so,we need to give 12v supply externally.

Step 4: Run the model & displayed output is shown in Figure8.

Figure 8: Output

Tenet Technetronics | R&D LAB

2514/U, 7th Opp:B.B.M.P. Swimming Pool, 8th A Main Rd, Hampi Nagar, RPC Layout, Vijaya Nagar, Bengaluru-560104
Ph. No: 080-26722726., Website: www.tenettech.com, Email: info@tenettech.com
Tenet Technetronics 44
Application Notes

CHAP 7: C/C++ Code integration tool

7.1 Introduction
Code integration tools are useful for creating high performance real-time control and
measurement applications. C/C++ programmers will benefit from code integration tools
giving easy way to write custom Xcos block.

MicroDAQ toolbox for Scilab allows easy integration of legacy or custom C/C++ code
making Xcos model creation more flexible. User can automatically generate Xcos
blocks which executes custom C/C++ code.

Moreover block code can also be debugged with Code Composer Studio. User can
optimize some parts of Xcos model by replacing Xcos standard block with custom
block which contains optimized C code for faster execution.

'Execution profiling' feature allows to precisely determine model execution times.

This article presents two examples,

i. How to integrate sine C function generator

ii. How to create custom ADC block with oversampling feature for getting
ADC reads more accurate.

7.2 Custom Sine waveform Generator
A simple sine waveform C function generator. to show how C/C++ code integration
tools works.
void sin_waveform_gen(double time, double amplitude, double bias, double freq, double *output)

{

*output = amplitude * sin(time * freq) + bias;

}
Function sin_waveform_gen() returns sin value depending on user parameters values
The function sin_waveform_gen() returns sine value depending on the user parameters
passed through pointer. Depending on needs we can create Xcos block which will
execute sin_waveform_gen() function with different input and parameter options, like
amplitude, bias and frequency inputs and sin value output or create block which will
have frequency parameter and amplitude and bias input.
Tenet Technetronics | R&D LAB

2514/U, 7th Opp:B.B.M.P. Swimming Pool, 8th A Main Rd, Hampi Nagar, RPC Layout, Vijaya Nagar, Bengaluru-560104
Ph. No: 080-26722726., Website: www.tenettech.com, Email: info@tenettech.com
Tenet Technetronics 45
Application Notes

MicroDAQ toolbox for Scilab provides macros which simplifies custom code integration
as a Xcos block.

A new block creation is done in two steps.

1. First generate Xcos block then

2. Xcos block C code has to be modified to call custom code, in our case it is
sin_waveform_gen() function.

7.3 Xcos block creation
C/C++ code integration tools uses structure which describe Xcos block. The structure
holds block parameters, block name, block description, default block parameters,
default parameters sizes and block input and output configuration.

MicroDAQ toolbox for Scilab provides following macros which are used for custom
code integration and increase Xcos model flexibility.

 mdaq_block() - initializes structure which holds custom Xcos block parameters

 mdaq_block_add(block_structure) - generates new block based on provided
structure

 mdaq_block_build(%T) - builds/rebuilds block C code, if %T argument provided,
block is build for debug

To create default Xcos block structure mdaq_block() macro needs to be called from
Scilab console:

Tenet Technetronics | R&D LAB

2514/U, 7th Opp:B.B.M.P. Swimming Pool, 8th A Main Rd, Hampi Nagar, RPC Layout, Vijaya Nagar, Bengaluru-560104
Ph. No: 080-26722726., Website: www.tenettech.com, Email: info@tenettech.com
Tenet Technetronics 46
Application Notes

Resulting structure contains default block parameters which have to be modified to
meet our requirements regarding input/output and block parameters. The structure
sin_block contains fields depending on their values new block will be generated. The
name field holds block name, block macros, C code and block name will be
generated with prefix 'mdaq_' which denote that this block is dedicated for MicroDAQ
device. Now we can modifiy default structure and run mdaq_block_add() block
generator macro.

Tenet Technetronics | R&D LAB

2514/U, 7th Opp:B.B.M.P. Swimming Pool, 8th A Main Rd, Hampi Nagar, RPC Layout, Vijaya Nagar, Bengaluru-560104
Ph. No: 080-26722726., Website: www.tenettech.com, Email: info@tenettech.com
Tenet Technetronics 47
Application Notes

Based on modified sin_block structure mdaq_block_add macro will generate Xcos
block with two inputs, first one will be used for sine waveform amplitude and the second
one for bias. In addition sine2 block will have one parameter 'Frequency' which will
define sine waveform frequency. Finally block will have one output where actual sine
waveform will be generated.

After calling mdaq_block_add macro we will have generated block macros and block
C code which will be executed on MicroDAQ DSP core. The macro generates only
block C code template, user has to edit generated file in order to call custom or legacy
code. More advanced Scilab users can edit block macros to change block
functionality. In our case we don't need to modify generated block macros, only C
code has to be modified to call sin_waveform_gen().

7.4 Block C code modification
In order to obtain generated C file path we can use mdaq_block_add() output or use
mdaq_toolbox_path macro:

mdaq_toolbox_path() + 'src\c\userlib\' + 'mdaq_sin2.c'

The generated mdaq_sin2.c file contains C code which is executed during model
initialization, calculation and model termination. There are three functions init(), inout()
end end(), these function are executed during model initialization, execution and
termination respectively.

Figure 1

Tenet Technetronics | R&D LAB

2514/U, 7th Opp:B.B.M.P. Swimming Pool, 8th A Main Rd, Hampi Nagar, RPC Layout, Vijaya Nagar, Bengaluru-560104
Ph. No: 080-26722726., Website: www.tenettech.com, Email: info@tenettech.com
Tenet Technetronics 48
Application Notes

In our case initialization function isn't used, only inout() function will be used to compute
sin_waveform_gen(). Generated code contains input, output and parameters
variables, generated variables names are the same as defined in Scilab structure
describing block. Block input variables are named with 'u' and number related to input
count. Block outputs on the other hand are need with 'y' and number of output, e.g 'y1'.
Generated function with input, output and block parameter variables looks as follows:

/* This function will be executed on every model step */

static void inout(scicos_block *block)

{

/* Block parameters */

double *params = GetRparPtrs(block); /* param size = 1 */

double frequency = params[0];

/* Block input ports */

double *u1 = GetRealInPortPtrs(block,1);

int u1_size = GetInPortRows(block,1); /* u1_size = 1 */

double *u2 = GetRealInPortPtrs(block,2);

int u2_size = GetInPortRows(block,2); /* u2_size = 1 */

/* Block output ports */

double *y1 = GetRealOutPortPtrs(block,1);

int y1_size = GetOutPortRows(block,1); /* y1_size = 1 */

/* Add block code here (executed every model step) */

}

Tenet Technetronics | R&D LAB

2514/U, 7th Opp:B.B.M.P. Swimming Pool, 8th A Main Rd, Hampi Nagar, RPC Layout, Vijaya Nagar, Bengaluru-560104
Ph. No: 080-26722726., Website: www.tenettech.com, Email: info@tenettech.com
Tenet Technetronics 49
Application Notes

Generated code contains comments which can give a hint where and how to add
custom code. In order call our sin_waveform_gen() function we will use u1, u2 input
variables and y1 output port variable. For frequency we will use frequency variable
which holds value provided by user in Xcos block properties. Our function call can look
as follows:

sin_waveform_gen(get_scicos_time(), *u1, *u2, frequency, y1)

We can add function call to mdaq_sin2.c source code.

Function sin_waveform_gen() code can be added in two ways.

i. We can copy and paste function to mdaq_sin2.c file

ii. we can create separate C source file & corresponding header file

and copy it to userlib directory and in mdaq_sin2.c file include header file. Scilab
mdaq_block_build() macro will compile every C source (generated and copied) file
which is located in userlib directory. In order to compile modified mdaq_sin2.c file
mdaq_block_build macro needs to be executed

mdaq_block_build();

If macro execution doesn't returns any error we can restart Scilab to have access to
newly created sin2 block. After Scilab restart new palette MicroDAQ User appears in
palette browser with sin2 block. Generated block has two inputs and one output as
described in sin_block structure before. Block sin2 also has Frequency parameter for
determining sine waveform frequency with default value 1.

Tenet Technetronics | R&D LAB

2514/U, 7th Opp:B.B.M.P. Swimming Pool, 8th A Main Rd, Hampi Nagar, RPC Layout, Vijaya Nagar, Bengaluru-560104
Ph. No: 080-26722726., Website: www.tenettech.com, Email: info@tenettech.com
Tenet Technetronics 50
Application Notes

Figure 2

We need to verify if our generated block works as expected. In order to do this we will
create simple model with generated block and scope for verification. We can use
generated block same as standard Xcos blocks, after code generation with Tools-
>MicroDAQ build and load model we can see on scope if our generated block works
as expected.

Tenet Technetronics | R&D LAB

2514/U, 7th Opp:B.B.M.P. Swimming Pool, 8th A Main Rd, Hampi Nagar, RPC Layout, Vijaya Nagar, Bengaluru-560104
Ph. No: 080-26722726., Website: www.tenettech.com, Email: info@tenettech.com
Tenet Technetronics 51
Application Notes

Figure 3

We can also change frequency from default 1 to 10 and add bias to the waveform
with created custom block.

Tenet Technetronics | R&D LAB

2514/U, 7th Opp:B.B.M.P. Swimming Pool, 8th A Main Rd, Hampi Nagar, RPC Layout, Vijaya Nagar, Bengaluru-560104
Ph. No: 080-26722726., Website: www.tenettech.com, Email: info@tenettech.com
Tenet Technetronics 52
Application Notes

Figure 4

This example shows how user can integrate custom C code as a Xcos block in a Xcos
diagram and generate from it DSP applicaion which can be executed on MicroDAQ
device. This way MicroDAQ toobox code integration tools allows easy integration of
user code by filling out a structure with basic block parameters and block C code
modification to obtain custom block executing user C code. In the next example we
see how to customize MicroDAQ hardware blocks by implementing custom ADC block
with oversampling feature.

For more information please visit: www.tenettech.com

For technical query please send an e-mail: info@tenettech.com

Tenet Technetronics | R&D LAB

2514/U, 7th Opp:B.B.M.P. Swimming Pool, 8th A Main Rd, Hampi Nagar, RPC Layout, Vijaya Nagar, Bengaluru-560104
Ph. No: 080-26722726., Website: www.tenettech.com, Email: info@tenettech.com