• AVR Freaks

Helpful ReplyHot!Simulink- connect to target with external mode

Page: 123 > Showing page 1 of 3
Author
borutp
New Member
  • Total Posts : 1
  • Reward points : 0
  • Joined: 2012/07/23 05:51:24
  • Location: 0
  • Status: offline
2012/07/23 05:57:40 (permalink)
0

Simulink- connect to target with external mode

Hi,
has anybody successfully connected to the dsPic target in Simulink through external mode while using Simulink dsPIC blockset? The dsPIC used is dsPIC33FJ128MC802.
Thanks, Borut.
 
 
#1
bizard
New Member
  • Total Posts : 6
  • Reward points : 0
  • Joined: 2015/02/25 02:24:52
  • Location: 0
  • Status: offline
Re: Simulink- connect to target with external mode 2015/07/20 07:24:39 (permalink)
0
Hi Borut,
I also tried to do this, everything seems to be ok, but nothing appeared on the simulink scope
 
hope this will work soon
bizard
#2
Lubin
Moderator
  • Total Posts : 396
  • Reward points : 5
  • Joined: 2007/03/31 07:38:15
  • Location: Bayonne, France
  • Status: offline
Re: Simulink- connect to target with external mode 2015/07/20 07:52:56 (permalink)
0
Hi Bizard,
 
The Blockset v3.37 enables External Mode as well as PIL through a serial channel.
 
The embedded model requires one UART configuration block to configure the UART channel on the target side.
The UART is set through the MICROCHIP menu in the Simulink menu bar (top). 
You might need to create a new model using this blockset release (or use the reset Configuration block to remove possible issues due to old model settings)
 
Lubin
 
#3
bizard
New Member
  • Total Posts : 6
  • Reward points : 0
  • Joined: 2015/02/25 02:24:52
  • Location: 0
  • Status: offline
Re: Simulink- connect to target with external mode 2015/07/24 04:55:12 (permalink)
0
Thanks Lubin,
The external mode  still doesn't work, I tried the configurations you suggested, the serial port is ok (I tried it with the picgui) I tried the example attached but no data acquired on the scope
 
Bizard
#4
Lubin
Moderator
  • Total Posts : 396
  • Reward points : 5
  • Joined: 2007/03/31 07:38:15
  • Location: Bayonne, France
  • Status: offline
Re: Simulink- connect to target with external mode 2015/07/24 07:30:31 (permalink)
0
Hi Bizard,
 
Few points:
1) Activate the "Verbose" option to check whether connection is Ok or Not. (see attached below)
2) If "Enable data upload" is not enabled, the external mode only allows to set parameters (switch position, modify gain, constants etc...). 
3) With data upload enabled, you should be able to see data on scope. Display is easier to use.
 
One remark with data upload: The bandwidth required by External Mode is quite high. If you need to log/visualize data with a high frequency, you might prefer the Matlab Tx block coupled with its picgui interface to retrieve data on Matlab side.
 
Attached are two models, one with data upload disabled (you could set the A4 pin with the switch once the target is connected to Simulink), the other one with data upload enabled (you should see the value on the digital display)
 
Lubin
 

 
Model with External-mode data upload disabled. User can swith parameters during real-time execution on the target (here the only parameters is the manual swith)

 
 

Attached Image(s)

#5
bizard
New Member
  • Total Posts : 6
  • Reward points : 0
  • Joined: 2015/02/25 02:24:52
  • Location: 0
  • Status: offline
Re: Simulink- connect to target with external mode 2015/07/24 08:26:57 (permalink)
0
Hi Lubin,
Thank you very much for your help, things are clear now, both models are working as expected
 
all the best
Bizard
 
 
#6
mecch
Starting Member
  • Total Posts : 12
  • Reward points : 0
  • Joined: 2009/07/23 08:54:32
  • Location: 0
  • Status: offline
Re: Simulink- connect to target with external mode 2015/09/14 08:29:48 (permalink)
0
Hi Lubin,
  I have tried the external mode to update signal, and down load data. But the data rate has to be very low, otherwise a message will appear in the Matlab command window complaining not enough memory.t
  But I never succeeded in exchanging data with the new gauge blocks in the R2015a's Simulink. The external mode  seems only work with simple switch and display blocks. Any suggestion to remedy this problem. 
 
Best regards
Chen
#7
apriddis
New Member
  • Total Posts : 13
  • Reward points : 0
  • Joined: 2016/06/13 10:30:10
  • Location: 0
  • Status: offline
Re: Simulink- connect to target with external mode 2016/07/12 16:53:28 (permalink)
0
I have a Microstick II as well as a PicKit 3 that I used for programming the microcontroller. Do I need to connect a separate serial port that reads the PIC UART output into a serial port on my computer, or can it communicate through one of my programmers? I've used external mode on arduino before and it just passes data back through the USB serial connection. Also, is there a tutorial or something that shows how to use the picgui?
Thanks,
#8
Lubin
Moderator
  • Total Posts : 396
  • Reward points : 5
  • Joined: 2007/03/31 07:38:15
  • Location: Bayonne, France
  • Status: offline
Re: Simulink- connect to target with external mode 2016/07/13 07:10:04 (permalink)
0
Hi Chen,
 
External mode with data upload enabled adds quite an overhead on the UART at each time step; possibly overloading the available bandwidth.
We privilege MathWorks internal solution like external-mode ; However for fast algorithm, I would recommend picgui if External Mode bandwidth & CPU load is not compatible with your application. 
Note that PICGUI does not provide parameters tuning. You might however add it by adding some logic within your model (see PICGUI doc from the blockset pdf starter guide).
 
Hi Andrew,
 
The External Mode or PIL simulation requires an UART communication. Microchip programmers do not include such a link. You must add an UART cable. You might pick one on the FTDI website. If you do have the Microstick Plus Development Board, you might use another (mini) USB cable for the UART link (UART óUSB converter is present on that board).
Please check the Quick Start Guide available within the Blockset installation folder for further input for PICGUI (DS50002238A-page 16).
There are also examples provided for External Mode (and PICGUI).
 
Lubin
#9
apriddis
New Member
  • Total Posts : 13
  • Reward points : 0
  • Joined: 2016/06/13 10:30:10
  • Location: 0
  • Status: offline
Re: Simulink- connect to target with external mode 2016/07/13 09:24:33 (permalink)
0
Thanks Lubin. You are by far the most helpful forum moderator of all time. Smile: Smile I had been looking for documentation online and didn't realize it was in the installation folder. I'll go over all of that and that will probably get me all the information I need. Thanks again for the great support. Do you know if there are any plans to release an OSX version of the blockset?
#10
Lubin
Moderator
  • Total Posts : 396
  • Reward points : 5
  • Joined: 2007/03/31 07:38:15
  • Location: Bayonne, France
  • Status: offline
Re: Simulink- connect to target with external mode 2016/07/15 02:11:09 (permalink)
0
Documentation provided is "only" a Quick Start Guide at this time. Hope however that you will find useful information. Please do not hesitate using forum for deeper technical questions.
 
There are no short term plans to support OSX version. But you might open a new forum thread with that question. Maybe if we have many requests, this might be done sooner.
 
Lubin
#11
apriddis
New Member
  • Total Posts : 13
  • Reward points : 0
  • Joined: 2016/06/13 10:30:10
  • Location: 0
  • Status: offline
Re: Simulink- connect to target with external mode 2016/07/19 10:54:29 (permalink)
0
I've been able to get everything to work now except true external mode. My UART connection works and everything seems to be setup correctly but when I try to connect to the device I get the following error: 
 
Error occurred while executing External Mode MEX-file 'ext_serial_win32_comm_no_acks_rtt':
ExtTargetPktPending() call failed while checking for target pkt
 
Any ideas?
#12
Lubin
Moderator
  • Total Posts : 396
  • Reward points : 5
  • Joined: 2007/03/31 07:38:15
  • Location: Bayonne, France
  • Status: offline
Re: Simulink- connect to target with external mode 2016/07/19 12:17:32 (permalink)
0
Hi Andrew,
 
This is little information to start with. If “everything” works : UART connection is ok for both direction, then the only problem might be a buffer overrun, a missed Rx interrupt missing incoming data, or a CPU overload.
 
  1. Check that your input/output buffers are big enough. Set a circular buffer implementation for both Rx and Tx implementation. Setting 256 bytes buffer length should be safe enough. Set interrupt priority as follow: UART Rx > UART Tx > 2. (2 correspond to the the Simulink scheduler priority level)
  2. Make sure you have no other block using the UART peripheral dedicated to External-Mode/PIL. (No UART Tx, UART RX or Tx-Matlab blocks)
  3. Make sure the UART COM setting is correct for the host, within the Microchip External Mode menu (see figure in previous post). You might verify with a scope that the host sends data to the target when connecting. (I think it send something like “EXT-MODE”)
  4. When you check your target UART setting, you might connect a simple Rx to a Tx block, adding a bias (+1) in between. Then open a terminal (RealTerm, TeraTerm..) and check that you get back ‘b’ when you press ‘a’…
No others ideas to check so far. For further help, please post your model or at least a screenshot with the complete report you obtain.
 
Lubin
#13
Hassan16
New Member
  • Total Posts : 9
  • Reward points : 0
  • Joined: 2016/07/24 15:03:20
  • Location: 0
  • Status: offline
Re: Simulink- connect to target with external mode 2016/07/27 04:38:51 (permalink)
0
Hi
Facing a problem when operating in external mode. Everything seems right but i got following error:


Error occurred while executing External Mode MEX-file 'ext_serial_win32_comm_no_acks_rtt':
Failed to connect to the target. Possible reasons for the failure:
a) The target is not switched on.
b) The target is not connected to your host machine.
c) The application for the model is not running on the target. You might have clicked the Stop button. If the Run button is not dimmed, click it. Otherwise, click the Build button, which downloads and runs your application on the target.
Caused by:
An error occurred attempting to open an rtIOStream. More detail may be reported in the MATLAB command window
========
 
I'm using explorer 16 development board with dsPIC33FJ256GP710A and Matlab Simulink. The only thing that changed in the Simulink file posted by Lunin is the chip number.
 
Thanks,Hassan
 
#14
Lubin
Moderator
  • Total Posts : 396
  • Reward points : 5
  • Joined: 2007/03/31 07:38:15
  • Location: Bayonne, France
  • Status: offline
Re: Simulink- connect to target with external mode 2016/07/27 04:51:43 (permalink)
0
Hi Hassan,
 
By "Everything seems right", do you confirm the 4 tests mentioned in the previous post are validated with your setup ?
Please let me know if any test described is not clear.
 
Is your host a PC or a MAC with an emulated windows ?
 
Lubin
#15
Hassan16
New Member
  • Total Posts : 9
  • Reward points : 0
  • Joined: 2016/07/24 15:03:20
  • Location: 0
  • Status: offline
Re: Simulink- connect to target with external mode 2016/07/27 05:09:42 (permalink)
0
Hi Lubin
 
I followed all the configuration setup but the final file that you posted it is not working for no reason even i bought two USB to serial cable RS 232 because i was not sure from them but same error i got for both.
 
I'm using windows 8.1 and the COM port is working as in the configuration picture. Also, i upload the simulink file to the target but when trying to work in external mode i got error.
 
Thanks
post edited by Hassan16 - 2016/07/27 05:19:45
#16
Lubin
Moderator
  • Total Posts : 396
  • Reward points : 5
  • Joined: 2007/03/31 07:38:15
  • Location: Bayonne, France
  • Status: offline
Re: Simulink- connect to target with external mode 2016/07/27 06:43:35 (permalink)
0
Hi Hassan,
 
Could you confirm that you get the UART working both side with a "normal" compiled model ?
See point 4: 
"When you check your target UART setting, you might connect a simple Rx to a Tx block, adding a bias (+1) in between. Then open a terminal (RealTerm, TeraTerm..) and check that you get back ‘b’ when you press ‘a’…"
 

 
You might use picgui if you do not have any terminal on your system. Use the "send" button to check that the model read value correctly.
 
Lubin

Attached Image(s)

#17
Hassan16
New Member
  • Total Posts : 9
  • Reward points : 0
  • Joined: 2016/07/24 15:03:20
  • Location: 0
  • Status: offline
Re: Simulink- connect to target with external mode 2016/07/27 16:34:04 (permalink)
0
Thanks for help Lubin. I got same error when i did what you said. Only TX and Rx blocks which are uploaded to the target but when i chose connect to the target i got same error.
 
Other thing i notice following comment in the command window:
Failed to open serial port '\\.\COM0'. The reported error code is: 2 or 0x00000002. Possible causes are:
a) The target is not powered on.
b) The specified port number is not correct.
c) The specified bit rate is not supported by the host machine.
d) The previous connection was not closed correctly. If this is the case, you may need to re-start MATLAB.
Starting programmation of Micros.hex on 33FJ256GP710A
 
=====================
 
In external mode configuration the COM11 is appeared while in the command window, Matlab trying to open COM0.
is that mean matlab is not seeing COM11 as the required COM? if so why in the External Configuration COM11 is the only COM available. BTW COM11 is same COM as in the device manager window.
I cant upload image or matlab file to become easy to understand which is need permission.
#18
Lubin
Moderator
  • Total Posts : 396
  • Reward points : 5
  • Joined: 2007/03/31 07:38:15
  • Location: Bayonne, France
  • Status: offline
Re: Simulink- connect to target with external mode 2016/07/28 01:32:43 (permalink)
0
Hi Hassan,
 
I am not completely clear about what works and what does not work.
 
Validate your hardware setup and UART connection WITHOUT EXTERNAL-MODE. (I am not clear if that is done on your side). If/Once validated, go to the ‘Last’ section below.
 
First,
I suggest you to use a standalone model with the simple UART Tx-Rx model as shown above.
Such model should send continuously on the Tx pin the latest value+1 received on the Rx pin. Once your model is running on a board, connect to the target with either your preferred terminal (free ones like realterm, teraterm) and verify the model behavior. If you do not have a terminal installed, go directly to the Second step.
 
Second,
Does matlab handle properly COM port with your setting: Make the same test from MATLAB using blockset “picgui” interface. (click RAW button at bottom left to disable protocol decoding)
 
Third,
Remove any UART Rx and Tx block from your model (sharing same UART pin than the one use for Ext-Mode), just keep the UART config block which will be used by the External-Mode. Note that this UART channel must be use exclusively to External-Mode. Then set the External Mode setting from the Simulink-Microchip menu bar.
 
Last:
This not crystal clear, but external mode seems capricious with older matlab release. With release prior to (2016?), it seems that once External-Mode opened an UART connection with defined settings, any settings change will not be taken into account until a MATLAB close and restart... 
If you use such "old" matlab, try to set Host UART setting correctly at first connection attempt.
 
Another point:We did not tested Ext-Mode with Windows 8 setup, as well as virtual windows (for OSx).
 
The message your reported (Mixing up COM0 with COM11) is weird. I would be interested you to perform a test with picgui interface to test windows-8-MATLAB behavior with COM port (see step 2 above).
 
Which Matlab release are you working with?
 
Lubin
#19
Hassan16
New Member
  • Total Posts : 9
  • Reward points : 0
  • Joined: 2016/07/24 15:03:20
  • Location: 0
  • Status: offline
Re: Simulink- connect to target with external mode 2016/07/28 06:38:09 (permalink)
0
Lubin
Hi Hassan,
 
I am not completely clear about what works and what does not work.
 
Validate your hardware setup and UART connection WITHOUT EXTERNAL-MODE. (I am not clear if that is done on your side). If/Once validated, go to the ‘Last’ section below.
 
Second,
Does matlab handle properly COM port with your setting: Make the same test from MATLAB using blockset “picgui” interface. (click RAW button at bottom left to disable protocol decoding)
 
I did this part with picgui and i sent a data after that i got plot figure this is during normal operation not external mode. In external mode is not working.
 
 
Third,
Remove any UART Rx and Tx block from your model (sharing same UART pin than the one use for Ext-Mode), just keep the UART config block which will be used by the External-Mode. Note that this UART channel must be use exclusively to External-Mode. Then set the External Mode setting from the Simulink-Microchip menu bar.
===============
 I'm using UART config block with only with the Simulink program that i want to work with and i have uploaded the program but again does not work in external mode.
 
Last:
This not crystal clear, but external mode seems capricious with older matlab release. With release prior to (2016?), it seems that once External-Mode opened an UART connection with defined settings, any settings change will not be taken into account until a MATLAB close and restart... 
If you use such "old" matlab, try to set Host UART setting correctly at first connection attempt.
Another point:We did not tested Ext-Mode with Windows 8 setup, as well as virtual windows (for OSx).
The message your reported (Mixing up COM0 with COM11) is weird. I would be interested you to perform a test with picgui interface to test windows-8-MATLAB behavior with COM port (see step 2 above).
Which Matlab release are you working with?
 
Im using matlab 2016 and even i tried to figure out the problem with windows7+matlab 15 and got same problem.
 



Really appropriate your help
 
Thanks,Hassan
#20
Page: 123 > Showing page 1 of 3
Jump to:
© 2019 APG vNext Commercial Version 4.5