About the ADC_ModuleCalib() function in the Dual motor demo board MPC5643L C-code project

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

About the ADC_ModuleCalib() function in the Dual motor demo board MPC5643L C-code project

1,395 Views
edenli
Contributor V

Hidumitru-daniel.popa‌,

   Firstly, I'am sorry to bother you again,Because i posted my  question to another  Community named MPC5XXX,the link:The question about the S32 C-code project of dual motor demo board for MPC5643L ,but Nobody reply to me,so whether the Web address is right about the dual motor demo board C-code?

   Daniel,Can you give me the link abou the Community?

  BTY,Can you help me slove my follow question,shown as below?

A C-code segment in the main.c shown as below:

tBool ADC_ModuleCalib(pmsmDrive_t *ptr)
{
static tFloat fltFiltOutput;

if (!(ptr->adc.flag.B.calibInitDone))
{
ptr->adc.calibCntr = 4096; // 2^(8 + 4) order to accommodate settling time of the filter

ptr->adc.measured.fltPhA.filt = 0.0F;
ptr->adc.measured.fltPhB.filt = 0.0F;
ptr->adc.measured.fltPhC.filt = 0.0F;
ptr->adc.measured.fltUdcb.filt = 0.0F;

ptr->adc.flag.B.calibDone = 0;
ptr->adc.flag.B.calibInitDone = 1;// initial setup for DC offset calibration done
}

if (!(ptr->adc.flag.B.calibDone))
{
/* --------------------------------------------------------------
* Phase A - DC offset data filtering using MA recursive filter
* filt= filtered value
* ------------------------------------------------------------ */

PART A:
ptr->adc.measured.fltPhA.filt = MLIB_Add(ptr->adc.measured.fltPhA.filt , ptr->adc.measured.fltPhA.raw);
fltFiltOutput = MLIB_Div(ptr->adc.measured.fltPhA.filt,ptr->adc.param.u16CalibSamples);
ptr->adc.measured.fltPhA.filt = MLIB_Sub(ptr->adc.measured.fltPhA.filt,fltFiltOutput);
ptr->adc.offset[ptr->svmSector].fltPhA = fltFiltOutput;

, , , ,,,,,,,,,,,,,,,,,,,,,,,,,,,,

if ((--ptr->adc.calibCntr)<=0)
{
ptr->adc.flag.B.calibDone = 1; // end of DC offset calibration
}
}

return (ptr->adc.flag.B.calibDone);
}

Analysis:

  According to the C-code segment,we can conclude that in the ADC_ModuleCalib() function ,will execute 4096 cycles in the ADC_ModuleCalib() funtion, then jump out the ADC_ModuleCalib().

The Value of u16CalibSamples is defined 256 in the stateInit().

The reference AN4518:

pastedImage_34.png

question:

1#,Why we assign the 4096 to ptr->adc.calibCntr,rather than  ptr->adc.calibCntr=.u16CalibSamples?

I thought we should sum the ptr->adc.measured.fltPhA.raw,and then averaged the values,that is the sum divide u16CalibSamples.

2#,I seemly not cleary with the Phase A - DC offset data filtering using MA recursive filter?

and the theory is,that is How to comprehend the the four lines C-code in the PART A ?

0 Kudos
6 Replies

1,093 Views
petrfajmon-b173
NXP Employee
NXP Employee

Hi Eden Li,

  your questions were answered by Marek Stulrajter here:  

The question about the S32 C-code project of dual motor demo board for MPC5643L  

Best Regards,

Petr

0 Kudos

1,093 Views
petrfajmon-b173
NXP Employee
NXP Employee

Hi Daniel, Eden Li,

  I have contacted my colleagues who are owners of the example code for "Dual 3-phase Permanent Magnet Synchronous Motor (PMSM) Motor Control Development Kit for the MPC564xL". They will look on your question as soon as possible.

Regards,

Petr

1,093 Views
dumitru-daniel_
NXP Employee
NXP Employee

Hi edenli‌,

The MPC5xxx Community you asked the question is OK. Please allow some time until peoples will figure it out - that is now a trivial piece of code, therefore a specialist opinion in such matter will be needed.

I can't answer all the question because i don't know that sw - i can only look at it and read it - but behind that i do not know what the designer though about it:

Regarding #1 and #2

(1) Why the c-code need subtract the 0.5F?

(2) why the c- code need mulitiply the constant 2?

in think is a sort of round up to floor followed by a scalling (not sure)

Regarding #3

(3) the initial value of the u16CalibSamples is 0, and if adc.measured.fltPhA.filt divide the u16CalibSamples,the ansower is INF? that is right?

No, there is no division by 0 since there is a function stateInit() that initialize the 

ptr->adc.param.u16CalibSamples = 256; // number of samples = 2^u16CalibSamples = 2^8 = 256

prior to calling the ADC_ModuleCalib()

Hope this helps!

Daniel

0 Kudos

1,093 Views
edenli
Contributor V

Hi Daniel,

I am sorry to bother you again!:smileysad:

My questions have posted Out in the  MPC5XXX Community,But there is  nobody replying my question.Can you give some proposal to solve it ?or Can you recommend some one to help me?

Thank you very much!

Best Regards!

Eden Li

0 Kudos

1,093 Views
dumitru-daniel_
NXP Employee
NXP Employee

petrfajmon-b17364‌,

Who's the person responsible for this code? Looks like nobody gave any feedback on MPC5xxx Community. Can you ask someone familiar with this topic to have a look and advice.

Thank you!

Daniel

0 Kudos

1,093 Views
edenli
Contributor V

OK,Thank you for your reply!

0 Kudos