Please take a minute to review and accept our Terms of Use.
Welcome to the PLECS User Forum, where you can ask questions and receive answers from other members of the community.

Many technical questions regarding PLECS are answered on the Technical Solutions page of our website. Tutorial videos, specific application examples, and pre-recorded webinars are available on our YouTube page. Please follow us on LinkedIn for the latest Plexim news.

PIL model can't connect to the device target when allocation memory in C-script

0 votes
258 views

Hi everyone, I am simulating a cascade multi-level inverter and using C-script to calculate the switching angle by applying the Grey Wolf Optimization algorithm (GWO). In 'codegen' mode, the simulation seems correct, but when I convert to 'PIL' mode, the model can't connect to the device target. Then, I tested the c-script without code with the simple PIL model, it work, when I add the allocation memory function like the code below, I get the error like the image, and I can't simulate my model in the PIL mode. Is there any problem here with my allocation function with PIL? Thanks for your help.

#define SEARCHAGENTS 30
#define NUMBER_GENES     5

float **currentGeneration, **nextGeneration;
void AllocateMemory(void);

void AllocateMemory(void){
  int organism;
  currentGeneration =
    (float**)malloc(sizeof(float*) * SEARCHAGENTS);
  nextGeneration =
    (float**)malloc(sizeof(float*) * SEARCHAGENTS);

  for(organism=0; organism < SEARCHAGENTS; ++organism){
    currentGeneration[organism] =
      (float*)malloc(sizeof(float) * NUMBER_GENES);
    nextGeneration[organism] =
      (float*)malloc(sizeof(float) * NUMBER_GENES);
  }
}
asked Apr 23, 2023 by hang (20 points)
Can you post a complete model for debugging? You can always reach out to support@plexim.com if you don't want to post on the forum.

I suspect you have some kind of overflow/access violation happening.

Does your code run not in PIL mode (e.g. if you have an LED toggling in the model, does the LED toggle after you program the device)?  You can always run the code in CCS Debug and see if a run-time error or assertion occurs.

Thank you very much for your response,

I reduced the number of SEARCHAGENTS and NUMBER_GENES in my code and it works. According to your response, I think that this is a memory issue because my target device is kit LaunchPad XL MS TI28069M. But with the simulation result, I need the value of the two above variables at least like that. How could I solve this overflow memory problem?

Try and disable External Mode and/or reduce the "Target buffer size" parameter.  I would also try and reduce the overall complexity of your model to a minimum, and then add back required logic.
Thanks for your response. I have to use the PIL function, which requires an external mode via serial connection so I can't disable this mode. I will review my code in order to reduce the complexity of my model.

Please log in or register to answer this question.

...