• AVR Freaks

Helpful ReplyHot!Simulink- connect to target with external mode

Page: < 123 > Showing page 2 of 3
Author
Lubin
Moderator
  • Total Posts : 397
  • 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 08:47:20 (permalink)
0
Hi Hassan,
 
The good news is that from now (5th post) you could upload pictures ;-)
 
I understand your hardware is working fine thus problem is only software.
After you configured the Ext-Mode panel, could you report the content of the field "MEX-file arguments" that you will find withih Simulink into:
Configuration Parameters (Ctrl-E) => Code Generation => Interface => Data Exchange, Mex-file arguments
 
You should have something like: "0 11 115200" where 2nd argument is the COM port used.
 
Thanks,
Lubin
#21
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/30 17:47:55 (permalink)
0
Hi Lubin
 
Regarding the content after setting (external mode) i got 1 2 115200 and second term is the same as the COM number in the device manager.
I have attached two pictures and Matlab file that i need to work with. ( tried tx and rx blocks only and same result).
 
Thanks,Hassan

Attached Image(s)

#22
Constantin Cristi
New Member
  • Total Posts : 9
  • Reward points : 0
  • Joined: 2016/08/07 22:39:53
  • Location: 0
  • Status: offline
Re: Simulink- connect to target with external mode 2016/08/09 01:43:00 (permalink)
0
Hi Guys,
Maybe you may find this link useful: https://www.youtube.com/watch?v=wuzLmORk1M0&feature=youtu.be
This is an External-Mode demo video based on the model you can find in "Examples" folder of the Simulink Blockset v3.38. 
#23
LukasB
New Member
  • Total Posts : 6
  • Reward points : 0
  • Joined: 2017/07/05 02:37:09
  • Location: 0
  • Status: offline
Re: Simulink- connect to target with external mode 2017/07/10 08:30:55 (permalink)
0
Hello,
I'm using the dsPICDEM MCLV-2 Board with the dsPIC33EP256MC506 Plug-In Module (PIM). My Goal ist using the PIL mode, but for now I'm just happy to get the UART Connection working.
 
Sending and receiving data works with HTerm (Terminal: I send an 'a' via Rx and get 'b' back on the Screen with bias+1 in between, just like Lubin described). Switching to External Mode is a struggle, I had the same error like apriddis (see below). A larger Reserved Memory (4000) in the External Mode Setup worked for me to get updates from the dsPIC to my Simulink "Display" but I was neither able to change the state of a Manual Switch nor can I get scopes working. The error is again the one from below with a high Reserved Memory (10000) or the following when its below (also to be seen in the attachment):
 
Not enough Memory on the target to process the packet: EXT_SELECT_SIGNALS
 
I don't know why 10000, it was just trial and error. The memory should be more than enough, as you can see in the diagnostics (see attachment).
 
I attached the working Test of UART and the not working Test of External Mode.
 
Thanks for your answers,
Regards Lukas
 
apriddis
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?


 

Attached Image(s)

#24
LukasB
New Member
  • Total Posts : 6
  • Reward points : 0
  • Joined: 2017/07/05 02:37:09
  • Location: 0
  • Status: offline
Re: Simulink- connect to target with external mode 2017/07/10 10:33:13 (permalink)
0
Hello,
 
I did another try. This time the Display and Scope worked in External mode, but still no changes on parameters/switches was possible (settings are grey, when I open e.g. a Constant block). The simulation works for some time but then again aborts with the known error (see attachment). I tried both a predefined Memory Size (10000) and Heap size (5000) and they behave the same. One time Matlab crashed while running.
 
I don't know what I can do anymore. Why can't I update my model during runtime? You can see my UART settings in the attachment of my earlier post.
 
I hope you can help.
 
Lukas

Attached Image(s)

#25
Constantin Cristi
New Member
  • Total Posts : 9
  • Reward points : 0
  • Joined: 2016/08/07 22:39:53
  • Location: 0
  • Status: offline
Re: Simulink- connect to target with external mode 2017/07/11 00:21:59 (permalink) ☄ Helpfulby Burgm 2017/07/11 00:36:20
5 (1)
Hi Lukas,
 
I tested your model, applied few changes and now it works fine. In order to tune some parameters using External Mode, you have to enable "Default Parameter Behaviour" as "Tunable" (see printscreen attached). 
I attached the modified version of your model, you can have a look (the greyed out blocks are yours). It's modified to work with Microstick2.
 
I have few suggestions for you:
- Use 70 MIPS for that dsPIC (or 60MIPS if you use internal osc). This way you will achieve better UART communication at 115200 Baudrate (this is the reason of unstable communication you experienced earlier).
- If you have a good UART-to-USB transceiver, you can also use a higher baudrate (I use 921600 and it works fine).
- Use external oscillator/crystal resonator if you have one. Internal oscillator has a higher clock-drift and is temperature-dependent. This way you will obtain a more reliable UART communication at higher baudrates. 
 
You can also have a look on "ExternalMode" model from Blockset installation folder, it's a very good example.  
 
Good luck,
Cristi
post edited by Constantin Cristi - 2017/07/11 00:31:48

Attached Image(s)

#26
LukasB
New Member
  • Total Posts : 6
  • Reward points : 0
  • Joined: 2017/07/05 02:37:09
  • Location: 0
  • Status: offline
Re: Simulink- connect to target with external mode 2017/07/11 05:43:29 (permalink)
0
Hi Cristi and everyone else interested,
 
thank you for the fast response. I tried the updated model. With the "Default Parameter Behaviour" on "inlined" the communication is now much faster and stable using the crystal resonator (8 MHz). The scope now updates very fast and the communication does not abort after some time. Very good.
 
But switching to "Tunable" Parameter Behaviour, I get the following (compare with the images in the attachment). A regular connection message, 16 times download of parameters and in the end the same error as before. The whole process takes around 20 seconds and I get no updates for my scope/display because I don't reach the state "connected".
 
From the updated model (of Cristi) I only switched back to my dsPIC and the corresponding Pins for UART and LEDs. So what is the problem with my setup? I have no idea. You can find the whole Diagnostics from the connection trial in the .txt file.
 
Thanks for helping me out.

Attached Image(s)

#27
Lubin
Moderator
  • Total Posts : 397
  • Reward points : 5
  • Joined: 2007/03/31 07:38:15
  • Location: Bayonne, France
  • Status: offline
Re: Simulink- connect to target with external mode 2017/07/11 06:49:28 (permalink)
0
Hi Lukas,
 
Could you try increasing your UART Rx and Tx priority:
Set Rx priority >= Tx priority >= 2. (I would advise Rx and Tx interrupt both set to 5).
model rate tasks run with a priority oscillating between 1 and 2. 
 
FYI, there is a possibility to reduce the number of tunable parameters: 
Set parameters you want tunable through matlab variables (for example, use G1,G2 in gain blocks, declare G1, G2 value in the matlab workspace...) . 
In Model configuration => Set Optimization -> Signals and Parameters -> Default parameter behaviour to inline (inline invariant signals). Go to Configure, and set theses variable as Global tunable parameters.
You could list model tunable variable with the command: >> get_param(gcs,'TunableGain').
 
Last, you can control manually parameters download with the menu: Code => External Mode Control panel => Batch download checkbox (see MathWorks help for further inputs).
 
Lubin
#28
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 2017/08/08 14:50:25 (permalink)
0
Hi Lubin and everyone on this forum
I am trying to get int32 data on the workspace from of a dspic, I have successfully plotted the signals on the scopes using external mode which works great but unfortunately I can't save to the workspace, I've also tried to record these data using the picgui (which should be the best solution) but it accepts only int16, an obvious way to get out of this problem is splitting the data into 2 chunks of 16 bits I tried that without success till now, it would be very nice if someone could help.
btw I also tried the pil solution and it also worked very well but it's quite slow.
 
thanks in advance
bizard
#29
Charles Lo
New Member
  • Total Posts : 10
  • Reward points : 0
  • Joined: 2017/09/10 14:49:42
  • Location: 0
  • Status: offline
Re: Simulink- connect to target with external mode 2017/09/14 15:14:20 (permalink)
0
Hi Lukas (and other readers if relevant), 
 
Your post on July 10, 17 said that you made your model worked in External Mode but you did not say how.
I downloaded your test2 model, deleted its PWM block (as the pic33fj256gp710 I used does not support PWM blocks), compiled it successfully, but was not able to connect it to external model.
I have been trying in the past several days trying to make my models work in external mode with my explorer16 board with a pic33fj256gp710 chip.
Error messages always came up saying,  "The model that you are trying to run in External mode does not match the application running on your target. .............  ".
I was able to use the UART blocksets to capture data either using the picgui or my Tera Term terminal.  So UART connection was fine but I am puzzled why connecting to External Mode was so difficult if not impossible.  I supposed that once the UART connection is correct, connection to external mode is a function that I can use.  It does not appear there is any thing I can modify or adjust for the external mode.
There had been so many posts in this forum telling the difficulties of connecting to external mode and I did not seem to get any solid solution so far. 
Please let me know
 
#30
Lubin
Moderator
  • Total Posts : 397
  • Reward points : 5
  • Joined: 2007/03/31 07:38:15
  • Location: Bayonne, France
  • Status: offline
Re: Simulink- connect to target with external mode 2017/09/18 13:03:56 (permalink)
0
Hi Lukas,
 
The model that you are trying to run in External mode does not match the application running on your target. ............. 
This output means that the connection is ok. If you disconnect your uart or set a wrong baud rate, you would get either a timout message or another error message mentioning that connection is not ok.
 
When the model is compiled, the c code contains model checksum. This checksum is compared with current model when PIL or external mode is started. Make sure you do not modify the model once compiled before connecting with External Mode. A script might modify some parameters.
One known issue is that the blockset will update the latest programmer which successfully flash the model, after model compilation, causing a checksum modification. However, this happen only for the first time you use programmer with the model. If you compile/program a model more than once using the same programmer, this update has no effect.
 
Last, you could get the model checksum with the command:
Simulink.BlockDiagram.getChecksum(gcs)
for current selected model. You might also replace gcs with 'youModelName.slx'. It might help to check values before and after compilation.
You should find the same checksum values within the source code as well as in file named ModelName_targ_data_map.m
 
Lubin
 
#31
Lubin
Moderator
  • Total Posts : 397
  • Reward points : 5
  • Joined: 2007/03/31 07:38:15
  • Location: Bayonne, France
  • Status: offline
Re: Simulink- connect to target with external mode 2017/09/18 13:11:05 (permalink) ☄ Helpfulby bizard 2017/09/23 02:08:13
0
Bizard,
 
We should have created a new thread for your question related to int32.
Current picgui dropped support for int32 as it was replaced by a support for single (32 bit) and double (64 bits) Floating point values.
Thus picgui support
  • 8 bit integers
  • 16 bits integers
  • 32 bits Floating Point values
  • 64 bits Floating Point values
The protocol is limited to 4 different data types. Thus either we drop 8 bit support to add 32 bit integers. Alternatively, we could add 32 bit integers side by side to 32 bit Floating Point values and ask users in the picgui interface what represent that 32 bit variable. Let's think about it.
#32
Charles Lo
New Member
  • Total Posts : 10
  • Reward points : 0
  • Joined: 2017/09/10 14:49:42
  • Location: 0
  • Status: offline
Re: Simulink- connect to target with external mode 2017/09/19 14:13:43 (permalink)
0
Hi Lubin,
 
Thank you for your reply for my external mode connection problem to explorer 16 Dev. Board, due to checksum inconsistencies between the connected hardware and the simulink model. 
Due to the error message came up with suggestion to compile and build the model, and to try to connect to external mode again, I tried many times before to compile and build the model immediately, but same error came up every time.  I tried the same thing today after receiving your reply but again same error message came up again.  I read past posts about the external mode connection problem and other people seems to get similar error message and they also had been saying that problem was not solved even after model was build and flash to the hardware again.  
I watched a microchip video about connecting to external mode using the Microstick Dev. Board and it seems to be so strict forward - once UART connection is OK, connecting to external mode happens just by clicking the connection to external mode button.  I guess that that should be as easy as that as there is nothing else an user can change or modify everything about the external mode connection.  
Please note that I am only using the Microchip demo program of the 'Explorer 16 Simple Filter' that was downloaded together with the dowloaded Microchip_Simulink blocksets.
One thing may be worth mentioning - my explorer 16 Dev. Board is quite old and I bought it may be 5 years ago.  May be that is the reason ? Although I still think that it should not be as when UART connection is OK, Simulink should be OK to 'talk' with the pic33 chip in any development board.   I notice that there is a Microchip hardware target file installed in the Simulink Coder and may be it does not support old explorer 16 Dev. Board ?  
At the time being, I can only use the UART gui to capture the data online which is still a very useful feature to me.  However, online parameter tuning, scope display and actuators control etc. are not possible without the 'External Mode/HIL' feature. 
 
#33
Constantin Cristi
New Member
  • Total Posts : 9
  • Reward points : 0
  • Joined: 2016/08/07 22:39:53
  • Location: 0
  • Status: offline
Re: Simulink- connect to target with external mode 2017/09/20 04:14:07 (permalink)
0
Hi Charles,
 
Please note that "Explorer 16 Simple Filter" example does not use External Mode and the Simulink Blockset is not actually related to a specific board but centered around supported dsPIC devices instead.
There is one interesting External Mode example entitled "Microstick_II_PlusDevBoard_33EP128MC202_ExternalMode_R2015b". This is the same model used in the video you previously mentioned. You can open that model and configure it to for your own device/board making sure you follow the same steps as those from the video and properly configure the External Mode settings together with an UART block. Make sure that the same UART is not also used elsewhere in your model and is used exclusively for External Mode communication.
Once the chip is flashed, if UART connection hangs-up, you can always apply a device reset and then reconnect External Mode for your model. It's not necessary to re-build and load the model if you don't make any change.
 
Please let us know if this works for you!
#34
Constantin Cristi
New Member
  • Total Posts : 9
  • Reward points : 0
  • Joined: 2016/08/07 22:39:53
  • Location: 0
  • Status: offline
Re: Simulink- connect to target with external mode 2017/09/22 06:32:27 (permalink)
0
Hi everybody,
 
Let me share two examples using External-Mode and Explorer 16/32 (see pics attached). These examples are also compatible with older Explorer-16 boards.
Please note that there are two versions: one is for Matlab R2012a or newer. The other one is for R2015b or newer. The second one uses a slider to tune one parameter (the slider is a widget introduced into Dashboard - Simulink Library starting with R2015b).
If you have any issue plotting the signals, try to reduce the number of scopes and change the value for "Limit data points to last xxx samples" (scope settings). Another important setting for External Mode can be found in Code->External Mode Control Panel->Signal & Triggering->TriggerOption->Duration. This determines the number of base rates samples to be collected in one single buffer on the dsPIC target.
 
Good Luck! 
Cristi
 
post edited by Constantin Cristi - 2017/09/26 05:56:16

Attached Image(s)

#35
Charles Lo
New Member
  • Total Posts : 10
  • Reward points : 0
  • Joined: 2017/09/10 14:49:42
  • Location: 0
  • Status: offline
Re: Simulink- connect to target with external mode 2017/09/25 11:38:59 (permalink)
0
Hi Cristi,
Thank you very much for providing your timely supports.  Sorry for my late reply as I was tied up with something in the last few days. 
For yr last suggestion to test the "Microstick_II_PlusDevBoard_33EP128MC202_ExternalMode_R2015b" example which is the same model used in previous Microchip video, I did try that may be 2 weeks ago.  As I do not have the EP128MC202 chip in my explorer 16 Dev. Board which is required for the example (as the model uses a high speed PWM module which is absent in my 33fj256gp710 chip),   I modified the example to exclude the use of the high speed PWM but tried to maintain other functions to show the external mode capabilities.  Same error message happened and I was not able to connect to the external mode. 
Thank you for providing the two new examples for the explorer 16 - external mode demonstration.  I have downloaded them and notice that both examples use high speed PWM modules again.  As my chip does not has high speed PWM module, I will again try to modify the examples so as to test them.  Will let you know the outcome once finished my testing.
Best Regards.  
 
#36
Constantin Cristi
New Member
  • Total Posts : 9
  • Reward points : 0
  • Joined: 2016/08/07 22:39:53
  • Location: 0
  • Status: offline
Re: Simulink- connect to target with external mode 2017/09/26 06:14:05 (permalink)
0
Hi Charles,
Please check the new models added to my previous post for the chip you mentioned. These examples use the following devices:
dsPIC33EP512MU810
dsPIC33FJ256GP710A
Development Board: Explorer 16/32 or Explorer 16 (PIM to MCU mapping + dev. board documentation added within device configuration subsystem).
Matlab version: R2012a or newer / R2015b or newer
Please let me know if now it works on your side.
 
All the best,
Cristi
#37
Charles Lo
New Member
  • Total Posts : 10
  • Reward points : 0
  • Joined: 2017/09/10 14:49:42
  • Location: 0
  • Status: offline
Re: Simulink- connect to target with external mode 2017/09/26 11:00:05 (permalink)
0
Hi Cristi,
I just tried your new model written for pic33fj256gp710a.
As my chip is pic33fj256gp710 (not the a version chip), I modified the Microchip master block to my chip.
Build process was successfully done with codes being flash to my chip in explorer 16 dev. board.  I could see the blinking pattern of the LEDs, with change of pattern by pressing different buttons.  
Then I used the top menu bar to go to the Microchip menu to use the 'External Mode Set Up' function.  I could see COM5 being enabled and was connected to explorer 16 com port.  Baud rate was the same as the UART config module.
So my next step was to click on the 'Connect to Target' icon to connect to external mode.  Again, error message appeared as below :-
"Error occurred while executing External Mode MEX-file 'ext_serial_win32_comm_no_acks_rtt':
Failed to connect to the target. A time-out occurred while waiting for the connection response from the target. Possible reasons for the time-out:
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.  ".
I saw this error message many times before, and apparently it seems to indicate that UART connection was not done properly.  However, as in the past testings, my UART connection had always been good and including this time obviously.   Anyway, I still followed the suggestion as in c) to 'click the build button, which downloads and runs the application in the target one more time.  Same error message appeared again when I click the 'Connect to Target' icon. 
I am curious that your new example model must/should have been able to connect to external mode in your explorer 16 Dev. Board when you wrote and tested the model,  and if so, my explorer 16 boards should have no problem doing the same thing.   But the same error message appeared again. 
May be the change of the chip to 710 from 710a created the external mode connection failure ?  
If you have any other suggestions, please let me know.
Thanks and Best Regards,
 
Charles
 
 
 
 
 
 
#38
Lubin
Moderator
  • Total Posts : 397
  • Reward points : 5
  • Joined: 2007/03/31 07:38:15
  • Location: Bayonne, France
  • Status: offline
Re: Simulink- connect to target with external mode 2017/09/26 11:26:46 (permalink)
0
Hi Charles,
 
I do not think the change from dsPIC33Fj710 to dsPIC33Fj710A would make a difference here.
 
You should check the bidirectional UART communication with the PC.
On the previous post on this thread, we propose adding three blocks (UART Rx - bias - UART Tx) to your current model, compile it and just check with an hyper terminal if the bidirectional communication is ok:
(sending 'a' should return 'b'). See post http://www.microchip.com/forums/FindPost/940952.
 
Lubin
#39
Charles Lo
New Member
  • Total Posts : 10
  • Reward points : 0
  • Joined: 2017/09/10 14:49:42
  • Location: 0
  • Status: offline
Re: Simulink- connect to target with external mode 2017/09/27 09:37:20 (permalink)
0
Hi Lubin,
 
I do not think that using the 710 chip rather than the 710a made the difference either.  In fact, the model worked with the 710 chip but it failed to connect to external mode with my explorer 16 board.
My UART communication is always OK from explorer 16 to my laptop as testing the simple filter example, I can see data displayed either with my Tera Terminal or with the picgui.  I did not try the bidirectioonal communication with the example with the previous post. 
I doubt that if UART communication fr explorer 16 to laptop is OK, UART communication fr laptop to explorer 16 should have no problem.   
I would still tried on your two ways communication example in these two days. 
Would let you know the outcome.
 
Thanks and Best Regards,
 
Charles
 
 
 
 
 
 
#40
Page: < 123 > Showing page 2 of 3
Jump to:
© 2019 APG vNext Commercial Version 4.5