(New) USB-HID Real-Time Data Acquisition into Matlab/Simulink Demonstration (part 2 of 2)

Uploaded by RapidSTM32 on 03.02.2011

There is one warning about the build process.
Before you build, your current directory must be in the same location as your Simulink model, like this.
If you are not in the same directory as your model when you try to build it, you will get this error.
If you get this error, the first thing to check is that you are in the correct directory, which is where your Simulink model is.
We will now create a new Simulink model for our host PC.
First we go to “File”, “New” and “Model”. A new Simulink model appears.
This time we don’t need to configure our model to use the RapidSTM32 target because this model will be running on the host PC - so let’s just “Save As”: “adc_hid_hostpc_demo” and “Save”.
Next we will open up the “Simulink Library Browser”, go to “RapidSTM32 Blockset”, “Add-On Modules” and find the “HID Receive” block.
We drag and drop it into our model. Now we can configure this block by double-clicking on it.
Because we are receiving two single precision data types, we just type in “single” twice.
Because we are sampling at a 100 hertz sampling rate, we set the sample time to 10 milliseconds.
Click “OK” and “Save” that.

Suppose we would like to convert the measured temperature in volts to celsius, we just use “Convert Onboard AN16 Volts to Temp C” from the “On-Chip Peripherals” block. Here.
Suppose we want to display this temperature as numerical values, we just go to the standard “Simulink” block and “Sinks” and drag the “Display” in here.
Suppose we want to plot the potentiometer voltage as a graph, we use the “Scope” block, again from the “Simulink/Sinks” blockset, and drag it here.
Suppose we want to display the numerical display for the voltage as well, instead of dragging the display from the “Library Browser” there is a short cut.
We can click on “Display” and drag the block with the right mouse button and it will just copy the block.
Ok, so let's connect the signal line together like this.
However, there is a special requirement for displaying the potentiometer voltage using the display block. This is because the display block requires an input of type "double precision".
As our potentiometer voltage is outputted as single type, we need to convert it from "single precision" to "double precision" type.
We can do that by using the standard Simulink block.
Go to “Signal Attributes” and “Data Type Conversion”.
Double click on “Data Type Conversion” and change the output data type to “double”.
Click “Ok”.
To create another signal line from here we just press the right mouse button, keep it pressed and drag it to the block
but here we can drag the signal line as normal.

There is one useful tip about data types in Simulink, which is very basic and you should become familiar with:
You can right click on your model and select “Format” and “Port Data Types”.
It will display all the data types that are being used in your model so that you can
de-bug your model.
Let’s save this model now.
We cannot run it yet. We have to set our target to “Running Mode” first, so that is what we are going to do next.
To put our target in “Running Mode”, all we need to do is change the program switch ("Switch 1") to the left and press the “Reset” button once.
Now our target is running.
If we go back to the simulation model for the host PC, "Update" the model once (just ignore the warning for now), and press “Run”, you can see all the information displayed and a graph of the measured potentiometer voltage.
However, this model will only run for 10 seconds, so if we want it to run for much longer, we can change it to infinity by typing in “inf” and then “Save”.
This model will run forever so let’s see what happens.
Click “Run”.
If I adjust the potentiometer, you can see the changes in the voltage from 3.3 volts down to 0 and up again, like so.
We can zoom in to the graph by clicking on the “Binoculars” icon
and I’ll do that again.
So this is it for our first program for acquiring real time data into Simulink, using the RapidSTM32 blockset.
Just a final remark about the performance specifications of the blockset.
At the moment the maximum real-time data acquisition rate into Simulink and Matlab is around 400 hertz and it is possible to perform signal generation from Simulink to control the target and also to control hardware in a closed loop simulation.
Both settings have maximum update rates of about 200 hertz.
These specifications are based on USB HID communication protocol.
Faster speeds are possible.
The hardware settings for both loop simulations will be the subject of our next training tutorial.
For those of you who need further information, please visit www.aimagin.com.
There you can find data sheets for the FiO Evaluation Board and other information.
Thank you for watching.