Home

Simulink PML Manual - Aerospace Mechatronics

image

Contents

1. A fiordable Comprehensive Transparent MIL PERSONAL MECHATRONICS LAB Personal Mechatronics Lab www PML4all org Matlab Simulink Support Package z oa D eee re res oii EUGEN eee a eme df File Edit View Simulation Format Tools Help DSHS tBOeleo tp 22 gt m foo Noma J 2HR 8 REIS Pic Master Initialization Subsystem Welcome Subsystem Generste Code Double Click LCD Display3 Switch Case This tinier shows how the A2D RS232 RTC and EEPROM l l i l modules can all be used together with the switch case block Invalid Option EEPROM RTC RS232 A2D Subsystem Subsystem Subsystem Subsystem Subsystem Created on Tue Jul 30 15 02 40 2013 Author Douglas Model Name AdvancedExample Ready 100 FixedStepDiscrete A 2013 M R Emami Contents Es ETT ee tee EE 2 E e e 2 EE ee H E ee en EE 2 2 A AISA le aE AET 2 22 SUC DUD SUC T OT EE 3 Ze ENNIO eg BEEN 5 2o SUD yS os 6 Ee 8 3 Support for individual blocks cece cescccceesececceecccceesececeuececeeuecceeensececeuececeenecesseeecessunecesseneceesenseeeeas 11 SST hRS 11 SELDE eege 11 PADCI E 12 Bi PDC COI E 12 E EECHER 12 EE 12 SLO EFPROMR EOU DE 13 SAFE E lag he EE 13 ig Me AO EE 13 GE EES 13 DN L10R9232 CUtOM e el 13 d a E Pr VW WE 13 eg Me CAO UN EE 13 Bode Ee ne 14 LRT EE EE 14 Da WR Ae 0 mee nee nee re ee ee ee ee en ee eT 14 e et te E 14 BT CUS OM Code LIDI aly E 14 IL IVE BO Bee e crxincne est
2. Help oe ed S XB Ss e gt a hun Noma D MCU Digital Input Read MCU Digital Input Read Enabled Subsystem Generate Code Double Click Virtual LCD Initialization Enabled Subsystem 100 T 0 00 FixedStepDiscrete Double click on each enabled subsytem block and set it up as shown below The removal of the input and output blocks automatically get rid of the ports on the corresponding blocks File Edit View Simulation Format Tools Help Deele leo E m hun Noma LCD Display Delsy Block FixedStepDiscrete The mask of each LCD display block should appear as below with the custom text being whatever you desire It is important to note that the code section must be output Likewise the delay can be set to any arbitrary number but for this example 500ms was selected e Block Parameters LCD Display exe MCU Peripheral mask link LCD Display operates in one of 2 modes either input or custom text In the input mode the block accepts integer inputs and writes them to the Icd screen In the custom text mode the user enters the custom text desired for each line of the Icd screen The user has the option of selected either one or two lines to clear the led before writing and to go to a specific led location before writing in any of the two modes The use of this block requires the LCDInit block to have been placed before it The code can also be placed either in the start outputs or terminate
3. and having jumpers on both JP6 and JP7 3 1 15 RTCRead This mask requires four parameters value digit block ordering and code location Value is chosen from a popup menu and allows the user to select from either Year Month Date Day Hours Minutes or Seconds Digit allows the user to select either the tens digit or the ones digit of the aforementioned value RTClInit block must be implemented to use this block 3 1 16 RTCSet This mask requires allows the user to reset all or set the date time time format AM PM and day of the week Reset all sets all values to 0 RTCInit block must be implemented to use this block 3 1 17 Custom Code Library The Custom Code library is very similar to the Simulink Coder library and includes some similar blocks Basically The System Start Outputs Terminate and Initialize blocks allow you to place any pic compliant C code into any of these four main sections of code The VersatileCustomCode block allows the user to select virtual inputs and outputs for block ordering as well as the specific code section Model Header and Model Source allow for custom code to be added to the model header or model source respectively EmbeddedCustomInitCode takes the name of a file in the current working directory and embeds the contents within the start function CustomInit Function takes the name of a C code puts that C code into a function creates a header for the function and then calls the function in the
4. and the simulation should be started Finally the user must click the play button on the control GUI to see the results display on the scope Note the Pic master block is only included to set the appropriate solver parameters The Driver board library was expanded to add a motor controller block This motor controller block takes the type of motor as a parameter Depending on the type of motor different options such as duty cycle direction and enable are provided as inputs to the block Putting the first input as a 1 turns on the motor whereas 0 turns it off Putting the second input as 1 makes the motor move forward whereas 0 makes it go reverse Duty cycle values 17 range from 0 4 All other motors can be controlled and monitored in a similar manner as shown by the unipolar motor above 3 3 Sensor Board Library DEE emm emm mg em e D E a ae a em a mg y w i Figure 3 Picture of the Sensor board The main purpose of the sensor board library is to monitor the signals of the sensros attached to the sensor board pictured above in Figure 3 An example of how to use the Input Monitor block in the sensor library is shown below Open SensorBoardInputMonitorExample in the Samples folder 18 WW SensorBoardlInputMonitorExamp File Edit View Simulation Format Tools Help Dep ize Input Monitor FixedStepDiscrete To monitor and control any input sensor double click the Input Monitor
5. block and select a sensor after connecting the sensor board a Sensor Board File Bootloader Help JF conti Temperature Sensor Switch Sensor 1 Switch Sensor 2 Phototransistor 1 Phototransistor 2 Comparator Module PIR Sensor Photodiode Resistive Sensor 1 CONNECTION Resistive Sensor 2 Cinnal Canaddtianina k eedle Open the scope block and press simulate Setting the simulation time depends how long the simulation will run for The scope block is shown below The top graph will display the signal while the middle and bottom graphs display the max and min respectively 19 Scope x a ajasa RRRA gt 1000 2000 3000 4000 FOO Time offset 0 3 4 Utility Board Library FUNCTION ELH Si GENERATOR KEE o o HALLING Hal SHl INIS odla ho De 4 FO FIGIN MREF MAN VREF Oo Ole gfo o z 4 eo Sle clilre 2 2s 12 12 OO OO OO OD OO OO OO AD7862 of ke RSENSE a Qoxz02 RESET CRR7RR RR Se d 1 al i Se 8 Utility Board v2 0 Figure 4 Overview of utility board 20 The utility board library is used to monitor either channel A B A B or the signal generated by the utility board pictured in figure 4 Below is a tutorial on how to use the Channel A block in the utility board library Open UtilityBoardChannelAExample in the Samples folder It should appear as shown below UtilityBoardChanne ee File Edit View Simulation Format Tools H
6. left justified as parameters The clock select determines what frequency the conversion will take place at If left justified is selected then the 8MSB of the 10 bit conversion result will be placed in ADRESH while the 2LSB will be placed in ADRESL If right justified is selected the opposite is true 3 1 3 ADCConvert This block simply converts and analog to digital signal and outputs it as a 10 digit number The user is able to select which channel he she wants to be converted and ADRESH and ADRESL will output from the top and bottom outputs respectively This block only functions when its input is true ADCInit must be placed in the model with this block and it is strongly advised to set the analog pins to input with an I O configuration block 3 1 4 EEPROMInitialize EEPROMInitialize allows the user to set the first 8 values of EEPROM memory by entering a matrix of length 8 3 1 5 EEPROMWrite This block functions in two modes Input or custom values mode The input mode accepts two inputs the first one being the value to be written and the second one being the 12 address to be written to In custom value mode the user inputs pairs of the form address value to be written to EEPROM 3 1 6 EEPROMRead This block allows the user to read any EEPROM value by selecting how many addresses they wish to read and inputted those addresses The outputs correspond to EEPROM values of the entered addresses 3 1 7 External Interrupt When
7. subsystem as shown below ple While P File Edit View Simulation Format Tools Help oe ed S Bl Ss pl p gt m hoo Noma LCD Display MCU Digital Di Input Read MCU Digital Input Read IC oom T 000 Turn on the Create Hex Code automatically and Burn Hex Code Automatically options under the Extra Features tab in the Pic Master block as shown below Then connect your microcontroller board ensure it is in program mode and then double click the generate code block This example will continually write the message You are pressing a key to the Icd while RB1 is high The complete model can be found in the model WhileloopExample mdl under the Samples folder Master mask link Define and configure PIC porperties to create a compliant c code Configuration Clock Frequency Extra Features Launch Code Report Create Hex Code Automatically Burn Hex Code Automatically 2 3 Subsystem Enable Tutorial Open a new model and set it up as shown below MCU Digital Input Read is found under the Digital I O library of Simulink PML blockset The Enabled subsystem blocks can be found under the Ports and Subsystems sublibrary under the Simulink library in the Simulink browser The Compare to Zero block can be found under the logic library Do not worry if there are currently input and output ports attached to the enable subsystem blocks we EnableSubsystemsExample File Edit View Simulation Format Tools
8. ISC7 O in C syntax The digital I O blocks are used to configure the I O pins and clear or set the output pins as well as to read the input pins Before using any of the write or read blocks the I O configuration block must be implemented with the appropriate array of pins for each port being selected A Matlab array takes the form 1 2 3 4 This block will essentially set or clear the aforementioned Tris bits in the program memory The MCU Digital Output Write block accepts any Simulink block as input s and will set the pin of the pic associated with the input port to whatever state the input port is in This input should be a boolean value Note this block only operates in the outputs function any initialization of pins must be done using a custom code block The MCU Digital Input Read block will output the state of the selected pins via its output ports at each simulation time step The extended I O blocks work in a similar fashion to the aforementioned blocks however the 12C Setup block must be used before setting the I O configurations Also the MCU must be in RUN mode for extended I O to function The MCU Digital Output Read block is a very different block intended for advanced users only The main premise of the block is to create a link between Matlab and the register watcher standalone program The use of the register watcher program requires a specific firmware 3 1 2 ADCInit This block takes in a clock select and either right or
9. LED_dspic cs lt 1x1 Simulink Config CustomlnitCode2_pic E mc make_rtw D CustomlnitCode_pic solver FixedStepDiscrete amp CustomInitCodeExample_pic stf pic tlc CustomlnitializationCodeExampl tmf pic tmf og DigitallnputWriteExample_pic DigitalOutputWriteExample_pic EEPROMInitializeExample_pic EEPROMReadExample_pic EEPROMWriteExample_pic EmbeddedCustomlInitCodeExam EN A EmbeddedCustomlnitializationC ExternalInterruptExample_pic Command History oF amp KeypadExample_pic clear LCDDisplayExample_pic ele D MultipleCustomlnitCodeExample och SM MultipleEmbeddedCustomInitCo gcb setup PlCDrivers_pic i i 2 gcb NumImport J RS232Example_pic Be pechen SI A Samples gcb NumInputPorts DI A sfun_x2_dspic BlockOrderingGui Dm deg eg 15 07 2013 4 33 PM D test_pic D 16 07 2013 10 18 AM 5 w Z pedit ert default Cd A ge PNR pedit ert_default_tmf F BlankBlock m medit ccopenfcn ST BlankBlock tlc as Och Details A cle d Start OVR Open a new Matlab window File Edit View Help O g a Enter search term Simulink AT Commonly Used Blocks Continuous E Discontinuities Ima Logic and Bit Operations ES ECH Lookup Tables User Defined Functions i Additional Math amp Discrete A Math RW Aerospace Blockset Operations Open the Si
10. at ct rer aes ci vate earnest gs snt nears E teeta es sewaenue seu tutvereaons 15 5 SONS Ol Board EID GOI Y E 18 Be LIEN IEW OA EUREN 20 1 Introduction 1 1 Overview The Simulink PML short for personal mechatronics laboratory block set was designed as an interface between Simulink and the following 5 PML boards Microcontroller board Driver board Sensor board Utility board and FPGA board The use of this block set requires a basic working knowledge of Simulink The main usage of this block set is to drag a few of the blocks into a new model connect the blocks together and then double click the generate code block The Simulink coder will then generate a C code compatible with the selected PIC and compile and burn the hex code directly onto the PIC if said options are selected Also this block set can be utilized to monitor the sensors on a sensor board or control the motors on the driver board 1 2 Features gt Open source modular design with easy to understand parameters for beginners Supports code generation for the PIC16f877 PIC16f887 and PIC16f1937 Includes virtual input and output options for block ordering Code Section parameter to give users added flexibility Custom code blocks to enable users to embed their own C code MICU Peripherals library to interface with Microcontroller board Driver Board Library to monitor and control motors Sensor Board Library with analog and digital inputs Utility Board Library complete with oscil
11. elp Ge Hga Average Channel A Signal Channel A FixedStepDiscrete Double click the channel A block The GUI below should appear File View Reset Calibrate Help Channel A Not connected VOLT DIV Display Soe Channel B ChA ChB Display Display AC ChAChB GND i d e GND VOLT DIV Voltage Average Press the play button after connecting the Utility board Signals should appear on the gui 21 la eil Utility Board Oscillosc File View Reset Calibrate Help RH VOLT DIV ETE VOLT DIV Display Display se AC Sine GND D GND a DC C Square Voltage Voltage 0 82 1 675 Average Average 0 49 0 162 Sr Display Display gt AC s Offs Ampl ChA ChB GND ao Pa e Dc ocase Voltage Voltage Dy 034 op o2v WI Average i Ai eS 8 Average emm les ars emm Next open the scope and run the simulation The voltage of channel A and average of channel A will appear on the scope The other blocks in this library work in a similar fashion to the channel A block shown above 22
12. function using the code location parameter Parameters Display Custom Text Number of Une Enter First Line Key Pressed Clear LCD Before Writing Go to LCD Location Before Writing Writing Location Hex number ie 40 0 Apply This example displays Key Pressed on the LCD when a key is pressed and Key not pressed when a key is not pressed The complete model can be found in the model EnableSubsystemExample mdl under the Samples folder 10 3 Support for individual blocks 3 1 MCU Peripherals Library Rs SS 2 go Sc E iH BOC Loo D m Lil Lt be D LP SN a RR ty La LA A a man i edel T PIC IOBLUS e AAE Fa EE LE Figure 1 The Microcontroller Board Every block in the MCU peripherals library corresponds and controls a module on the Microcontroller board pictured above For more information on each of the modules refer to the sections below or to the microcontroller board user manual 3 1 1 Digital I O Every microcontroller that is inserted into the MCU board will have a number of pins which can be set to input or output Traditionally to set a pin to input the user would set the associated TRIS bit in the program memory For example to set the pin RC7 to input one would write the line bsf TRISC 7 in assembly syntax or TRISC7 1 in C syntax 11 Conversely to set the pin RC7 to output one would write bcf TRISC 7 in assembly syntax or TR
13. ge provides a brief description of each of the modules 15 Module Description 1 Power Provides the necessary power for the controller side of the board It has a 2 1 mm jack fora 12 V adapter the voltage is regulated to 5V A 1 25 A protection fuse can also be found in this module 2 Computer Interface Provides a USB connector for communication with the PC The on board microcontroller PIC18F4550 resides on this module The PIC microcontroller is responsible for the PC Board communication 3 Unipolar Stepper Controller Provides the tools to control the speed and direction of the unipolar stepper motor It also provides the required terminals to drive the unipolar stepper motor when using an external microcontroller 3a Unipolar Stepper Driver Set of transistors and LED indicators that allow the user to verify which coil of the motor is being energized 4 DC 1 Controller Provides the necessary tools to control the speed and direction of the first DC motor 4a DC 1 Driver Set of transistors forming an H bridge Provides LED indicators to shows the direction in which the first motor is running 5 DC 2 Controller Provides the necessary tools to control the speed and direction of the second DC motor 5a DC 2 Driver Set of transistors forming an H bridge Provides LED indicators to shows the direction in which the second motor is running 6 Bipolar Stepper Controller Provides the necessary tools to control the speed and d
14. irection of the bipolar stepper motor It also provides the required terminals to drive the bipolar stepper motor when using an external microcontroller 6a Bipolar Stepper Driver Combination of DC 1 and DC 2 drivers connected by jumper J1 7 Brushless DC Controller Provides the necessary tools to control the speed and direction of the brushless DC motor It also provides the required terminals to drive the brushless DC motor when using an external microcontroller 7a Brushless DC Driver Combination of three half bridges connected to the phases of the motor It provides LED indicators to show the two phases that are always on 8 Servo Motor Controller Provides the necessary tools to control the movement of the servo motor 9 Mode Selector Switch to select between running the DC motors or the bipolar stepper motor LED indicators show what mode the board is on Table 1 Description of driver board modules 16 Open UnipolarMotorExample in the Samples folder The model should appear as shown below E UnipolarMotorExample File Edit View Simulation Format Tools Help Ir G M a Es Lntpolech cotog Unipolar Motor FixedStepDiscrete To monitor and control any motor in the Driver Board library involves three simple steps First the block must be double clicked to open the control GUI as shown below Kl Unipolar Motor Con mojm p STATUS Not Connected O Next the scope should be opened
15. loscope External Applications Library to access important standalone applications VVVV VV VV VV Automatic code generation block gt Automatic code report open option gt Automatic hex code generation and hex code burning 2 Operation 2 1 Installation To install the Simulink PML block set the folder SimulinkKPML must be set to the MATLAB working directory This folder is automatically installed when any of the PML applications are installed Note the folder SimulinkPML may need to be copied to a writable directory first Next the slblocks m script must be ran This script puts the Simulink PML library into the Simulink browser under the name Simulink PML block set The user must also ensure that the Microchip xc8 compiler is installed correctly and that the application xc8 exe is on the current MATLAB path This can be confirmed by typing xc8 exe in the MATLAB command window 2 2 Step by Step Tutorial 2012 File Edit Debug Parallel Desktop Window Help oO zs C Bh E current Folder c Users Douglas Documents VEAR2 Semester2 AERIOB Simulink PML Blockset REQUIREDFILES Diet Shortcuts Z Howto Add Z What s New Current Folder Oa xi sane Workspace ef J REQUIREDFIL 2 e f gt gt Sr Zi B Stack Base YM Select data to plot M L Name Name Value Min Max basic3_pic H ans lt hd struct gt amp basic4_pic T cm pic_main tlc Blinking
16. mulink library browser Click file gt new model Simulink Librar File Edit View Help O e Enter search term Z E Library Simulink PML block set R pp Digital UC Driver Board c i Simscape RM Simulink 3D Animation T Bi mcu e H i Simulink Coder open Applications Peripherals i RM Simulink Control Design SS i e e e D oli T S 8 RW Simulink Design Optimiza ia a Double Click RW Simulink Design Verifier RW Simulink Extras es Recompile E i Simulink PML block set g i Double Click Custom Digital VO Driver Board External Applications 3 MCU Peripherals i Miscellaneous DI Showing Simulink PML block set File Edit View Simulation Format Tools Help Doe SBS SD PLL pr m foo eeng I led Initialization LCD Display LCD Initialization LCD Display Generate Code Double Click 100 FixedStepDiscrete Add an LCD initialization block LCD Display block and generate code block to your model and Save it File Edit View Simulation Format Tools Help JE Bleas tla hun Noma xl lod Initialization LCD Display LCD Initialization LCD Display Generate Code Double Click 100 FixedStepDiscrete Link them together as such using the block ordering dialog parameter of each block The parameters box is accessed by double clicking the block To link blocks together hold control and click the first block followed by the second block Next choose the ap
17. n using either the CCP1 or CCP2 modules The use of this block requires RC1 and RC2 to be set as outputs and the period and CCPRxL values can be entered The CCPRxL value determines the duty cycle The prescalar for timer2 can also be set from the mask dialog 3 1 12 Capture This block sets either the CCP1 or CCP2 modules to capture mode The user can select when they want the capture of timer1 contents to occur The options are either every falling edge rising 13 edge 4th rising edge and 16th rising edge of RC2 The block ordering is purely for the initialization setup of timer 1 This block outputs CCPR1L and CCPR1H which will contain the contents of the last capture of timer1 3 1 13 Compare This block sets either the CCP1 or CCP2 modules to compare mode The user can select what value they want to compare TMR1 to be setting the CCPRxH and CCPRxL parameters TMR1 is a 16 bit timer so CCPRxH and CCPRxL should both be 8 bit numbers Next the mode can be selected from the drop down menu Low to high mode changes pin CCPx pin RC2 or RC1 from low to high when the compare values match up High to low mode does the exact opposite IRQ mode requests an interrupt service routine while special event trigger causes analog to digital conversion to run 3 1 14 RTCInit This block is used as the initialization for RTC RTCInit block requires I2C Setup block All RTC blocks rely on a DS1307 IC with lithium ion battery the appropriate 12C firmware
18. propriate pic from the choose a pic dialog parameter in the Pic Master block Double click generate code then open PiCusb and burn the hex file onto your desired PIC Alternatively you can also select the Burn Hex Code Automatically parameter in the extra features tab of the Pic Master block 2 2 While loop Tutorial Open a new Simulink model and name it WhileLoopTutorial Drag a Pic Master block and Generate code block from the Simulink PML block set to the new model This example will use the Pic16f877 and so it will be selected from the Pic Master block File Edit View Simulation Format Tools Help coe ed BSS Pee gt m foo Normal sl Generate Code Double Click 100 o FixedStepDiscrete Next drag a while subsystem block from the Ports and subsystems library under Simulink in the Simulink browser to your new model Then add an LCD Init block and MCU Digital Input read block and set the blocks as shown below File Edit View Simulation Format Tools Help neng ip gt hun Noma sl Inputs Hi Outputs RIX HU ROZ RO3 Ria RI RDG ROT Extended Inputs Extended Outputs LCD Initialization LO Configuration il MCU Digital Input Read While Iterator Subsystem Generate Code Double Click Ready 100 T 0 00 FixedStepDiscrete E Double click the While Iterator Subsystem block and drag an LCD Display block and MCU Digital Input Read block inside the subsystem Set up the
19. specified function of the main code 14 3 2 Driver Board Library WER a WER SR Tt ca SS E E ep A Hg a j P bes A e ae soos t Ale k A Jes sis 3 j Rz al A SH vw Ee a e Al e alt 5 E TE EE i i ue 3 E e g t i ke et vn ZP E g e ei E S S42 S E ttt o DA En he ka Et A a i 7 on ae p ep 6a em eg ER en a ER Ca ER I io o il IITIITT e es ep ES Ge ee SI UL en ka a TETTE ETI a i as A Ee a a a SECH SCH e CC KCL ok EEE aots asa soal zw Pk veggie o qo ee oo J o wi A TI osteo o ogesen d R kal zaspe 33 _ aooooc F RL ep bed tin Cow KS e di bam A mik T coccecss Dppppp Dppppp K Kaf i j Figure 2 An overview of the driver board The Driver Board V 3 0 has been designed with the user in mind It is an educational printed circuit board that offers a complete method to test and understand motor drivers The Driver Board is capable of running 2 DC motors 1 unipolar stepper motor 1 bipolar stepper motor 1 servo motor and 1 brushless DC motor and it provides the user the option of running the motors either manually using an external microcontroller or using the computer application software Figure 2 shows an overview of the complete driver board split into separate modules Table 1 on the following pa
20. the external interrupt block is double clicked a subsystem featuring a model source and model start block are shown The model start block simply sets up the interrupt and the actual Interrupt service routine can be modified under the inter function in model source It is assumed that external interrupts occur on RBO 3 1 8 Keypad The keypad block takes in an input purely for block ordering purposes It can be placed in either the start or terminate code locations The block will wait for the user to press a key and output the result as an unsigned char from 0 15 3 1 9 LCD Display LCD Display operates in one of 2 modes either input or custom text In the input mode the block accepts integer inputs and writes them to the Icd screen In the custom text mode the user enters the custom text desired for each line of the Icd screen The user has the option of selected either one or two lines to clear the Icd before writing and to go to a specific Icd location before writing in any of the two modes The use of this block requires the LCDInit block to have been placed before it 3 1 10 RS232 Custom Code The RS232 Custom Code block illustrates how to use blocks from the custom code library The user may change any of the code within the block to suit the needs of what should be outputted via the RS232 The use of this block requires the RS232Init block to be placed before it 3 1 11 PWM This block allows the user to create a pulse wave modulatio

Download Pdf Manuals

image

Related Search

Related Contents

Newstar keyboard/mouse support  Conceptronic Optical Travel Mouse  ACDC-100 TRMS 1000A AC/DC Clamp  Johnson Hardware 2060 SERIES User's Manual      取扱説明書  guía del usuario e información de garantía del parlante para ducha    Bedienungsanleitung  

Copyright © All rights reserved.
Failed to retrieve file