• AVR Freaks

Helpful ReplyHot!Simulink- connect to target with external mode

Page: < 123 Showing page 3 of 3
Author
RISC
Super Member
  • Total Posts : 5379
  • Reward points : 0
  • Status: offline
Re: Simulink- connect to target with external mode 2017/10/13 14:24:26 (permalink)
0
Hi,
Which baudrate is used in the UART ?
Be careful with UART...There is one significant silicon bug in dsPIC33fj256gp710 with was solved in dsPIC33fj256gp710A : the BRGH=1 should not be used with dsPIC33fj256gp710 as it may not operate.
 Please check the generated source code and search for the U1MODE or U2MODE register depending if you use UART1 or UART2.
If this is the issue, just buy a MA330011 PIM module and it will come with dsPIC33fj256gp710A .
you may also check the UART signal on an oscilloscope to see if the signal is OK.
Please also make sure you use the EXPLORER16 XTAL as source clock (not the internal oscillator) to garantee that it is within +/-2% of desired frequency.
Regards
 
#41
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/10/16 10:47:14 (permalink)
0
Hi RISC,
 
Thank you for your information.
 
I used baud rate of 9600 cycle/s for the UART. 
 
I had spent several days trying to test out the external mode but it was not successful despite numerous trying.   As said in my last post, I think that my UART communication from my explorer16 (with dspic33fj256gp710) to my laptop is OK as I can see some waveforms displayed with 'Simple Filter' demo example.  However, using demo program for the external mode, I always got error messages when I tried to connect to External Mode.  May be there was problem in the other direction of UART communication.  Not sure about that as I did not have time yet to try out the two ways communication as suggested by Lubin. 
 
I had looked at the generated c codes generated by the Simulink Embedded Coder and as reflected by many other people, these c codes are almost impossible to read and to understand and apparently these codes are generated from automation conversion process from Matlab codes to c codes.  As apparently, the program logics are lost during these automated conversion process,  program modification on these generated c codes will be very difficult.   Surprisingly, I found that in the generated c programs, there are a significant amount of content and efforts gearing for the 'External Mode' operation.
 
My original passion in using the Simulink Coder to save my time in hand written c programming dies down significantly due to the difficulty to understand its generated c codes and to modify them. A bunch of c codes that cannot be understand and to modify (though they work) or to integrate to other c programs have very limited usage.   The 'External Mode' and 'HIL' (Hardware in the Loop) is a good idea but apparently it is not easy to use and one has to write special program and to use special blocksets to use/demonstrate the desirable functions. (Logically, I think that any demo program can/should serve to demonstrate the external mode as a scope blockset in Simulink should be able to show the waveform during the hardware running when external mode is enabled.  Apparently, it is not as simple as that).     I suspect that these scenario is not unique just for Microchip chips but also apply to other popular chips such as Arduino and Raspberry Pi (I am thinking to buy  Arduino or Raspberry Pi platforms to try them out when my time is available).   
 
I will bear in mind what you suggested for further testing but I am tied up with something else at the time being and can only come back to this issue at a later time. 
 
Thanks again, and have a nice day. 
 
 
 
 
 
#42
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 2017/10/18 06:46:49 (permalink)
0
Hi Charles,
 
External Mode is supposed to work out of the box and it usually does once the UART in/out is set. Let me know if you get back to this issue if bidirectional UART test is ok.
Two common mistakes are:
  • UART Rx/Tx pin not set appropriately
  • UART Rx/Tx Interrupt priority level is below 2 (it should be set to 3 or higher, 5 is the preferred value)
If your UART test is Ok, please upload your External Mode project.
 
External mode is working great and is easy to use, but has one pitfall when going to higher rate applications: its bandwidth is still limited. If you need to log/view high rate data, use our picgui interface instead.
 
Regarding Simulink generated code, it is highly configurable. By default, it makes the generated code efficient at the expense of readability. I would advise to look at Simulink options for code generation.
One important point to keep in mind with Simulink subsystem: at code generation time you can imagine subsystem are flattened to have all blocks at the same level. Simulink coder will then determine optimal block ordering and collapse blocks whenever possible: for example two gains following each other might be optimized into one unique gain.
If you want to keep “subsystem” separated from each other, enable the “Atomic” option in the subsystem block. “Atomic” ensures the subsystem generated code is one unique C code block (i.e. not spread all over the project); at the expense of efficiency!
 
Lubin
#43
stshmang
New Member
  • Total Posts : 22
  • Reward points : 0
  • Joined: 2017/01/12 07:07:06
  • Location: Germany
  • Status: offline
Re: Simulink- connect to target with external mode 2017/10/19 04:42:20 (permalink)
0
Hello Lubin,
I am using the same model used in the post  but with dsPIC33fJ32202. I too face similar issues like Hassan. In teraterm when I tried the Point 4 you mentioned : to type a and get B did not happen. Instead a continous characters were typed which I had to force stop. With Pic Gui i tried and was worked pomn using RAW. But in plot buffer a value with 129 was plotted.
When I try to run the model with the counter fed to digital Output model with external mode I see following error displayed in matlab: 
***
Connecting... May take few seconds...
try to open 'COM4' at 460800bps... May take few seconds...
Port COM4 successfully open at 460800............OK
redefinition SerialCOM
redefinition SerialCOM
Failed to open serial port '\\.\COM4'. The reported error code is: 5 or 0x00000005. 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.
 
In the diagnostic viewer I got following error: please see attachment
 
I am using R2017a and windows 10 PC
 
Kindly assist or guide through this.
 
Warm Regards,
Aemika

Regards,
Aemika
#44
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 2017/10/19 06:35:31 (permalink)
0
Hi Aemika,
 
The chip you are using is a dsPIC 33FJ32MC202. Are you working with a Microchip board I could test here ?
 
Your overall model idea is good. The UART test you performed (with the commented block) is ok as well.
Few advices:
  1. UART baud error is -1.34%. At 460800, the lower the error the better...
    For testing purpose, I would advise a lower baud rate: 115200 should be enough here. Note that windows might have issue to keep-up with high baudrate (460800 seems reasonable however).
  2. The oscillator clocking the chip (Master Block) is set to "internal FRC" (7.37MHz). The FRC will add error to the UART baud rate.
    Don't you have an external oscillator or quartz on your board ?
    Otherwise, try at least to lower the UART % error ; set for PLL: 20.268e6 MIPS which provide 0.04% error on the UART. ( 20 MIPS * (1+1.34%) = 20.268 MIPS ) 
  3. Model Scheduler use interrupt with priority 1 and 2. Please set the UART Tx and UART Rx with priority above. For example set both Rx and Tx to 5. (UART 1 config block)
  4. Go to Code -> External Mode Control panel -> Signal & Triggering ->  Duration: set 1 instead of 1000. Otherwise the chip will grab 1000 points before sending them to the the host. You did not set a big enough memory in external mode to do it (memory is currently set to 256). Sending values 1 by 1 is ok here.
  5. Base rate model is set to 1ms (1kHz). As none of the blocks run at that speed, you might reduce it to 10ms. (Simulation -> Model Configuration Parameters -> Solver -> Additional parameters -> Fixed-Step size
 
Please check points 1 to 3 then validate the bidirectional UART transmission with a terminal. 
If you press 'a', you should get 'b' repeated with the same rate as the UART Tx block.
 
Once you get there, comment again Tx and Rx block to test External Mode.
 
Lubin
#45
stshmang
New Member
  • Total Posts : 22
  • Reward points : 0
  • Joined: 2017/01/12 07:07:06
  • Location: Germany
  • Status: offline
Re: Simulink- connect to target with external mode 2017/10/19 07:12:34 (permalink)
0
Hello Lubin,
I did the changes as suggested. However I have no external Clock. Also I checked that 460800 works fine when I manually configure UART pins and send data in MPLAB project. I tried with lowering baud bt still no change in the result. 
Hoe to enter 'a' in teraterm? because when i press a some weird character is displayed. I think some internal ASCII value.. I do not understand how to provide characters to be accepted. In MPLAB i wrote down a in script with quoted characters as follows:
const command_t CommandList[] =
{
{ 't', testfunction },
{ 's', start },
{ 'h', halt },
{ 'o', output },
{ 'a', accel },
{ 'r', setRef},
{ 'm', setMode},
};
 
And I am converting this as  char on = atoi(s); and so on to do the respective function. But here I have build my model, flashed and then in teraterm when I type a it outputs as in the attachment. (sequence of 3 characters per one input)
 

Attached Image(s)


Regards,
Aemika
#46
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 2017/10/19 08:07:11 (permalink)
0
Hi Aemika,
 
I am not sure to understand what you are trying to do with MPLAB X.
You compile your model and flash it directly from simulink do you ?
 
Maybe it worth testing first the Tx part: replace the UART Rx block with a free running counter block set with 7 bits. You might have to add a convert block between the free running counter and the UART Tx block to avoid datatype conflict.
 
Then you should see on your terminal: abcd...ABCD...124... so on...
 
Lubin
#47
stshmang
New Member
  • Total Posts : 22
  • Reward points : 0
  • Joined: 2017/01/12 07:07:06
  • Location: Germany
  • Status: offline
Re: Simulink- connect to target with external mode 2017/10/20 02:53:03 (permalink)
0
Hello Lubin,
With MPLAB I just gave a try to ensure baudrate and if my teraterm works as per the input. As I was wondering why the weird characters were displayed when i used model. THey are done seperately. No link between my program and model.
And yes I directly build model and have enabled Flash after build so it does program controller automatically.
 
Lubin
 
Maybe it worth testing first the Tx part: replace the UART Rx block with a free running counter block set with 7 bits. You might have to add a convert block between the free running counter and the UART Tx block to avoid datatype conflict.
 
Then you should see on your terminal: abcd...ABCD...124... so on...

 
 
I do not see abc or ABC its just again those wird characters. But the controller reponds to the teraterm, because even when the flashing is undergone the terminal displys unsual characters.
 
I tried with 115200 baud as well but no changes. 
Note( I am using serial to TTL  connector, among the 6 connections I use the Tx and Rx to connect to my controller board. ) I hope this is not the issue.
 
Apart from this I have no idea why is the External Mode not working or if the characters are not as expected without External Mode.
 
Kindly let me know if I am not in right path.
 

Regards,
Aemika
#48
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 2017/10/20 07:02:41 (permalink)
0
Hi Aemika,
 
You did not mentioned which board you were using.
If you are using the Microstick II board, then if A-B switch is set on B, then programmer is connected to pin 14 (RB5) and 15 (RB6) of your chip you are also used for the UART. Not sure UART might work in such configuration. 
Switching to A would solve the problem and free-up theses two pins.
 
Lubin
#49
grcatu
New Member
  • Total Posts : 6
  • Reward points : 0
  • Joined: 2019/03/26 15:30:10
  • Location: 0
  • Status: offline
Re: Simulink- connect to target with external mode 2019/10/11 04:06:25 (permalink)
0
Hi, a simple question.
If I compile my model in "normal mode" in simulink and then load it through MPLAB to the DSPIC, can I still see the online variables in simulink with the UART port running the simulation in "normal mode"?
#50
DenF
New Member
  • Total Posts : 2
  • Reward points : 0
  • Joined: 2019/04/22 03:56:07
  • Location: 0
  • Status: offline
Re: Simulink- connect to target with external mode 2019/11/10 14:54:51 (permalink)
0
Hello, Lubin!
I just try to use external mode. I try to use external mode on my model and use an example, but in both cases i see this error "Application BuildInfo does not exist: buildInfo.mat." I use MATLAB 2019b. Can you help me pllease with this problem.
Regards, Den
#51
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 2019/11/15 07:21:42 (permalink)
0
Hi Den,
 
Which example did you used ? I am willing to test with the same setting.
Thanks,
Lubin
#52
DenF
New Member
  • Total Posts : 2
  • Reward points : 0
  • Joined: 2019/04/22 03:56:07
  • Location: 0
  • Status: offline
Re: Simulink- connect to target with external mode 2019/11/17 02:37:59 (permalink)
0
I use "Microstick_II_PlusDevBoard_33EP128MC202_ExternalMode_R2015b" . Now i find the solution for this problem. This solution may be is not the best. After this error I add to path ModelName.X directory, wich contains "buildInfo.mat", and I do it every time I make a new model for external mode. I find another problem: all models for work with PIC are open too slow (it can takes for few minuts for very simple model). In this case and some times when there are problems with connection I see the same errors:
 
In MCHP_findCompilerPath
In coder.internal.stf.FileReader/parseSettings
In Simulink.filegen.internal.FolderSpecificationTokens
In Simulink.filegen.internal.FolderConfiguration
In RTW/getBuildDir
In coder.internal.toolstrip.HardwareBoardHandler/getBuildDirectory (line
170)
buildDirInfo = RTW.getBuildDir(modelName);
In coder.internal.toolstripHW.CustomHardwareBoardHandler/isExtModeBuilt
(line 225)
[this.BuildDir, this.BuildDirInfo] = this.getBuildDirectory();
In coder.internal.toolstripHW.CustomHardwareBoardHandler/isTargetDeployed
(line 332)
deployed = this.isExtModeBuilt();
In coder.internal.toolstrip.HardwareBoardHandler/getExtModeHWBoardContext
(line 44)
deployed = this.isTargetDeployed();
In coder.internal.toolstrip.HardwareBoardContext/refresh (line 51)
expectedContext = boardHandler.getExtModeHWBoardContext();
 
Thank you
Den
#53
Page: < 123 Showing page 3 of 3
Jump to:
© 2019 APG vNext Commercial Version 4.5