FiO BOard and RapidSTM32 Beginner`s Workshop

Report
FiO Boards and RapidSTM32
Beginners Workshop
www.aimagin.com
Objective:
Able to use FiO Boards and
RapidSTM32 Blockset to perform
"most common tasks"
immediatley
FiO Boards and RapidSTM32 Beginner's Workshop
www.aimagin.com
What are microcontrollers?
FiO Boards and RapidSTM32 Beginner's Workshop
www.aimagin.com
3GHz, 1TB HDD, 8MB RAM
USB, Wifi, LAN
Keyboard, Monitor, Mouse
FiO Boards and RapidSTM32 Beginner's Workshop
100MHz, 1MB HDD (Flash), 64kB RAM
UART, I2C, SPI, CAN, USB, LAN
Buttons, LCD
www.aimagin.com
what?
when?
how?
FiO Boards and RapidSTM32 Beginner's Workshop
www.aimagin.com
what?
when?
how?
FiO Boards and RapidSTM32 Beginner's Workshop
www.aimagin.com
Software
FiO Boards and RapidSTM32 Beginner's Workshop
+
www.aimagin.com
Minimum Requirements
...install in the order shown
1. Microsoft .NET Framework 3.5 or later
Free download from http://www.microsoft.com/net
2. Matlab + Simulink + Real-Time Workshop + Real-Time
Workshop Embedded Coder R2009a or later
(R2011 or later Real-Time Workshop = Simulink Code,
Real-Time Workshop Embedded Coder = Embedded
Coder)
3. Keil RVMDK R4.13a or later
Free download from
https://www.keil.com/demo/eval/arm.htm
4. RapidSTM32 Blockset
Free download from https://www.aimagin.com/download/
FiO Boards and RapidSTM32 Beginner's Workshop
www.aimagin.com
http://aimagin.com/learn/index.php/Getting_Ready
FiO Boards and RapidSTM32 Beginner's Workshop
www.aimagin.com
You will learn to ...
Implement a Low-Pass
Butterworth Digital Filter
Use PWM signal to control a
servo motor
Perform PIL Verification
Use photocell
(LDR) to acquire
light data in realtime into Simulink
Log data to microSD
Generate code for Non
FiO Board & Manually
modify C Code
Control external
hardware from Simulink
Use digital
output to
drive LEDs
Display status on a
character LCD
Real-Time DAQ and data
plots in Simulink
FiO Boards and RapidSTM32 Beginner's Workshop
www.aimagin.com
Let's Begin
FiO Boards and RapidSTM32 Beginner's Workshop
www.aimagin.com
Case studies:
Design an automatic light switch controller.
Auto OFF during the day
FiO Boards and RapidSTM32 Beginner's Workshop
Auto ON at night
www.aimagin.com
Photocell (LDR) Circuit
Vin = 3.3V
The brightness level relates to Vsense and Rphotocell
R 2.2KOhm
as follows:
Vsense = Vin * Rphotocell / (Rphotocell+2200)
Photocell (LDR) resistance
Rphotocell varies as a
function of brightness.
FiO Boards and RapidSTM32 Beginner's Workshop
www.aimagin.com
Warning!!!
FiO Boards ADC only accepts between 0 - 3.3V DC.
Higher voltages will cause permanent damages to the system.
FiO Boards and RapidSTM32 Beginner's Workshop
www.aimagin.com
System Concept
Acquire Real-Time Data into Simulink
Target
Host PC
Plot Graphs
ADC CH13
= Pin C3
USB (HID)
FiO Boards and RapidSTM32 Beginner's Workshop
www.aimagin.com
Analog to Digital Converter
(ADC)
Analog
Sensors
(Pressure,
Temperature
, Distances,
etc.)
FiO Boards and RapidSTM32 Beginner's Workshop
Voltage (03.3V)
www.aimagin.com
The circuit diagram
3.3VDC
GND
Vsense
FiO Boards and RapidSTM32 Beginner's Workshop
www.aimagin.com
Target Simulink Model
FiO Boards and RapidSTM32 Beginner's Workshop
www.aimagin.com
Commonly Used Steps Before Build
•
•
Update Diagram Twice:
Check sample time (Ts) of all blocks are
correct.
Set target in USB IAP Mode:
Use request_productinfo('usb', 'name')
command
FiO Boards and RapidSTM32 Beginner's Workshop
www.aimagin.com
USB In-Application Programming Mode
FiO Boards and RapidSTM32 Beginner's Workshop
www.aimagin.com
Help Please
help rapidstm32_blockset
FiO Boards and RapidSTM32 Beginner's Workshop
www.aimagin.com
Host PC Simulink Model
FiO Boards and RapidSTM32 Beginner's Workshop
www.aimagin.com
Run User Custom Program Mode
FiO Boards and RapidSTM32 Beginner's Workshop
www.aimagin.com
Running the System
FiO Boards and RapidSTM32 Beginner's Workshop
www.aimagin.com
Questions?
•
•
•
What voltage range is "Day"?
What voltage range is "Night"?
How would you design the "ON" / "OFF"
algorithm?
FiO Boards and RapidSTM32 Beginner's Workshop
www.aimagin.com
Running the System - Explain
Night
Threshold
2VDC
Day
FiO Boards and RapidSTM32 Beginner's Workshop
www.aimagin.com
The "ON" / "OFF" algorithm
threshold = 2; %volts
LEDON = 1;
LEDOFF = 0;
if (vin>threshold)
cmd = LEDON;
else
cmd = LEDOFF;
end
FiO Boards and RapidSTM32 Beginner's Workshop
www.aimagin.com
System Concept
Testing Algorithm
Target
Host PC
ON/OFF
Algorithm
Plot Graphs
+ ON/OFF
ADC CH13
= Pin C3
USB (HID)
FiO Boards and RapidSTM32 Beginner's Workshop
www.aimagin.com
Host PC Simulink Model
FiO Boards and RapidSTM32 Beginner's Workshop
www.aimagin.com
Running the System
Vin
Threshold
2VDC
cmd
FiO Boards and RapidSTM32 Beginner's Workshop
www.aimagin.com
The Build Process Explain - 1
Source Files
(*.c, *.h)
Compiler
Assembly Files
(*.s)
Assembler
Assembly Files
(*.s)
Compile
Object Files
(*.o)
Object / Library Files
(*.o, *.lib, *.a)
Linker
Executable Files
(*.hex / *.bin)
Load/
Burn
FiO Boards and RapidSTM32 Beginner's Workshop
www.aimagin.com
The Build Process Explain - 2
Keil
RVMDK
Matlab/
Simulink
Source Files
(*.c, *.h)
FiO /
RapidSTM32
Compiler
Assembly Files
(*.s)
Assembler
Assembly Files
(*.s)
Compile
Object Files
(*.o)
Object / Library Files
(*.o, *.lib, *.a)
Linker
Executable Files
(*.hex / *.bin)
Load/
Burn
FiO Boards and RapidSTM32 Beginner's Workshop
www.aimagin.com
System Concept
Turning LED ON / OFF from Simulink
Target
Host PC
Algorithm
Plot Graphs
+ ON/OFF
ADC CH13 = Pin C3
ADC
USB (HID)
LED
ON/OFF
cmd
FiO Boards and RapidSTM32 Beginner's Workshop
www.aimagin.com
Target Simulink Model
FiO Boards and RapidSTM32 Beginner's Workshop
www.aimagin.com
Host PC Simulink Model
FiO Boards and RapidSTM32 Beginner's Workshop
www.aimagin.com
Try the following
simulation !!!
FiO Boards and RapidSTM32 Beginner's Workshop
www.aimagin.com
Things
to note
1.
Communication Architecture Explain
Native Simulink simulation
is NOT real-time
FiO Boards and RapidSTM32 Beginner's Workshop
www.aimagin.com
Things
to note
2.
Communication Architecture Explain
Target
Host
Very Accurate Timing
Poor Real-Time
Performance
FiO Boards and RapidSTM32 Beginner's Workshop
www.aimagin.com
How to make Simulink simulation real-time?
FiO Boards and RapidSTM32 Beginner's Workshop
www.aimagin.com
Poor Timing
Very Accurate Timing
Target
Host
RX
RX
5
2
DO
DO
6
3
TX
FiO Boards and RapidSTM32 Beginner's Workshop
1
4
TX
www.aimagin.com
How to make Simulink simulation real-time?
FiO Boards and RapidSTM32 Beginner's Workshop
www.aimagin.com
Play dumb
Very Accurate Timing
Target
Host
RX
RX
5
2
DO
DO
6
3
TX
1
4
TX
Wait for correct time step
FiO Boards and RapidSTM32 Beginner's Workshop
www.aimagin.com
Both target & host start in wait (RX) state.
Target
Host
RX
RX
5
2
DO
DO
6
3
TX
FiO Boards and RapidSTM32 Beginner's Workshop
1
4
TX
www.aimagin.com
Solution
Target
Host
RX
RX
DO
DO
TX
TX
Force Output
FiO Boards and RapidSTM32 Beginner's Workshop
www.aimagin.com
communication architecture controls
Real-Time Simulation
FiO Boards and RapidSTM32 Beginner's Workshop
www.aimagin.com
Human Interface
Device
USB
63 bytes per data
packet
HID Protocol Blocks
No special driver needed
Same as
Maximum 1,000
packets per second
FiO Boards and RapidSTM32 Beginner's Workshop
www.aimagin.com
Limitations when using USB HID
From Target -> Host maximum 1kHz
FiO Boards and RapidSTM32 Beginner's Workshop
www.aimagin.com
Limitations when using USB HID
Between Target <-> Host maximum 200Hz.
FiO Boards and RapidSTM32 Beginner's Workshop
www.aimagin.com
Limitations when using USB HID
USB HID packet is 63bytes maximum.
FiO Boards and RapidSTM32 Beginner's Workshop
www.aimagin.com
What happens when the photocell
output is very noisy?
Sensor affected (shadowed) by a
tree or clound.
FiO Boards and RapidSTM32 Beginner's Workshop
www.aimagin.com
How
would
you
solve
this
problem?
FiO Boards and RapidSTM32 Beginner's Workshop
www.aimagin.com
Fourier Transform
Time
Domain
FiO Boards and RapidSTM32 Beginner's Workshop
Frequency
Domain
www.aimagin.com
Simulation Study
FiO Boards and RapidSTM32 Beginner's Workshop
www.aimagin.com
Simulation Results
FiO Boards and RapidSTM32 Beginner's Workshop
www.aimagin.com
Fast changing
(high frequency)
signal component
+
Slow changing
(low frequency)
signal component
Low frequency
component
Low Pass
Filter
High frequency
component
FiO Boards and RapidSTM32 Beginner's Workshop
www.aimagin.com
System Concept
Implementing Low Pass Filter
FiO Boards and RapidSTM32 Beginner's Workshop
www.aimagin.com
System Concept
Adding Low Pass Filter
Target
Host PC
Plot Graphs
+ ON/OFF
ADC CH13 = Pin C3
ADC
USB (HID)
2 LEDs
ON/OFF
cmd
FiO Boards and RapidSTM32 Beginner's Workshop
Lowpass
FIlter
ON/OFF
Algorithm
www.aimagin.com
Target Simulink Model
FiO Boards and RapidSTM32 Beginner's Workshop
www.aimagin.com
Host PC Simulink Model
FiO Boards and RapidSTM32 Beginner's Workshop
www.aimagin.com
Running the System
FiO Boards and RapidSTM32 Beginner's Workshop
www.aimagin.com
Advantages of designing and
testing algorithm in the Host PC?
Any one???
FiO Boards and RapidSTM32 Beginner's Workshop
www.aimagin.com
Answers: Fast 'n' Easy
FiO Boards and RapidSTM32 Beginner's Workshop
www.aimagin.com
How certain are you that the actual
embedded system will perform
exactly as simulated?
FiO Boards and RapidSTM32 Beginner's Workshop
www.aimagin.com
System Concept
Processor in the Loop (PIL) Verification
Explain
Target
Host PC
Compare
results
ADC CH13 = Pin C3
ADC
Lowpass
FIlter
FiO Boards and RapidSTM32 Beginner's Workshop
Lowpass
FIlter
www.aimagin.com
Target Simulink Model
FiO Boards and RapidSTM32 Beginner's Workshop
www.aimagin.com
Host PC Simulink Model
FiO Boards and RapidSTM32 Beginner's Workshop
www.aimagin.com
Running the System
Why do we need to
reset the target
before running
every time?
Answer on the
following slide.
FiO Boards and RapidSTM32 Beginner's Workshop
www.aimagin.com
Answer to previous question
To reset the initial condition of the
filters on the target to the same state
(zero) as on the host.
FiO Boards and RapidSTM32 Beginner's Workshop
www.aimagin.com
System Concept
Stand-Alone System Implementation - LCD
Toggle LED
Display
string
FiO Boards and RapidSTM32 Beginner's Workshop
www.aimagin.com
Target Simulink Model
FiO Boards and RapidSTM32 Beginner's Workshop
www.aimagin.com
Tips for using the LCD Block
Select Action
before output
characters to "Do
nothing" for none
first line display.
FiO Boards and RapidSTM32 Beginner's Workshop
www.aimagin.com
System Concept
Stand-Alone System Implementation LCD + Data
Logger
Log Data to
Micro SD Card
FiO Boards and RapidSTM32 Beginner's Workshop
www.aimagin.com
Target Simulink Model
FiO Boards and RapidSTM32 Beginner's Workshop
www.aimagin.com
The Challenge...
Can you design an auto-tune
(adaptive) ON/OFF algorithm?
FiO Boards and RapidSTM32 Beginner's Workshop
www.aimagin.com
Adaptive Algorithm Solution
FiO Boards and RapidSTM32 Beginner's Workshop
www.aimagin.com
The Real-Time Block
FiO Boards and RapidSTM32 Beginner's Workshop
www.aimagin.com
Non Real - Time
FiO Boards and RapidSTM32 Beginner's Workshop
www.aimagin.com
The Non - Real Time Simultion
Simulation
Do Something
FiO Boards and RapidSTM32 Beginner's Workshop
www.aimagin.com
Try the same simulation
with the Real-Time Block
(The Real-Time Block Explain)
FiO Boards and RapidSTM32 Beginner's Workshop
www.aimagin.com
The Real Time Block
No
Correct
time?
Yes
Do Something
FiO Boards and RapidSTM32 Beginner's Workshop
www.aimagin.com
FiO Boards and RapidSTM32 Beginner's Workshop
www.aimagin.com
System Concept
Driving an RC Servo
Target
Host PC
Drive Servo
Motor
Add a Real-Time
Block
USB (HID)
%Duty
Cycle
Display %
Duty Cycle
Slider Gain User Interface
FiO Boards and RapidSTM32 Beginner's Workshop
www.aimagin.com
How does an RC servo work?
20msec = 50Hz
10deg
10% Duty Cycle
80deg
40% Duty Cycle
FiO Boards and RapidSTM32 Beginner's Workshop
www.aimagin.com
Target Simulink Model
FiO Boards and RapidSTM32 Beginner's Workshop
www.aimagin.com
Host PC Simulink Model
FiO Boards and RapidSTM32 Beginner's Workshop
www.aimagin.com
Can you help find the range of %Duty Cycle for correct operation?
Degrees
% Duty Cycle
Minimum
Maximum
FiO Boards and RapidSTM32 Beginner's Workshop
www.aimagin.com
The Sample Time
FiO Boards and RapidSTM32 Beginner's Workshop
www.aimagin.com
CTRL + J
Base Sample Time
FiO Boards and RapidSTM32 Beginner's Workshop
www.aimagin.com
Multi-rate
Single
Tasking
FiO Boards and RapidSTM32 Beginner's Workshop
www.aimagin.com
How to allow users to input angles
in degrees instead of %DC?
FiO Boards and RapidSTM32 Beginner's Workshop
www.aimagin.com
FiO Boards and RapidSTM32 Beginner's Workshop
www.aimagin.com
Advanced "How To"
www.aimagin.com/learn/index.php/Advanced_"How_to
"
FiO Boards and RapidSTM32 Beginner's Workshop
www.aimagin.com
Manually Modify the generated
C Code
FiO Boards and RapidSTM32 Beginner's Workshop
www.aimagin.com
Where is the generated C
code?
FiO Boards and RapidSTM32 Beginner's Workshop
www.aimagin.com
model.mdl
model_rapidstm32 folder
header1.h
source1.c
FiO Boards and RapidSTM32 Beginner's Workshop
www.aimagin.com
model_rapidstm32
folder
stm32f10x_hwdrvlib.h
Hardware Driver Code
stm32f10x_hwdrvlib.c
model.h
Algorithms
model.c
FiO Boards and RapidSTM32 Beginner's Workshop
www.aimagin.com
How to Set up Keil RVMDK?
www.aimagin.com/learn/index.php/Advanced_"How_to"
FiO Boards and RapidSTM32 Beginner's Workshop
www.aimagin.com
Manually modifying C code allows applications with ...
No Blocks
Non - FiO Boards
Mass Products
FiO Boards and RapidSTM32 Beginner's Workshop
www.aimagin.com
FiO and RapidSTM32 is for ...
Rapid prototyping
Complex algorithm made easy
FiO Boards and RapidSTM32 Beginner's Workshop
www.aimagin.com
http://www.aimagin.com/learn/
http://www.aimagin.com/forum/
https://www.facebook.com/groups/fiousers/
http://www.youtube.com/rapidstm32
https://www.facebook.com/fioboard
[email protected]
FiO Boards and RapidSTM32 Beginner's Workshop
www.aimagin.com
For more information please visit
www.aimagin.com

similar documents