Example | Top Previous

Examples Our embedded platform is dsPIC33EP256GP502 . Please see screenshot of model below: As you see above, in order to watch result, we used "probe" blocks. So we used "Modbus RTU/ASCII Dual Masters adaptor" as debugger hardware. This hardware connects Target Uart2, and Uart2 controls RS485, TX_transmit Enable is controlled by RB11. Logic High will enable RS485 transmit and disable RS485 receiver. Please see our "emModbusServerDebugSetup" block settings below (only for debugging): Please plug into "Modbus RTU/ASCII Dual Masters adaptor" to your PC USB Port. And if you are the first time to use this adaptor, run software "ConfigTool.exe" to config debug/monitor tool: In above configuration, The first Uart setting must match Target including baud rate and physical interface (RS485/RS422/RS232). The second part setting can be different, but you must make sure parameter "PC Side USB/Bluetooth Serial Port Baud Rate" in "emModbusServerDebugSetup" block matches it. Double click block "emCustomCBlock1", we will see parameters settings for "emCustomCBlock" below: It means that there are 2 input ports which used name U1 and U2 and data type is int16, there are 2 output ports which used name Y1 and Y2 and data type is int16, Before you build this simulink model, you must create the firmware project by your IDE. and remember the firmware project directory name. In our example, it is microchip MPLAX IDE software, you must use MCC to configure timer1 as 1ms timer and interrupt enabled. You must use MCC to enable Uart2 with interrupt enabled and both "software Transmit Buffer Size" and "software Receive Buffer Size" =255 or 254. Timer1 interrupt priority is below UART (you can choose equal too) We put our MCC configuration file BasePrj.mc3 into example folder for your reference. You must modify according to your hardware. You'd better compile your firmware which is created by MCC to identify any error by MCC. After your "Modbus RTU/ASCII Dual Masters adaptor" connects to Target (dspic33) and PC USB, right click on any empty space of simulink model, pop up context menu, click on menu item "Build Embedded Target and open its IDE" It will start build, and popup dialog window to input base sampling period: Input your base sample time and click OK. If any error occurs, it will stop building, and display error information. The error block will display in Yellow color. If build successfully, it will popup window to ask you firmware directory for your IDE project. If you give out the correct IDE project directory, Simulink will open IDE software automatically. We search to "//Customized Step (loop) Code for Block: emCustomCBlock1 ------Start" in IDE editor, we will add code "Y1= U1+U2;" and "Y1= U1-U2;" as below: And you can compile firmware in your IDE, and program into Target by emulator IDE supported. We can use Simulink directly view results. By select stop time= inf, and click "Run" button. You can change U1 and U2 value when run time. you will see result below: Please open "Your embedded creator library folder"/examples/example14_emCustom.slx (You must change "PC Com Port for Debug or Monitor" in emModbusServerDebugSetup block according to your physical USB port number)