MC33771 measurement channel timing issue

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

MC33771 measurement channel timing issue

Jump to solution
2,996 Views
paneri
Contributor III

Hi, I am working on MC33771BSP AFE and I am able to read measurement registers properly but the time taken from sending start of conversion bit to read current measurement register is 7ms , but as per datasheet it will take only 0.86 ms to read all measurement registers. Please any one support as I need to reduce the time for reading the measurement registers.

measuremnt_channel.PNG

Thanks.
Paneri Shah.

0 Kudos
1 Solution
2,937 Views
jann_
NXP Employee
NXP Employee

Hi Paneri,

I am the developer of the SW driver you shared screenshots from. A few notes and recommendations follows:

1. Time values in the BCC datasheet do not count any SW overhead. They asume time for transmission of SOC command (at the physical layer = SPI) + conversion + reading the values back. No time for pre- (and post-) processing of data at MCU is counted.

2. I suppose you are using S32K144 MCU with some code based on the examples provided with the SW driver. Therefore, the time mentioned in the datasheet is extended by packing the SPI frames, calculating/checking CRC and finally by not negligible time overhead of used S32K144 SPI SDK in your case.

3. If you would like to decreace the time for measuring the current to the possible minimum, I would recommend:

  • Calling of BCC_Meas_IsConverting() in getMeasurements() is not needed if your BCC_MCU_WaitUs() is implemented accurately. This can be removed as one more read-request causes a time overhead.
  • If you are interested only in the current measurement, read back only the MEAS_ISENSE1 and MEAS_ISENSE2 registers (instead of 30 registers by BCC_Meas_GetRawValues()). This will save really a lot of time.
  • Optimize pre-processing: Pre-create the content of sent SPI frames including CRCs - i.e. write your own optimized code and do not use the BCC SW driver to dynamically create the frames.
  • Optimize SPI transfer: For the SPI transmission, do not use the SDK SPI driver in BCC_MCU_* functions but implement a so-called "pooling" approach for the LPSPI periphery to directly access the LPSPI periphery registers. When the periphery is well configured, only (+-) three register accesses are enough to start the SPI transmission including the movement of transmitted data to LPSPI FIFO.
    The same with reading the data received from SPI MISO to LPSPI periphery.

Best regards,

Jan

View solution in original post

0 Kudos
8 Replies
2,991 Views
TomasVaverka
NXP TechSupport
NXP TechSupport

Hi Paneri,

Are you polling the EOC_N bit or wait for the maximum conversion time (546us in 16-bit mode, with some margin typically 600us) before reading all the measured values?

Is your SPI communication running at 4Mbps? If yes, it should indeed take in total ~900us.

Best regards,

Tomas

0 Kudos
2,952 Views
paneri
Contributor III

Hello Tomas,
I have a requirement to detect over current in 500us. Is there any way to do it?

0 Kudos
2,972 Views
paneri
Contributor III

Hi Tomas, I have changed frequency to 4Mhz and ensure it using Hantek(please check image).
But still the time is not reduced after increasing frequency also. I have attached the code snippet below. Please take a look and support for reducing time of reading measurement registers.SPI frequency set to 4Mhz.SPI frequency set to 4Mhz.getMeasurement functiongetMeasurement function

paneri_0-1616494179738.png

paneri_2-1616494235706.png

 

 

 

 

0 Kudos
2,933 Views
jann_
NXP Employee
NXP Employee

If I'm counting well:

When you would be reading only the current, you should save reading of 24 registers in terms of the t(CLST_SPI) datasheet value, i.e. 24 times 40-bit SPI frame @4MHz, i.e. more than 240us from the t(CLST_SPI) datasheet value.

Therefore, with a highly optimized SW, you could be theoretically able to read the current within 500 us with the BCC configured to 15-bit ADC (not 16-bit ADC)

Best regards,

Jan

0 Kudos
2,938 Views
jann_
NXP Employee
NXP Employee

Hi Paneri,

I am the developer of the SW driver you shared screenshots from. A few notes and recommendations follows:

1. Time values in the BCC datasheet do not count any SW overhead. They asume time for transmission of SOC command (at the physical layer = SPI) + conversion + reading the values back. No time for pre- (and post-) processing of data at MCU is counted.

2. I suppose you are using S32K144 MCU with some code based on the examples provided with the SW driver. Therefore, the time mentioned in the datasheet is extended by packing the SPI frames, calculating/checking CRC and finally by not negligible time overhead of used S32K144 SPI SDK in your case.

3. If you would like to decreace the time for measuring the current to the possible minimum, I would recommend:

  • Calling of BCC_Meas_IsConverting() in getMeasurements() is not needed if your BCC_MCU_WaitUs() is implemented accurately. This can be removed as one more read-request causes a time overhead.
  • If you are interested only in the current measurement, read back only the MEAS_ISENSE1 and MEAS_ISENSE2 registers (instead of 30 registers by BCC_Meas_GetRawValues()). This will save really a lot of time.
  • Optimize pre-processing: Pre-create the content of sent SPI frames including CRCs - i.e. write your own optimized code and do not use the BCC SW driver to dynamically create the frames.
  • Optimize SPI transfer: For the SPI transmission, do not use the SDK SPI driver in BCC_MCU_* functions but implement a so-called "pooling" approach for the LPSPI periphery to directly access the LPSPI periphery registers. When the periphery is well configured, only (+-) three register accesses are enough to start the SPI transmission including the movement of transmitted data to LPSPI FIFO.
    The same with reading the data received from SPI MISO to LPSPI periphery.

Best regards,

Jan

0 Kudos
2,866 Views
paneri
Contributor III

Hi,

I am trying to optimize the BCC_S32k144_Monitoring_Diagnostics code by transmit and receive LPSPI data in polling method. I am able to write the data for the first time properly but while reading the data the RDF flag of status register is not getting set because of which I am not able to read any data and simply getting CRC error. I have attached the code snippets below. Please help to find where is the issue.

0 Kudos
2,861 Views
jann_
NXP Employee
NXP Employee

Hi paneri,

the issue of your code is that RDR and TDR are 32b FIFO registers (not 8bit!). I cannot test any code as have not the HW equipment at home, but my test implementation of BCC_MCU_TransferSpi was like:

/* Not sure about the byte order...!! */
LPSPI0->TDR = (transBuf[0] << 24U) | (transBuf[1] << 16U) | (transBuf[2] << 8U) | (transBuf[3]);
LPSPI0->TDR = (transBuf[4]);

/* Wait till transfer is done. (LPSPI0->FSR[TXCOUNT] is 0) */
/* Wait till 2 words are in RX FIFO (LPSPI0->FSR[RXCOUNT] is 2) */
/* Read that two 32b words from LPSPI0->RDR a parse individual bytes to recvBuf */

BR,
Jan

0 Kudos
2,901 Views
paneri
Contributor III

Hi jann,

Thanks for the information, I will try to optimize the code based on your suggestions.

0 Kudos