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

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

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

640 Views
edenli
Contributor V

Hi Guys,

   Guys,I don't know whether is it right  that post my doubt in the Community,If not please give me ansower!

    I bought theDual 3-phase PMSM Kit with MPC5643L MCU|NXP from NXP,Nowdays,i am learn the S32 project(MTRCKTDPS5643L Application Software) about the board,i have some question about it.

1# in the file named ADC_MEAS_FLT.c,there is a segment C- code :

tBool ADC_Measure3Ph(pmsmDrive_t *ptr, tFloat Imax)
{
//12bit accuracy,the const 0.5F
ptr->adc.measured.fltPhA.raw = MLIB_Mul(((tFloat)(ioctl(ptr->uni3PeriphCfg.PhABaseAddr,ADC_READ_VALUE, ptr->uni3PeriphCfg.PhAChnlOffset))/(tFloat)0x0FFF-0.5F),Imax);
ptr->adc.measured.fltPhB.raw = MLIB_Mul(((tFloat)(ioctl(ptr->uni3PeriphCfg.PhBBaseAddr,ADC_READ_VALUE, ptr->uni3PeriphCfg.PhBChnlOffset))/(tFloat)0x0FFF-0.5F),Imax);
ptr->adc.measured.fltPhC.raw = MLIB_Mul(((tFloat)(ioctl(ptr->uni3PeriphCfg.PhCBaseAddr,ADC_READ_VALUE, ptr->uni3PeriphCfg.PhCChnlOffset))/(tFloat)0x0FFF-0.5F),Imax);

ptr->iAbcFbck.fltArg1 = MLIB_Mul(MLIB_Sub(ptr->adc.offset[ptr->svmSector].fltPhA, ptr->adc.measured.fltPhA.raw),2);
ptr->iAbcFbck.fltArg2 = MLIB_Mul(MLIB_Sub(ptr->adc.offset[ptr->svmSector].fltPhB, ptr->adc.measured.fltPhB.raw),2);
ptr->iAbcFbck.fltArg3 = MLIB_Mul(MLIB_Sub(ptr->adc.offset[ptr->svmSector].fltPhC, ptr->adc.measured.fltPhC.raw),2);

return(1);
}

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

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

2# in the file named ADC_MEAS_FLT.c,there is another segment C- code :

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

if (!(ptr->adc.flag.B.calibInitDone))
{,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

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

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

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

(1) I am not clearly with theroy for Phase A - DC offset data filtering using MA recursive filter?

Who can help me solve it?

2 Replies

468 Views
Marek_NXP
NXP Employee
NXP Employee

Hi Eden Li,

the current post-processing depends on the signal preprocesing. It means, the current sinusoidal signal is divided by two and shifted by 1.65V to be aligned with ADC input voltage range 0-3.3V. This is done by OAMP on power stage board, please refer to the power stage user manual http://cache.nxp.com/docs/en/user-guide/3PHLVPSUM.pdf.

1.65V is now a zero of alternating signal and represents a number 0.5 in FRAC arithmetic. To perform correct current measurement, you have to substract this offset (-0.5) and multiply the resulting signal by 2.

However, the real offset is not fixed at 1.65V but it may vary around this value. To eliminate the real offset, we apply an MA filter that filters the current raw values and if there is a non-zero value it is stored in to the offset variable. This is performed in calibration routine. The approach (2#) you are refering to is just an another way how to write MA filter.

The u16CalibSamples variable says how many itteration will take the filtering. You may find some differences between the real code and AN, but this is not a fault. The lower value the shorter filtering however, the average value might be less precise, on the contrary, the higher value the higher precision but filtering takes longer time.

Best regards,

Marek  

468 Views
edenli
Contributor V

Hi Marek  ,

Thank you very much! Give me some time to think about it,if i have another question ,i will ask you again.:smileyhappy:

0 Kudos