Introduction
The aim of this article is to help any user of Model-Based Design to enjoy his/her own custom C libraries or to call any C drivers or components that are not yet supported by NXP's toolbox. This uses the Matlab Coder and requires to include only a MATLAB function block in which the model will call a C function. For more details, you can have a look on the Mathworks Help Center at Integrate C Code Using the MATLAB Function Block- MATLAB & Simulink.
BMS System
In my opinion, the greatest way to learn something is "learning-by-doing". So in this tutorial, we will add support for the BMS System in Model-Based Design for S32K. You are already familiar with our toolbox supported boards so let's talk a bit about this BMS system.
NXP has a great cell controller IC designed for automotive and industrial applications, more details can be found here MC33772B | 6-Channel Li-ion Battery Cell Controller IC | NXP. For this tutorial, we will use the FRDM33772BSPIEVB | MC33772 SPI EVB | NXP board, which handles up to 6 battery cells and connects to many NXP controllers via SPI. This is also compatible with the S32K family with some minor jumpers adjustments, but all the instructions can be found on the product page.
So the goal of this project is to be able to read the cell voltages from an MBDT Simulink model.
Main Steps
In order to include custom code, the user should follow these steps:
1. Add the directory path from which the Simulink will include the directories under Settings > Code Generation > Custom code > Include directories.
2. Insert a Matlab Function block in the Simulink model. This will be used for initialization. The goal here is to include the c headers in the generated code files. This requires to declare coder constant using the coder.const function. That has to be updated in the Build info using coder.updateBuildInfo . Here, the headers and the sources has to be included following this template:
%% Adding header information to the generated code
coder.cinclude('driver.h');
%% Adding source files to MakeFile
coder.updateBuildInfo( 'addSourceFiles', 'driver.c' );
This operation has to be performed only once.
3. When the user needs to call a custom function from the Simulink, the user must add a Matlab Function block, declare the inputs and outputs as required. Inside the Matlab Function code, the coder.ceval function must be called using the parameters provided as inputs.
For example, if the user needs to call a C function called BMS_Init with no parameters, the following line of code will perform that:
%% Initializing the BMS driver
coder.ceval('BMS_Init');
If the user needs to provide an input parameter, then it will be provided either directly, either using coder.ref as an argument or using coder.rref if the reference to that value has to be passed.
function BMS_Init(parameter)
if( coder.target( 'Rtw' ) )
coder.ceval('BCC_Init', parameter);
coder.ceval('BCC_Init', coder.ref(parameter));
end
end
This will generate the following code:
BCC_Init(true);
BCC_Init(¶meter);
But if the code is more complex, the easiest way is to declare a wrapper function and to call the wrapper using the coder.ceval.
BMS Support
This scenario fits on most of our users requirements: to use a piece of code unsupported yet on MBDT. For this IC, NXP already provides the KIT3377x_DRV driver together with an example in S32DS which measures cell voltages and displays it using FreeMaster.
We created an S32K project for the S32K144 board, added the FreeMaster block and an LPSPI Instance according to the settings and the pin requirements by the MC33772 board. The Initialize variable will only be used to call the initialization sequence for the BMS.
Now, as we described in the previous chapter, we declared a folder "bcc" that contains the required drivers and some wrappers, also inserted in the Configuration parameters.
The initialize function contains a Matlab Call Function. This one includes all the steps described at the second point. What should be noticed here is the check from line 7. All that cinclude code will be called only when the coder.target is Rtw. If the user adds an else condition, that code will be called only when simulate. Now, MBD_MCC_Init is wrapper designed to perform all the initialization steps from the driver. It was easier like this.
The MC33772 has been initialized so whenever the user needs the values, he/she must add a Matlab Function block that will provide the values to the model.
The code behind this block has been attached in the next image. The output values from the getCellMeasurements are provided as outputs and inside the get_cellVoltages, it will call the C updateMeasurements function using the coder.wref function.
Running BMS
Now, after we solved some bugs during code generation and had successfully built the code, we can run the generated code on the board. The following screenshot represents the Voltages and a variable Current measurement converted by the MC33772.
Conclusions
In this article, we presented a method of getting the needed C libraries/drivers/code in the Simulink model using custom code and Matlab Coder. We provided a short step list and a more detailed tutorial for an actual application, a Battery Management System, using NXP hardware. This approach can be successfully achieved either if we use the S32K or MPC Toolboxes.
Later edit (1):
As requested, I attached the model and the FreeMaster project for achieving the measurements from the MC3377xB (FRDM3377xBSPIEVB) with the S32K144 board using Model-Based Design and custom code.
In order to run it, you must follow the steps:
1. Download and unzip the archive there is a bcc folder inside, next to the s32k_mc3377x.mdl.
2. Download the SDK (Embedded SW: MC33771/MC33772 SW Driver | NXP ) BCC SW Driver package for MC33771B/MC33772B (Lite version) and from the SDK folder bcc copy all the files to the bcc folder of the model. I can not add the SDK driver in the archive since for the BCC SDK there is an agreement that you must read before download.
3. Open the s32k_mc3377x model, go to the BMS_Init function and replace the line 4 string with the full path of the model bcc location folder.
4. After this, the code should be generated and run successfully.
Later edit (2):
If you are interested to get the solution alongside the instruction on how to connect the MC3377xB and the MPC5744P via Model-Based Design Toolbox, please have a look at this question here: MPC5744P &MC33771B Configuration
Later edit (3):
As many of you requested, we've added the example code for the S32K144 & FRDMDUALMC33664 to communicate with the MC33771C. See the attached archive. bms_s32k_frdm2_771c_tpl_cc. The bcc driver for the MC33771C is different than the one for the MC33771B and you have to download the missing files from here.
Happy hacking!
Marius
Hi Marius
Is there a direct way to establish SPI communication between the NXPS32K144 and MC3371 using MATLAB Simulink .
Also in the code shown above,the baud rate is set to 1Mbps however as per the data sheet the Baud rate should be 2Mbps. Could you please explain the same.
Regards
Gopal Rathi.
Hello rathi.tg@araiindia.com,
Thank you for your interest in Model-Based Design Toolbox for S32K and this BMS example!
I will try to provide a response for each point.
Is there a direct way to establish SPI communication between the NXPS32K144 and MC3371 using MATLAB Simulink .
This custom code example is based on the MBDT for S32K, which is a layer on top of S32SDK for S32K drivers, delivered in the same package with MBDT. Now, in order to achieve a functional communication between S32K144 and MC33772B, you need to use the Embedded SW: MC33771/MC33772 SW Driver | NXP which also uses the same S32SDK for S32K drivers layer.
It is easier to use this driver, because there are only two functions that needs to be called: BCC_Init (to initialize the driver) and periodically updateMeasurements to achieve the new measured parameters. Obviously there are also a couple of C structures used for setting the parameters.
For now, the easiest and elegant way of doing this in the MBDT is by using this custom code method explained above. For supporting this board, NXP provides a User Manual for the SW Driver which can be found here Embedded SW: MC33771/MC33772 SW Driver | NXP, explaining more about the SW implementation and even how to change parameters. I strongly suggest to read this.
Now, in the tutorial above, I only initialized the SPI0 using the MBDT Block to the parameters used by the driver and I commented the Driver initialization from the bcc_peripheries.c component performed by the BCC_MCU_ConfigureLPSPI(). The reason for which I chose to do this is that the MBDT SPI block also initializes the pins used for SPI. In the official example, the pins are initialized separately. For the other communication commands, the MC Driver is responsible of.
Also in the code shown above,the baud rate is set to 1Mbps however as per the data sheet the Baud rate should be 2Mbps. Could you please explain the same.
Well, I set the SPI to work at the same frequency used in the SW Driver FreeMaster example.As you see below, in the bcc_peripheries.h the bauds are set at the following rates:
#define BCC_SPI_LPSPI_BAUD 1000000
#define BCC_TPL_TX_LPSPI_BAUD 2000000
But the MC33772 Driver specifies that in case of TPL the speed must be 2Mbps since the min in 1.9 and max in 2.1, while for the SPI the maximum frequency must not be higher than 4.2MHz, lower rates are accepted.
Hope this helps,
Marius
Hello mariuslucianandrei
I have Followed all the Steps which are stated above in your main Code but encountered with an Error. Here is the Attachment of the Error.
Secondly Embedded SW: MC33771/MC33772 SW Driver | NXP did not Provide me with any specific files like the one which are in the Code i.e mbdt_utils.c and .h.
So the Entire BCC_MCU_ConfigureLPSPI() has to be Commented?
Thanks for your Support
Gopal Rathi.
Hello rathi.tg@araiindia.com,
Sorry for my delayed answer.
Indeed, those files does not exists in the driver. I wrote them and contains the wrappers used for initialization like MBD_BCC_Init function, where you can fill the structure of settings and the function that actually measures the data. You can find them in the SDK FreeMaster example.
bcc_status_t updateMeasurements(float *cell_Voltages, float *pack_Voltage, float *pack_Current, float *internal_Temperature)
Also, inside it, I kept the initial function provided by the SDK, and I only transferred the measured data to the variables like here:
// MBDT Provide all required data in uV
cell_Voltages[0] = (float) cell1VoltageUV;
cell_Voltages[1] = (float) cell2VoltageUV;
cell_Voltages[2] = (float) cell3VoltageUV;
cell_Voltages[3] = (float) cell4VoltageUV;cell_Voltages[4] = (float) cell5VoltageUV;cell_Voltages[5] = (float) cell6VoltageUV;*pack_Voltage = (float) stackVoltageUV;*pack_Current = (float) isenseCurrentMA;
So the Entire BCC_MCU_ConfigureLPSPI() has to be Commented?
Not quite, the function must stay, I only commented the lines from 179->193 just after #if defined(SPI)
Also, when you write the call_getCellVoltages function, make an initialization for the Cell_Voltages with the type you need the variable and with a dummy values. Also, provide it as a pointer and you will be able to get all cells with a single array.
if( coder.target( 'Rtw' ) )
coder.ceval( 'bccError = updateMeasurements', coder.wref(Cell_Voltages), coder.wref(Pack_Voltage), coder.wref(Pack_Current), coder.wref(Internal_Temperature));
else
% We're not generating code
Cell_Voltages = single(3.7*ones(1,6));
Pack_Voltage = single(6.0*3.7);
Pack_Current = single(1.5);
Internal_Temperature = single(22.0);
end
Hope this helps,
Marius
I am bit confused with Steps which are mentioned above.Could you help me out by providing the demo code for both MC33771B as well as MC33771C.
Thanks and Regards
Gopal Rathi
Please help us, I am also in same investigation as him to migrate C.Code to fully use MBDT.
*.m file or some matlab example project would really appreciate.
Thanks & Regards,
Narudol T.
Hello,Marius.
If I want to achieve a functional communication between MPC5744P and MC33772B, what should I do? Is there any advice?
Thank you.
SHAO Jianbo
Hello rathi.tg@araiindia.com, teejaa,
As requested, I attached the model ( the archive can be found upper, to the initial text of the tutorial) and the FreeMaster project for achieving the measurements from the MC33772B (FRDM33772BSPIEVB) with the S32K144 board using Model-Based Design and custom code.
In order to run it, you must follow the steps:
1. Download and unzip the archive there is a bcc folder inside, next to the s32k_mc33772.mdl.
2. Download the SDK (Embedded SW: MC33771/MC33772 SW Driver | NXP ) BCC SW Driver package for MC33771B/MC33772B (Lite version) and from the SDK folder bcc copy all the files to the bcc folder of the model. I can not add the SDK driver in the archive since for the BCC SDK there is an agreement that you must read before download.
3. Open the s32k_mc33772 model, go to the BMS_Init function and replace the line 4 string with the full path of the model bcc location folder.
4. After this, the code should be generated and run successfully.
Happy hacking,
Marius
I have worked on the model as directed but i encountered an error while building the project(when i try to flash into the hardware(S32K144)).
1. I have Few more quires I am initially trying the code on MC33771B so i made necessary changes in the mdbt file of the Project and even in the bcc_Conf are there any other changes which i missed please let me know.
2. Can you guide me how could i even send Cell balance Command and get cell Balance Status and even send command for Sleep and make up.
Here i am attaching the snapshot of the error.
Thanks and Regards.
Gopal RathiK
Hello rathi.tg@araiindia.com,
Nice to see that you are using this article to design a real solution!
For the first point, by analyzing the screenshot I can tell that the program is crashing when it tries to link all the object file into the elf file. This happens when one of the source files is not yet compiled. So the missing references are defined under mbdt_utils.c which means that this file is never compiled. so please check in the BMS_init Matlab function that the bccPath is well defined, all the headers were inserted using coder.cinclude function and most importantly, all the source files had been passed as coder.updateBuildInfo function. Most likely the coder.updateBuildInfo( 'addSourceFiles', 'mbdt_utils.c' ); is missing. This is my output when deleted the mentioned line of code
But also, I can see from the screenshot that you are using an older version of the toolbox and an older compiler. Can you tell me which version of the S32K Toolbox are you using?
For the second point, give me some time to investigate these requirements and I will reply back to you!
Hope this helps,
Marius
I have added coder.updateBuildInfo( 'addSourceFiles', 'mbdt_utils.c' );
This is the Toolbox version "S32K1xx v.2.0.0" .The path specified "bccpath" is write or else it would throw error for all the files (as per my knowledge) .
I had made the model so there may be possibility i have missed something. So could you share me the Matlab model of lower version as 2019b is unavilable.2016b would be fine.
1.I am initially trying the code on MC33771B so i made necessary changes in the mdbt file of the Project and even in the bcc_Conf are there any other changes which i missed ? Please let me know.
Thanks and Regards
Gopal Rathi
Hello rathi.tg@araiindia.com,
If all the sources and headers are fine, you can check to have the bcc in Include directories.
I was asking about the toolbox because now, the Model-Based Design Toolbox for S32K1xx Series is at version 4.1.0, targeted for R2017b-R2019a. However, it is fully compatible with the latest versions like R2019b and R2020a. We encourage all our users to use our latest software releases, bor the best experience! We'll see what we can do about R2016 with future releases.
Try adding the Include directories and see if this helps or not the issue!
Hope this helps,
Marius
I have successfully built the code as i was having an issue with the tool box. But, I am using MC33771B to establish Communication and the output parameters are send via CAN but i am unable to get the values of the parameters.
The FRDMMC3371BSPI (Freedom SPI Board) connected to s32k144 goes to sleep after 2-3 min which may state that communication establishment wasn't successful.
I haven't connected the below two pins.I, guess they are optional as it was not specified were these are connected to FRDMMC3371BSPI .
I have Made necessary changes in the MDBT file.Could you share me the required configuration method to establish Communication maong S32k144 and MC3371B and MC3371C as well.
Regards
Gopal Rathi
Hi,
This is Ozan and I am trying to built a bms design with s32k144evb and FRDM33771BSPIEVB. As a first step I want to read the measurement values of mc33771. I understand that some configuration changes should be made in the s32_mc33772 model example in order to use mc33771 instead of mc33772. I have made following changes in mbdt_utils.c file which I downloaded from (Embedded SW: MC33771/MC33772 SW Driver | NXP ). Main purpose is to use mc33771 with 14 cells and SPI communication.
I want to know that whether following changes will be enough for proper device and cell number configuration or should I make some extra modification in bcc driver codes (and in which file specifically i.e bcc.c, bcc_wait.c, bcc_spi.c etc). Thanks in advance.
->uncomment the below part:
// To be used for the MC33771
uint32_t cell7VoltageUV;
uint32_t cell8VoltageUV;
uint32_t cell9VoltageUV;
uint32_t cell10VoltageUV;
uint32_t cell11VoltageUV;
uint32_t cell12VoltageUV;
uint32_t cell13VoltageUV;
uint32_t cell14VoltageUV;
cell7VoltageUV = BCC_GET_VOLT(measurements[BCC_MSR_CELL_VOLT7]);
cell8VoltageUV = BCC_GET_VOLT(measurements[BCC_MSR_CELL_VOLT8]);
cell9VoltageUV = BCC_GET_VOLT(measurements[BCC_MSR_CELL_VOLT9]);
cell10VoltageUV = BCC_GET_VOLT(measurements[BCC_MSR_CELL_VOLT10]);
cell11VoltageUV = BCC_GET_VOLT(measurements[BCC_MSR_CELL_VOLT11]);
cell12VoltageUV = BCC_GET_VOLT(measurements[BCC_MSR_CELL_VOLT12]);
cell13VoltageUV = BCC_GET_VOLT(measurements[BCC_MSR_CELL_VOLT13]);
cell14VoltageUV = BCC_GET_VOLT(measurements[BCC_MSR_CELL_VOLT14]);
-> Add following cell voltages:
cell_Voltages[6] = (float) cell7VoltageUV;
cell_Voltages[7] = (float) cell8VoltageUV;
cell_Voltages[8] = (float) cell9VoltageUV;
cell_Voltages[9] = (float) cell10VoltageUV;
cell_Voltages[10] = (float) cell11VoltageUV;
cell_Voltages[11] = (float) cell12VoltageUV;
cell_Voltages[12] = (float) cell13VoltageUV;
-> At last I changed init function:
bcc_status_t MBD_BCC_Init(void) {
//Configure the bcc_drv_config_t structure for the MC33772
drvConfig.drvInstance = 0U;
drvConfig.commMode = BCC_MODE_SPI;
drvConfig.devicesCnt = 1U;
drvConfig.device[0] = BCC_DEVICE_MC33771;
drvConfig.cellCnt[0] = 14U;
Hello,
I did the same but the output is zero and the slave MC33771B goes to sleep.
Regards
Gopal Rathi
Hello oeren5@ford.com.tr, rathi.tg@araiindia.com,
The changes that both of you have mentioned seem to be enough to work, but I need to investigate on a setup of S32K + MC33771B to in order to provide a relevant answer. I will try to generate a model for MC33771B and attache the sources, as soon as possible.
Hope this helps,
Marius
Hello rathi.tg@araiindia.com, oeren5@ford.com.tr,
As I've promised, I've attached the model running on 32K144EVB + FRDM33771BSPIEVB + BATT-14EMULATOR. Basically all the changes that oeren5@ford.com.tr mentioned in the previous post are enough, but since you have the code now (attached at the end of the article), you can perform a diff.
The only requirement I have is to go to the BMS initialization/MATLAB Function and to replace the line 4 with the full path of the bcc folder in the archive.
This is how the FreeMaster project looks like with all the 14 cells battery values.
Now, please check the following points in order to get a valid communication.
1. the FRDM33771BSPIEVB contains some hardware jumpers configuration on the board that has to be changed in order to get a working communication. You cand find it at the chapter 2.4.1 FRDM33771BSPIEVB configuration in the UM11143 manual, the changes that you have to perform with the soldering iron on the board (just 6 jumpers) in order to route directly the mC33771 pins to the S32K144 pins header.
2. I assume that the communication issue that rathi.tg@araiindia.com mentions in his reply, that the board gets in idle is caused by a faulty communication either we talk about a hw or sw problem: the board gets no communication and after 60 seconds it enters standby mode.
3. If you are using the same setup as I do, please make sure that the emulator is powered up
Hope this helps,
Marius
Hi Marius,
Thank you so much for your kind response and help. I will make necessary hardware configuration that you mentioned in chapter 2.4.1 FRDM33771BSPIEVB configuration.
Another point that I want to discuss is cell connection to FRDM33771BSPIEVB, because I will use real 18650 lithium ion cells (14 cells) instead of BATT-14EMULATOR. When I reviewed the user guide I saw that cell connection should be made by using cell connector X1. But I could not completely understand the connection.
I assumed that CT_14, CT_13, ...... to CT_1 are connectors which will be connected to cell's positive terminal through cell 1 to cell 14. But I did not figure out where to connect VBAT (X1-1 and X1-2), CT_REF, GND(X1-34 should be 1st cell negative?) and CB_14, CB_14:13_C, CB_13/CB_12.... to CB_1. Could you please explain or guide me through the connections in a detailed way?
Thanks in advance and this place is a great community to learn.
Hello oeren5@ford.com.tr,
You're correct:
- CT_n lines need to be connected to the n Cell's positive terminal.
- CB_XX lines need also to be connected to the Cell's positive terminal. Typically customers don't use power (for Cell balancing) and sense (for Cell terminals) all the way to the battery cells which could allow measuring cells accuractely while doing cell balancing. So you can simply connect one single line from the CT_n and CB_XX to the cell terminal.
- Supply of the IC is done through 2 additional lines that are needed to avoid inaccuracy due to the IC supply current through the cable resistance. So a separate line needs to connect VBAT (X1-1/X1-2) to cell14 positive terminal. Similarily, a separate GND connection is required between the negative terminal of the first cell and the GND (X1-34).
Below is a hand schematics on how to connect the connections to your battery Pack.
I Hope this will help you.
Best regards,
Philippe
.
.
.
Dear Philippe,
Thanks a lot for your time and effort. Huge help, appreciated.
Best regards.
Hello Marius ,
I have used the above code and build it successfully,MC3371B does not go to sleep.
I have connected the CAN module to check the output on the CAN Bus but the values are nor stable nor accurate.
Is there anything Specific Requirement to see the output on CAN.
Thanks and Regards
Gopal Rathi
Hi,
I am connecting actual Li-ion Battery cells to FRDM33772BSPIEVB.
I have successfully uploaded the code to the controller (S32K144). However, I am unable to read the voltages on FreeMaster.
After uploading the code, I get this message on FreeMaster
Also, I have noticed that the VCOM LED on BCC doesn't turn ON.
Can someone please help me this?
Thanks
Hello rparveez@mtu.edu,
From your post I notice that you basically have two issues:
1. The one related to the VCOM LED. Typically the LED lights up when the mc33772 is powered on for over 1 minute. If the controller is not communicating with it, the board will enter sleep and the VCOM LED will be turned off. Have you performed the jumpers modification to the board in order to route the board pins to the S32K controller? You can find all the steps in the UM11143. Please read this document and solder/desolder the right jumpers.
2. For the FreeMaster issue, the names of the CellVoltage array probably had been changed so the link is broken. You can fix this by pressing continue, double click inVariable Watch on the desired variable, and please retype the variable name.
From today, our MBDT S32K 4.2.0 has been released and we have added support for the MC3377xB both SPI/TPL boards so I encourage you to start using our BMS blocks.
Hope this helps,
Marius
Hello m15871781742@163.com,
For achieving the same functionality on the MPC5744P you have a little more work to do. Basically, besides the migration of the custom code model attached you have two also migrate the files bcc_peripheries.c and bcc_wait.c which for now are written for S32K. Basically you have to update the send and receive methods to call the ones forom the MPC SDK that also comes with our Toolbox.
Hope this helps,
Marius
Hello Marius
After following the Pin Configuration my Slave wasn't going to sleep any more.But, unfortunately when i see values on Free master all my output are zero.
I tried connecting CAN module to the Data Store "Cell_Voltages" and "Pack_Voltages" but the values are in appropriate.
I have used DATA TYPE CONVERTER .Is there any specific conversion require to convert a single data type value to a uint8 data type.
Thanks and Regards
Gopal Rathi
Hello Gopal Rathi,
So, you have now a connection with the Battery Cell Controller board?
Starting from today we have released the MBDT for S32K4.2.0 which adds support for MC3377xB in Mathworks and S32K. You can start from the model bms_s32k_mc33772b_spi.mdl. Just change the Device in the MC3377xB Config Block and the model will work with the MC33771B.
So the model has an LPSPI Config block that configures the SPI peripheral. The MC3377xB Config block initializes the MC33771B Battery Cell Controller and as you can see here, it will provide an error status code. It will be good to add the variable in the FreeMaster and see the results. The error code is explained in the block's help so it will be easy to figure out what's wrong.
The MC3377xB Get Values block can start the conversion, wait until the conversion is ready and provide the results directly in milliAmps, microVolts, degrees Celcius, all human-readable values. All are cast to single, so if you need to transform from uV to V you only need to change the gain factor.
Let's give this a try and see how it works on your side.
Hope this helps,
Marius
Hi Marius,
1. Yes, I have modified the jumpers as per UM11143.
2. I did change the variable name but still, I see the following message every time I build the model.
I am still getting 0V on CellVoltage.
Is there a way to check if there is a communication error?
Thanks
Hello Marius,
Can you please share the link for MBDT S32k 4.2.0? I didn't find it.
Thanks
Hello rparveez@mtu.edu,
You can find the announcement in this page https://community.nxp.com/docs/DOC-347202
You can also install the latest version directly from the Matlab Add-Ons, following all the steps required there.
Marius
Hello rparveez@mtu.edu,
1. Make sure that you save the FreeMaster project and update the FreeMaster location on the.elf generated file from Project -> Options -> MAP Files -> Default symbol file.
2. Yes, every block in the new release added for BMS offers a Status Output which provides an information regarding the operation status. The error code is detailed in the block's help so it will be easy to figure out what's wrong.
Let's give this a try,
Marius
Hi Marius,
I tried the new BMS toolbox and I selected MC33772 device in the MC3377xB configuration. But the Get Values block outputs 14 elements. Is it possible to make it 6?
I am still not able to read cell voltages on FreeMaster. Below is the watch window, the Status variable on the Get values block outputs 5. Does this mean the wrong CRC? How can I fix this?
I tried using the previous Simulink example model for s32k, I was able to read only the pack voltage. The cellvoltage[0] shows 5V but the actual voltage of Cell 0 was 3.2V.
Please verify the battery connections below for MC33772, the pins 1-2, 19-20, 21-22, .... are connected together.
Thanks
Hello @Rubeena,
I got the notification for this post just yesterday, but I believe that you have already solved these issues.
For the 6 cell values, the Get_RAW_Values returns actually an array containing 30 registers. The values are described in the block's help. For the Get_Values block, this will return values already converted into the common measurement units. The block will return an array of 14 cell voltages, but since the cell number depends on the part and application, you just have to ignore the other 8 values that you are not using.
The status comm value of 5, represents the CRC error which probably means that the board has a bad or inexistent communication with the target.
I believe that the pins are connected together due to the high current that the nets have to handle during balancing.
For the mismatched measured values, please recheck the connections. I've tried connecting 3 LiIon cells (just ignore the 4th one, is dead) using the following pins:
Cell1 Neg – pin 34
Cell1 Pos – pin 30 (I only connected the 30 you can also connect both 30 and 29)
Cell2 Neg – pin 30
Cell2 Pos – Pin 28
Cell3 Neg – pin 28
Cell3 Pos – pin 26
Cell3 Pos – pin 2
Also connected the pin 33 with pin 32 to have a connection exactly like in the blue design for the following image. Finally, I got the following results.
Hope this helps,
Marius
Hello Marius,
Thank You Marius.I Have tried both the ways and i am able to establish the communication among the master and the slave.
I am right now facing one problem.Could you guide me how i could convert the single(data type) to Unsigned Interger so that same values can be observed on CAN.
Regards
Gopal Rathi.
Hello Marius,
The above Toolbox establish Communication among the S32K144 and MC33771B/2B. But Currently i am using MC33771C as my slave could you please guide me or provide an example code to establish Communication among both the boards(S32K144 and MC3371C).
Regards
Nisha.
Hello rathi.tg@araiindia.com,
As you can see, in the following attached image, the MC3377xB_Get_Values block provides output for the CellsVoltage as an array of 14 uint32 elements and the values are expressed in uV. For converting to single the model uses a gain of 1 and the results are then sent to the FreeMater as Float. The FreeMaster apply a simple equation to display data in volts.
So you can take directly the data in uin32t in uV from the Get_Values block.
If you need to convert data from single to uin32, you have multiple ways: either you use the gain of 1 and in the gain block you select which data type to have the output value, or you can use the data type conversion from Simulink.
Hope this helps,
Marius
Hello nishalemos@gmail.com,
For connecting the MC33771C to the S32K in Simulink, you have to follow all the steps presented in the article above but with another driver. The MC33771C uses the Software Driver that can be downloaded from this page Embedded SW: MC33771C SW Driver | NXP (the Lite version).
So, after you download the driver you can have as a model the BCC_S32K144_FreeMaster application from the same archive with the Driver. Ther you will also find the BCC_S32K144_FreeMaster.pdf that explains the application.
So, the recipe is the same: you have to use our toolbox to configure the SPI Instances that are going to be used for the communication (1/SPI, 2/TPL). You have to use a function that will call the driver initialization for the MC33771C with the initial register values (you will find all the required code in the S32DS project). You have to use a Matlab function to call all the driver functions that you need, exactly like the UpdateMeasurements function described above.
Hope this helps,
Marius
Hi Marius,
Can you please comment on Cell temperature readings, I am using NTCs (B25/50 with the value of 3380k. At room temperature, these outputs have incorrect results. Do I need to add scaling and offset on FreeMaster? or is there a way to change it in Simulink?
Thanks
Hello rparveez@mtu.edu,
The NTC parameters for the NTC thermistors are set in the BCC config block. If you have connected the NTCs sensors on the inputs, make sure to desolder the NTCs on the board because now you will have two NTCs in parallel.
Based on the values from the NTCS, during initialization, the algorithm will compute a lookup table. Please have a look at the generated code for the function called fillNtcTable. When monitoring, the code will get the NTC voltage and based on the lookup table will return the value in *C.
The values used in the MC3377xB_Config from the Pack settings tab, represents the parameters of the NTC thermistors used by the MC3377xB_Get Values block. The same is for the Shunt Resistance. The block will use this value to translate from shunt resistance values into current value.
If you do not want to use this method for translating the raw voltages read by the MC3377xB and you want to use your own methods of translating raw values into measurements required by the algorithm, please use the MC3377xB_Get_Raw_Values, that will return only 30 registers of raw data.
Hope this helps,
Marius
Hello Marius,
I was trying to integrate Power Saving Mode of master and the Slave Communication.
The Code for S32k144 is from PowerManagment_ISR (Power modes Via Gpio Call Back provided in NXP Example.
When i flash the code it runs fine as per the instruction but as soon as i integrate the Slave Communication the master does not wake up via Switch and requires a reset.
Secondly. I get an error when i import the .xml file of Master Slave Communication into the Design Studio a notepad pop out with the following .
The Error is as follows.1> C:\NXP\S32DS_ARM_v2.2\S32DS\build_tools\gcc_v6.3\gcc-6.3-arm32-eabi\arm-none-eabi\newlib\lib\thumb\v7e-m\fpv4-sp\hard\libm.a (The system cannot find the path specified)
Design Studio Version 2.2
Regards
Gopal Rathi.
Hi,
This is Ozan. I used the BMS model example and read the cell voltages, current, temperatures successfully via freemaster. But when I try to build logical operations with these measured values or store these data permanently I could not succeeded.
I try to built relational operations such as turn on the blue LED if the min cell voltage goes below 2.1 V or blink on and off the red LED if the pack voltage exceeds 31 V. I used both relational operator block and if condition block for this purpose. But the LEDs were on whether the conditions are satisfied or not. To be more clear blue LED is one while voltage level is below or above 2.1 V or red LED is blinking for pack voltage both above or below 31V. In the mean time I changed the voltage level via voltage source and I can observe the change in the voltage level for both min voltage and pack voltage level. What might be the problem and how can I solve this issue?
Another problem pops out when I try to write some data to permanent memory. I used Flash config and Flash EEEwrite blocks but I could not store the data and received an error related with memory. I want to store different data (let's say SOC, internal temperature, min and max cell voltage ) in non-volatile memory. How can I perform this?
Thanks in advance and best regards.
The models that I used for logical operations:
The model for Non-volatile memory:
Hello @rathi_tg
For the read register block, if you read this kind of registers like temperatures or voltages, you have to start a conversion before. I tried to read the internal temperatures and the voltages raw and it worked only after I start the conversion before, and waited for the until conversion is done.
Inside the while block, I've inserted the Is Converting block just like here:
For the S32DS import, I can't reproduce. I've imported the .XML project file and the block built successfully. What version of S32DS are you using?
Hope this helps,
Marius
h
Hello Marius
As you said we need to neglect the cells which are not connected. like , if I am using MC33771B to read 8 cells & the other slots will be read as 0, where it affects in building logic like under voltage fault, is there any solution so we can read & store only required cell voltages ( like in my case 8 cells in series) through BMD tool box
if it is possible then what settings has to be made & in Which Block/
I am using FRMDMC33771BSPI board & S32K144Q100 mc
Thank you
Hello,Marius.
I found that MC33771 MBD toolbox is given under S32K1 tool .And I found your advice about the communication between MPC5744 and MC33772B in the first picture in 2020.
Now I want to use MBDT to establish simulink model to connect MPC577B and MC33771C like the second picture. I want to know if there is a corresponding tool chain now.
If there is not tool , could you provide a demo or description file to help me build model to connect MPC577B and MC33771C?Thank you!
Look forward to your reply.
Thank you very much!