How can I change the PIT's period by global variable in simulink. DEVKIT MPC5744P(MBD)

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I change the PIT's period by global variable in simulink. DEVKIT MPC5744P(MBD)

268 Views
Contributor II

Hi,I want to change the PIT's period by global variable in simulink.

when I use the constant in Period Value ,it's good running. but when I use a global variable in Period Value , the program in MPC5744P is stuck.   

The attachment is my model.

my matlab's vision is 2017b ,

and my MBD Tool's vision is V3.0.0.

1.png2.png

Labels (1)
5 Replies

20 Views
NXP Employee
NXP Employee

Hello hesander‌,

Unfortunately you can not change it dynamically, by using a Simulink variable - you could do it by adding custom code, and in your custom code use the variable name from Simulink, but being careful the code generation ends up naming your control variable the way you wanted it to be. If you have trouble doing this, let us know and we'll provide a short example on how you can do this. I'll try and see if we can set the PIT block in such a manner that you can use it in the intended way. I'll get back to you on that manner as soon as possible.

Kind regards,

Razvan.

0 Kudos

20 Views
Contributor II

Dear Constantin Razvan Chivu ,

thank you for your reply.Please show the example for me,it may help me to understand this Chip more quickly.

Best wish,

he

0 Kudos

20 Views
NXP Employee
NXP Employee

Hello hesander‌,

I have attached a model that is updating dynamically the PIT period, but doing so with custom code insertion (System Outputs block). In this custom block I have added the following code:

/* First deinit PIT driver, to modify a channel's period */
PIT_DRV_Deinit(0U);

/* Use the following function call only if you are using a channel from the same PIT instance 0 as the main loop uses */
/* This function is generated in mbd_main.c and it enables the PIT channel that controls the main loop */
pit0_init();

const pit_config_t pit0_InitConfig = {
.enableStandardTimers = true,
.stopRunInDebug = false
};

/* Un-gate pit clock*/
MBDT_SetPeripheralClockControl(PITRTI0_CLK, MC_ME_PERIPH_CONFIG_2,
MC_ME_PERIPH_CONFIG_2);

/* Initialize PIT */
PIT_DRV_Init(0u, &pit0_InitConfig);

/*! User channel configuration 0 */
pit_channel_config_t pit0_ChnConfig1= {
.hwChannel = 1U,
.periodUnit = PIT_PERIOD_UNITS_MICROSECONDS,
.period = a,
.enableChain = false,
.enableInterrupt = true
};

/* Initialize channel 1 */
PIT_DRV_InitChannel(0U, &pit0_ChnConfig1);

/* Set priority for PIT ISR */
INT_SYS_SetPriority(PIT_Ch1_IRQn, 20U);

/* Start channel 1 counting */
PIT_DRV_StartChannel(0U, 1U);

This does the following: 

Disable the PIT instance, to be able to reconfigure it's channel(s).

Reconfigure PIT0 channel0 (the PIT that controls the main loop) -- this needs to be called if instance 0 of PIT is used (e.g.: PIT0 channel1, PIT0 channel2). If other instances are used (like PIT1), this is not necessary.

Note: the discrete fixed step of the model (period of the main loop) is set to 10s on the model attached. If you keep increasing the PIT period in the main loop, you need to be careful of the following scenario: after the period of PIT0 channel 1 (that controls the blinking of the LED) reaches >10s, the LED will remain on its last state forever. This is due to the fact that every 10s, the PIT is disabled, its period is changed (added 0.5s), then the counter starts. But it does not reach the value for which it should generate the interrupt, as the PIT that controls the main loop (PIT0 channel0) is set to 10s, and in that function the PIT0 ch1 is disabled, reconfigured, and started again (counter being reset to 0).

Please let me know if this is what you wanted to see or if it isn't clear enough.

Kind regards,

Razvan.

P.S.: The model is within this zip - you can use 1234 as password; the community seems to have a bug where it won't let me attach a .slx or .mdl file, so I had to resort to updating a zip with password. Sorry for the inconvenience.

20 Views
Contributor II

Thanks for your help.It solved my existing problems.

0 Kudos

20 Views
NXP Employee
NXP Employee

Hello hesander‌,

Glad to be of help! Just remember to mind the timings if you are changing other PIT periods from inside the main loop, as it is itself triggered by a LPIT.

Kind regards,

Razvan.

0 Kudos