Motor Control Class: Lecture 3 - Input Commands

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Motor Control Class: Lecture 3 - Input Commands

19,415 Views
Daniel_Popa
NXP Employee
NXP Employee

In this third lecture of the motor control course we discuss about how we can read different analog or digital inputs to build a speed reference block generator in Simulink model that will set the desired speed command for the PI speed controller.

 

Main topics:

    - How ADC works;

    - How to build an application around ADC peripheral;

    - How to flash the application on the target microprocessor;

    - How to build an application around the GPIO peripheral;

    - How to use the FreeMASTER to test applications in real time;

    - Mixing ADC and GPIO model into a single reference speed block;

 

Objectives:

    - Understand how the ADC and GPIO works on MPC5744P and DevKit;

    - Learn how to program the Flash Algorithm on the microprocessor to allow Matlab to download the applications;

    - Implement from scratch Simulink models for ADC and GPIO for MPC5744P;

    - Setup FreeMASTER for real time data visualization;

    - Test your knowledge with a short quiz;

 

Watch these 3 videos and leave your comments and questions below.

 

PART1: ADC Programming

注意:中国观众可以使用此链接观看YOUKU上的视频

185572_185572.JPG1.JPG185570_185570.JPG2.JPG185571_185571.JPG3.JPG

 

 

PART2: GPIO Programming

注意:中国观众可以使用此链接观看YOUKU上的视频

185578_185578.JPG4.JPG185576_185576.JPG5.JPG185577_185577.JPG6.JPG

 

PART3: INPUT COMMANDS

注意:中国观众可以使用此链接观看YOUKU上的视频

185579_185579.JPG7.JPG185580_185580.JPG8.JPG

 

 

Additional information:

    - pdf attached with slides shown in these videos;

    - Simulink models used in these videos;

Original Attachment has been moved to: Lecture3---Simulink-Models.zip

Update revisions:

February 25, 2019

May 06, 2020

18 Replies

15,619 Views
hc17
Contributor I

Hi, Daniel. Today, when I tired to download the program from SIMULINK, the following problem was encountered, which said, "Loss Communication with CCP MCU. Please cycle power and try again". I'm wondering if there are problems with my hardware or some other problems. Days before, the procedure went well. But today, the communication cannot be established. Can you offer some help? Thank you. 

pastedImage_1.png

0 Kudos
Reply

15,621 Views
constantinrazva
NXP Employee
NXP Employee

Hello hc17@mails.tsinghua.edu.cn‌,

If it worked earlier and it no longer does, I'd check to see if the board is still on COM7. If it is and it still does not work, you can try and download a simple example from SDK using S32Design Studio, to make sure the board is ok.

Please let me know if it works or what fails.

Kind regards,

Razvan.

0 Kudos
Reply

15,618 Views
hc17
Contributor I

Hi, Razvan. Still haven't found the problem why the communication cannot be established. But I find the problem why the result was not multiples of 100, just because the program run too fast so that an overflow occurred. :smileyhappy:

Kind regards,

Chao

0 Kudos
Reply

15,621 Views
hc17
Contributor I

Hi, Razvan. Thanks for your reply. It works fine when I download the '.elf' file generated by SIMULINK using S32DS. But there seems to be something wrong when debugging using S32DS, where the variable 'SpeedCommand'  should be multiples of 100, just as the lecture indicated. The result was right in FreeMASTER yesterday.

pastedImage_2.png

pastedImage_3.png

0 Kudos
Reply

15,621 Views
mahdkhalid
Contributor III

Hi Daniel,

This seems to solve the problem. Thank you so much for the help.

15,621 Views
mahdkhalid
Contributor III

Hi Daniel,

I have done all the steps you asked. I have also tried the lecture 3 file uploaded here but it doesn't work. I went through the forum and the only thing that works is the "ADC1_mbd_rtw" file from this thread https://community.nxp.com/thread/454868#comment-920887

I am able to connect with FreeMaster if I use this file.

If I use any other file of my own or the lecture files uploaded, the FreeMaster connection does not work. Can you please help with this problem?

0 Kudos
Reply

15,621 Views
Daniel_Popa
NXP Employee
NXP Employee

Hi Mahd, 

Well that is helpful and i think i can help. Most likely we are using the the Power Architecture compiler that is shipped with S32DS 1.2 or newer right ?

In that case you need to apply this patch on top of the MATLAB toolbox: https://community.nxp.com/thread/451804#comment-916493 

The reason why FreeMASTER is not working is due the fact because the entire application is crashing. That is why it works with a pre-compiled application.

Let me know if this solve the problem.

Best regards,

Daniel

0 Kudos
Reply

15,621 Views
mahdkhalid
Contributor III

Hi Daniel
I have done all the steps that you mentioned in that very order. The FreeMaster just does not communicate with the board. It gives the can not detect the board information error.

0 Kudos
Reply

15,622 Views
Daniel_Popa
NXP Employee
NXP Employee

Hi Mahd, 

I know this might sound crazy - but can you try a different micro-usb cable ?

Best regards,

Daniel

0 Kudos
Reply

15,622 Views
Daniel_Popa
NXP Employee
NXP Employee

Hi Mahd, 

The oversimplified procedure is like this:

- first you need to flash the RBF file;

- then you need to program the application from Simulink - this will enable the FreeMASTER embedded support;

- lastly you open the FreeMASTER to connect with the target;

The FreeMASTER has 2 components:

- FreeMASTER UI

- FreeMASTER embedded driver - that is enabled by the code generation from Simulink.

If there is no application code on the target the FreeMASTER will not be able to connect since there is "nobody" to answer it back. That might be the reason why you are not able to connect with the target.

A guide for configuring the MPC5744P can be found here: https://community.nxp.com/message/943597 

Please check section related with MPC5744P.

Anyhow, please be aware that when using the MPC5744P and MOTORGD (the tower assembly) the UART1 pins are shared with MOSFET pre-driver enable pins. In that case you will have to use the FreeMASTER over the CAN in order to communicate with the target.

Hope this helps!

Daniel

0 Kudos
Reply

15,622 Views
mahdkhalid
Contributor III

Hi Daniel,

No I am not using both in the same time. I follow the steps of the video where I first load the bootloader and then open FreeMaster. When I press debug I see the following message on the console and when I open FreeMaster and use the simulink elf file it does not communicate with the board.

Error on debugger.png

Message on console after running debug^

Regards,

Mahd

0 Kudos
Reply

15,622 Views
mahdkhalid
Contributor III

Hi Daniel, Thank you for your reply.

I have rechecked the cable and the jumper configurations they seem to be correct. I am attaching the screenshots. There is one difference in my Debugger console which I have attached as well. I would be grateful for any helpSimulink settings.pngPorts.pngDebug Settings.pngError on debugger.png

Thanks,

Mahd

0 Kudos
Reply

15,622 Views
Daniel_Popa
NXP Employee
NXP Employee

Hi Mahd, 

I'm not sure i understand. You said that the FreeMASTER can't connect and hence you show me a screenshot of S32 Design Studio. Are you trying to access the target via OpenSDA from both FreeMASTER and S32DS in the same time ? That would not work since the UART can't be shared across the multiple processes.

Best regards,
Daniel

0 Kudos
Reply

15,622 Views
mahdkhalid
Contributor III

Hi, I have tried this tutorial thrice now for some reason my FreeMaster gives the following error

"Can not detect the board information the communication will be paused"

Error code: 0x80000101(Response timeout.)

0 Kudos
Reply

15,622 Views
Daniel_Popa
NXP Employee
NXP Employee

Hi mahdkhalid‌,

I'm sorry to hear that. In case you got this message:

pastedImage_1.png

there are a few potential problems:

- wrong PORTxxx configuration in the FreeMASTER

- cable not connected over the microUSB

- wrong settings for FreeMASTER in the Simulink model

- wrong jumper configuration on the board that does not power on the board.

Can you attach screenshots with your Simulink FreeMASTER configuration, FreeMASTER communication configuration and your PC Device Manager /Ports when the MPC5744P is powered on ?

Thank you!

Daniel

0 Kudos
Reply

15,621 Views
Daniel_Popa
NXP Employee
NXP Employee

So far nobody answered the quiz. Let us raise the stake!

All of you that will answer to correctly to these 3 questions by June 26 EOD GMT will be enrolled in a raffle with a chance to win an NXP Development Kit S32K144 or MPC5744P. The raffle will be organized on June 27.

The questions are in this video  Video Link : 7768 @3.40

Q1: Can you change the model to start with at 500 rpm speed reference after reset ?

Q2: To operate smooth in any conditions – the model needs an additional block. What would that be ?

Q3: The model hides a design flaw that needs to be address in the future videos. Can you foreseen that issue ?

0 Kudos
Reply

15,620 Views
aunsal89
Contributor II

I have just started going through your lecture vids which are very helpful. Could you let me know the answer (if you have yet to do so) even though it has been more then a year? :smileygrin:

0 Kudos
Reply

15,620 Views
Daniel_Popa
NXP Employee
NXP Employee

Hi aunsal89@gmail.com‌,

Sure, why not :-)

Q1: Can you change the model to start with at 500 rpm speed reference after reset ?

A1: The Simulink Data Memory Store block for Desire_Speed initial value needs to be changes for 1000 -> 500

Q2: To operate smooth in any conditions – the model needs an additional block. What would that be ?

A2: If one is going to analyse the model of the reference command, will see that when operation over the GPIO (push buttons to increase/decrease the command speed) the reference is given in steps. This is going to introduce a perturbation in the system that will force the speed control to follow a sudden change in reference. Ideally we need to give that command as a ramp/slope from the old value to the newest one in order not to stress the controller. This might be implemented with a dedicated RAMP block from AMMCLIB or with a simple FIR 

Q3: The model hides a design flaw that needs to be address in the future videos. Can you foreseen that issue ?

A3: This is more subtle. In this model there are 2 methods of getting the reference speed: from GPIOs or from ADC. The problem is that GPIO give a incremental command (relative to the last know position) while ADC/Potentiometer give an absolute information.

Within the application we have the capability to switch between these 2 modes of operation by changing on the fly the value of SpeedCommandSource variable with FreeMASTER. Then you do then the reference is switch from one value to the other which might be a very sudden change in direction. This can be addressed in 2 ways:

- allow mode selection only at startup when the motor is not moving

- implement Q2 answer suggestions.

Hope this helps!

Daniel