How to put S32K MCU into sleep (low power mode)?

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

How to put S32K MCU into sleep (low power mode)?

Jump to solution
11,671 Views
eautopower
Contributor IV

With Simulink development, how can get S32K MCU into sleep?

Labels (1)
1 Solution
9,581 Views
mariuslucianand
NXP Employee
NXP Employee

Hello,

As a response for your question we have attached an example that allows the S32K144 to enter the Very-Low-Power Stop (VLPS) mode by using the Model Based Design Toolbox and by inserting some “Custom C code” inside a Simulink S-Function Blocks.

The functionality that we want to achieve is to put the processor in VLPS by pressing the SW3 button and to wake it up by pressing the SW2 button. When the processor will run into the VLPS mode the RGB led will light up red, otherwise it will light up green.

   Inside the archive code there are 5 files:

  • power_manager.c
  • power_manager.h
  • s32k_clock_init.c
  • mbd_s32k14_user_copy_required_files.m
  • test_low_power_s32k.slx

The first two files contains two functions that we need to configure the uC to unlock the low power modes (enable_low_power_modes()) and the other (go_to_sleep()) puts the uC into VLPS mode. The .m file contains the code that will copy the external files into the test_low_power_s32k_mbd_rtw folder.

 To run the example attached you need to follow these steps:

  1. Go to C:\MBDToolbox\mbdtbx_S32K\mbdtbx_s32k14\src\c_library (where the S32k toolbox is installed and replace the s32k_clock_init.c with the one in the archive)
  1. Go to C:\MBDToolbox\mbdtbx_S32K\mbdtbx_s32k14\mbdtbx_s32k14\mscripts\utils and replace the file mbd_s32k14_user_copy_required_files.m with the one from the archive. Open it and change the path highlighted with the one when you put the power_manager.c, power_manager.h, test_low_power_s32k.slx files as in the follow image. 

img4.PNG

  1. Open the project test_low_power_s32k.slx, build the model and program the S32k board. We used GCC compiler.
  2. How the program works: when the controller starts, it enters the RUN mode and the RGB led is turned on green. When you press the SW3 push button, the RGB led turns red and the processor enters VLPS mode. To wake up the processor the SW2 button must be pressed.

For measuring the actual current consumption of the uC, we desoldered the 0 ohm R117 resistor and placed an Ammeter on J15 (you don't need to do that). When the uC is in the RUN mode, the current consumption is about 35mA.

IMG_20170704_193458.jpg

When the uC runs in the VLPS mode, the consumption is about 30 uA. 

IMG_20170704_193532.jpg

I hope that this example helps you!

Marius Andrei

View solution in original post

19 Replies
9,498 Views
rathi_tg
Contributor III

Hello 

I am using a simple logic for power saving which is as follow

Press Switch3 Pressed  enter VLPS Mode.(No Callbacks are used)

Press Switch2 Pressed  enter RUN Mode.

and Led Blink to see the change in mode conversion.

The Program Runs well but when I add patch of MC3377xB Config Black to the Program I can enter Sleep Mode but unable to come back to Run Mode by Pressing SW2 but has to use Reset to enter Run Mode.

rathi_tg_0-1601912718774.png

 

Unable to figure how to use MC33771xB configure and Power Saving Simultaneously !!

Hope For Help

Regards 

Gopal Rathi

0 Kudos
9,426 Views
mariuslucianand
NXP Employee
NXP Employee

Hello @rathi_tg ,

Thank you for noticing this behavior!

I have investigated the issue and it seems that this behavior is related to the SPI blocking transfer. It uses the OSIF in order to count the timeout for the transfer. And basically, this enables a wakeup source for the interrupt. SO the workaround to solve that is to disable the SysTick Interrupt before entering the low power mode. 

The line of code that has to be added be for entering the VLPS is this one:

S32_SysTick->CSR = S32_SysTick_CSR_ENABLE(0u) | S32_SysTick_CSR_TICKINT(0u);

 

You can add this using the System Outputs block from the Simulink Coder library.

 

custom_Code.JPG

 

For testing purposes, I have attached the model in which you will find already the custom code inserted. I have tested the data acquisition on MC33772B and it works fine.

Now, independently of the noticed issue, I've found a lack in our toolbox that basically initializes the BMS more than once time, so please, if you want, you can update the attached mbdtargetmainlibss32k.tlc in the {S32K\mbdtbx_s32k} toolbox installed folder.

Hope this helps,

Marius

 

 

 

 

9,406 Views
rathi_tg
Contributor III

Hello  @mariuslucianand 

Thanks for your such a quick Reply!!

  I have used the above code and everything seems to work fine.

But i have encounter another issue while testing the cod.

The Scenario is as follow:

1) Connect Boards attach the battery pack  Establish communication. Status =0,pack Voltage=50

2) Now Press SW3 and enter Sleep Mode. Here the value of Status =?,pack Voltage=?(Observed on Freemaster)

3) Now Remove the battery pack and and press SW2 to enter normal mode .Here, the Value of Status=0  and Pack Voltage is 50.

But as per my understanding in step three the status value should be 5 and Pack Voltage to be zero.

Regards

Gopal Rathi

0 Kudos
9,396 Views
mariuslucianand
NXP Employee
NXP Employee

Hello @rathi_tg ,

I've replicated your scenario as follows:

1. connect the battery pack, start the board, everything looks good.

mariuslucianand_2-1602257907414.png

 

2. pressed the SW3, board enters sleep, FreeMaster lost connection because the board is in sleep

mariuslucianand_3-1602257927319.png

 

3. disconnected ONLY the battery pack (my case emulator)

4. Woke up the board by pressing the SW2 button.

mariuslucianand_4-1602258042434.png

The StatusMeas goes to 5, as expected, but the parameters displayed by the FreeMaster keeps the values just before entering the low power state. This is because, in the generated code, the S32K MCU will send start conversion, and when it will request the converted values. The error returned by the GetRawValues function will be different than the status success, and the program will avoid the values transformation calculus from the raw values (the ones that come from the board)  to the readable measured units (the ones displayed by the FreeMaster). Here is a screenshot of the generated code.

mariuslucianand_5-1602258358370.png

 

Hope this explains the behavior.

Regards,

Marius

 

 

0 Kudos
9,388 Views
rathi_tg
Contributor III

Hello @mariuslucianand 

Thanks for your such a brief explanation helps a lot.

But I am Focusing on variable names Status (Which is directly related with slave Communication Status).

rathi_tg_0-1602259390195.png

 

When Battery Pack is not connected the value of Status should be 5.

In the Fourth picture which you have shared the battery pack is disconnected but the variable Status is still 0.

 

Regards

Gopal Rathi. 

 

0 Kudos
9,383 Views
mariuslucianand
NXP Employee
NXP Employee

Hello @rathi_tg ,

There are two variables: Status and StatusMeas.

The Status variable represents only the status message for the initialization block, that has been executed during board initialization and will not be executed during code running (the reason that I've asked you to replace that mbdtargetmainlibs32k.tlc file, is that due to a bug, the initialization block was executed every step, so by replacing that tlc file, the initialization of the MC3377x is only performed at the beginning of the code. So that Status value is only updated during the initialization and will never be updated again during runtime.

The StatusMeas value is updated every time the GetValues block is executed. And represents the status of the last conversion result. 

If you want only to test the communication with one of the battery cell controllers, during the code execution, then you can use the Verify Communication Block. This block uses No Operation command of BCC to verify communication with the device specified by CID without performing any operation.

 
 
 

 

 

9,322 Views
rathi_tg
Contributor III

Hello @mariuslucianand 

 

As you have mentioned above the entire process. I am facing an other issue.

Lets Consider a situation were

1) I Establish communication (Staus=0 .StatusMeas=0,Pack Volatge =Dyamic,Verify Comm status=0)

2) Remove the battery pack (Staus=0 .StatusMeas=5,Pack Volatge =Static,Verify Comm status=5)

3) Reconnect the battery pack (Staus=0 .StatusMeas=12,Pack Volatge =Static,Verify Comm status=0)

 

So here in case 3 I guess the master and slave aren't Transferring the data that is the reason why the value remains static. I have to reset the system back to make data transfer. How can I get data without reset in step 3.

Correct me if I made any mistake I my observation

Regards

Gopal Rathi 

0 Kudos
9,312 Views
mariuslucianand
NXP Employee
NXP Employee

Hello @rathi_tg ,

I assume that after reconnecting the pack, the MC3377x has to be reconfigured, because the MC3377x is powered up from the battery pack, which is not possible with the current toolbox blocks, unless that you insert a custom line of code. I've tried that, using the custom code insertion for the reconnecting pack situation and indeed after reconnecting the pack, if the status message is 12, if you send the config commands, the status came back to 0 and the values are read again. I've attached the previous model updated with this if else statement.

mariuslucianand_0-1602499933096.png

Also, this is valid for the previous case when you disconnect the battery cell controller while the MCU is in sleep. You can insert this custom line of code in the "Callback after" to reinint the Battery Cell Controller. You will also find this blocks setup in the attached model.

mariuslucianand_1-1602500129735.png

Please tell me if this solves the reconnection issues.

Have you applied the patch sent in the previous message? the mbdttargetmainlibss32k.tlc

Also, this disconnecting scenario, in particular, the one when you disconnect the battery pack during the MCU running in sleep is just a test, or is a real use case scenario? If so, can you please describe to me this scenario? This question is just for my knowledge.

Hope this helps!

Regards,

Marius 

9,264 Views
rathi_tg
Contributor III

Hello @mariuslucianand 

The specification was only for test purpose.

thanking you for your Support and Help!!

Regards 

Gopal Rathi

0 Kudos
9,261 Views
mariuslucianand
NXP Employee
NXP Employee

Hello @rathi_tg ,

Thank you for your clarification!

So, reinitializing the bcc driver solved the issue?

Regards,

Marius

0 Kudos
9,582 Views
mariuslucianand
NXP Employee
NXP Employee

Hello,

As a response for your question we have attached an example that allows the S32K144 to enter the Very-Low-Power Stop (VLPS) mode by using the Model Based Design Toolbox and by inserting some “Custom C code” inside a Simulink S-Function Blocks.

The functionality that we want to achieve is to put the processor in VLPS by pressing the SW3 button and to wake it up by pressing the SW2 button. When the processor will run into the VLPS mode the RGB led will light up red, otherwise it will light up green.

   Inside the archive code there are 5 files:

  • power_manager.c
  • power_manager.h
  • s32k_clock_init.c
  • mbd_s32k14_user_copy_required_files.m
  • test_low_power_s32k.slx

The first two files contains two functions that we need to configure the uC to unlock the low power modes (enable_low_power_modes()) and the other (go_to_sleep()) puts the uC into VLPS mode. The .m file contains the code that will copy the external files into the test_low_power_s32k_mbd_rtw folder.

 To run the example attached you need to follow these steps:

  1. Go to C:\MBDToolbox\mbdtbx_S32K\mbdtbx_s32k14\src\c_library (where the S32k toolbox is installed and replace the s32k_clock_init.c with the one in the archive)
  1. Go to C:\MBDToolbox\mbdtbx_S32K\mbdtbx_s32k14\mbdtbx_s32k14\mscripts\utils and replace the file mbd_s32k14_user_copy_required_files.m with the one from the archive. Open it and change the path highlighted with the one when you put the power_manager.c, power_manager.h, test_low_power_s32k.slx files as in the follow image. 

img4.PNG

  1. Open the project test_low_power_s32k.slx, build the model and program the S32k board. We used GCC compiler.
  2. How the program works: when the controller starts, it enters the RUN mode and the RGB led is turned on green. When you press the SW3 push button, the RGB led turns red and the processor enters VLPS mode. To wake up the processor the SW2 button must be pressed.

For measuring the actual current consumption of the uC, we desoldered the 0 ohm R117 resistor and placed an Ammeter on J15 (you don't need to do that). When the uC is in the RUN mode, the current consumption is about 35mA.

IMG_20170704_193458.jpg

When the uC runs in the VLPS mode, the consumption is about 30 uA. 

IMG_20170704_193532.jpg

I hope that this example helps you!

Marius Andrei

9,161 Views
oeren5
Contributor III

Hi @mariuslucianand,

Firs of all thanks a lot for detailed information. I was looking for more information regarding power modes, this topic helps me a lot.

I want to measure the time when the uc enters the VLPR mode. To be more clear, let's say uc operates at run mode then I pressed SW2 and put the controller in VLPS mode. I want to start the timer and count the time as long as the controller in VLPS mode. After the controller turns back to normal Run mode I want to read and store the time that passed in VLPS mode.

For this purpose I crate a model base on pmc_vlpr_s32k14x example that provided with mbdt v4.2. As far as I understand I should used LPTMR for this purpose I add an LPTMR start/stop in VLPR mode and add Get counter block in normal mode. You can see the ss of models below. In this model I can observe the compare value correctly, but I could not observe the correct get counter value each time I observe 9 independent from time. Could you please guide me how can I do this task? 

Also, can I use LPTMR timer and same logic for VLPS mode?

Thanks in advance.

Model in general:

oeren5_0-1603377615267.png

Pressing SW3 (VLPR mode):

oeren5_1-1603377666225.png

Pressing SW2 (Run Mode):

oeren5_2-1603377704544.png

 

0 Kudos
9,149 Views
mariuslucianand
NXP Employee
NXP Employee

Hello @oeren5 ,

Let's take them point by point.

For the first main question regarding what is on and what is off when the uC runs in the low power modes, I strongly suggest having a look at the S32K1XXRM  Table 39-1. Chip power modes and table Table 39-4. Module operation in available power modes 

From those two tables, you will get that the LPTMR timer is fully functional VLPR but only if the SIRC clock is used, while in VLPS it runs in Async operation. This means that the peripheral is fully functional if the clock source remains enabled. 

mariuslucianand_0-1603443005999.png

Now, SIRCDIV2 can be the source clock for the LPTMR so having a look again at that table, we get that the SIRC is Fully Functional, no matter what power mode is active.

 
 

No, that we have this information, I have integrated the LPTMR timer functionality in the model that  @rathi_tg was kind enough to share previously. 

Now, what is important is to configure the LPTMR in the ticks to know exactly what Prescaler is used in order to be able to transform back from ticks to seconds. So I will select the maximum compare value, FFFF and select ticks.

 
 

ticks.JPG

Now, in the next tab, in Advanced, I select the SIRCDIV2 as main clock source and the prescale value to be 1024. What this means is that by dividing the SIRCDIV2 by 1024 I got 7815. (SIRCDIV2 is the name of a clock signal which, in our case, is equal to the 8MHZ the SIRC frequency. SIRCDIV2 it doesn't mean that the clock is 4MHz). So after one second, the timer will store 7815. This means that we can count up to 8.35 seconds until the LPTMR counter overflow occurs. If you increase the prescaler you will be able to measure a large amount of time.

tick2.JPG

With these settings, I am going to use the VLPS mode. In the Callback_before I am going to start the counter, while in the Callback_after I am going to get the counter value and to transform it back to seconds.

ticks3.JPG

 

In the callback after, I firstly turn off the RED LED, and them Get the Cunter Value. To transform the value back in seconds, I have to apply the formula: time = Counter / (SIRCDIV2/prescaler).

ticks4.JPG

I can check that the math is good, by using a Logic Analyser. I will attach the logic analyzer to the RED led which is turned on while the board runs in VLPS. You can see that the values are roughly the same.

I have attached both model and FreeMaster project. If you have further questions, feel free to post here.

Hope this helps,

Marius

 

0 Kudos
9,047 Views
oeren5
Contributor III

Hi @mariuslucianand 

Thanks a lot for detailed answer and model.

I upload the model that you provided to S32K144 and the model downloaded and run successfully. I observed that the LEDs blinks and turns on in a correct way(Green LED constant on, Blue LED blinking in Run mode and Red LED constant on in VLPS mode). 

I upload the Freemaster project and observe the cell voltage and pack voltage level. But I received same value in both LPTMR_CNT and LPTMR_CNT_S whenever I pressed SW3 and SW2. I constantly observe 5 as LPTMR_CNT and 0.000640005 as LPTMR_CNT_S regardless the time passed between each button press. 

I directly upload the model, the only change that I made changing the BMS IC to MC33771B and cell number to 14. 

Should I make any changes in the model? How can I observe the correct time?

Thanks in advance.

The screenshot of Freemaster is provided as follow:

 
 

1.PNG

0 Kudos
9,034 Views
mariuslucianand
NXP Employee
NXP Employee

Hello @oeren5 ,

Have you previously generated the code for the MC33772B? Well, there should be no difference regarding the code generation and the timer functionality if you have selected the MC33772B vs MC33771B. I usually don't keep the generated code, I delete it every time I end working to a model. I guess that maybe the Freemaster reads the data from other location... Please send me the generated code and I Have a look on it.

Until them, I've tested the board with the MC33771B and the Emulator and the timer seems to work fine. For the accuracy comparison, I've used the logic analyser to measure the RED led (PTD15) signal timing. Sorry, in my last response I forgot to add this screenshot. You can also see that I've added two more cells values to see that the code works on the MC33771B. I will attach again my model and the mot elf file. Please give them a try, without compiling first.

mariuslucianand_0-1604050427755.png

Hope this helps,

Marius

 

 

 

0 Kudos
9,581 Views
eautopower
Contributor IV

Hi Marius Andrei:

thank you very much for your answer.it is useful.

0 Kudos
9,583 Views
dumitru-daniel_
NXP Employee
NXP Employee

Hello, 

Sorry for delay - originally you placed the query in a different community. 

The Model Based Design toolbox does not covers all the "bells and whistles" that NXP S32K is capable of. We have plans to change that and we are currently working in adding additional blocks.

Nonetheless, this is the beauty for Model Based Design - you do not need to have all the blocks available in order to achieve what you want. Matlab and Simulink offers a wide variety of options that can be employed to resolve such use cases.

For your particular use case - i advice you to use the "Custom code". You can implement your our own C-code function to put the S32K in sleep mode by setting up the appropriate registers.  

Furthermore - you can potentially use the S32K SDK power management functions to be invoked from Simulink in order to reach your goal.

How to do that? it is relatively simple. Please have a look of these links:

https://community.nxp.com/message/910444?commentID=910444#comment-910444 

https://community.nxp.com/message/900776?commentID=900776#comment-900776 

https://community.nxp.com/thread/449904#comment-901737 

Hope these will help you!

Best regards,
Daniel

9,583 Views
eautopower
Contributor IV

popa:

thank you! if i use the s-function builder ,i must need the c-coder,but SDK example, the power management function nested many functions, it is very inconvenient to use, do you have a register version of the example?

0 Kudos
9,583 Views
dumitru-daniel_
NXP Employee
NXP Employee

Hello, 

We do not have a particular example power management. I think you should start from the example attached in this thread: https://community.nxp.com/thread/452468?commentID=910444#comment-910444 (simulation models)  and one you manage to recreate the setup on your PC then we can assist you with guidelines about the C-code.

Best regards,
Daniel

0 Kudos