About S32 project of the Dual motor control Demo board,I have a qusetion about the ADC

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

About S32 project of the Dual motor control Demo board,I have a qusetion about the ADC

681 Views
edenli
Contributor V

Hi Guys,

dumitru-daniel.popapetrfajmon-b17364

I down load the MTRCKTDPS5643L Application Software,and i use the S32 Design Studio for Power Architecture v1.1 to open it,There is a piece of code shown:

tBool ADC_Measure2Ph(pmsmDrive_t *ptr)
{
switch(ptr->svmSector)
{
case 2:
case 3:
{
ptr->adc.measured.fltPhA.raw = (tFloat)((ioctl(ptr->uni3PeriphCfg.PhABaseAddr,ADC_READ_VALUE, ptr->uni3PeriphCfg.PhAChnlOffset)));
ptr->adc.measured.fltPhC.raw = (tFloat)((ioctl(ptr->uni3PeriphCfg.PhCBaseAddr,ADC_READ_VALUE, ptr->uni3PeriphCfg.PhCChnlOffset)));
ptr->adc.measured.fltUdcb.raw = (tFloat)((ioctl(ptr->uni3PeriphCfg.UdcBaseAddr,ADC_READ_VALUE, ptr->uni3PeriphCfg.UdcChnlOffset)));

ptr->iAbcFbck.fltArg1 = MLIB_Mul(MLIB_Sub(ptr->adc.offset[ptr->svmSector].fltPhA,ptr->adc.measured.fltPhA.raw),2);
ptr->iAbcFbck.fltArg3 = MLIB_Mul(MLIB_Sub(ptr->adc.offset[ptr->svmSector].fltPhC,ptr->adc.measured.fltPhC.raw),2);
ptr->iAbcFbck.fltArg2 = MLIB_Neg(MLIB_Sub(ptr->iAbcFbck.fltArg1,ptr->iAbcFbck.fltArg3));
return(1);
}
case 4:
case 5:
{
ptr->adc.measured.fltPhA.raw = (tFloat)((ioctl(ptr->uni3PeriphCfg.PhABaseAddr,ADC_READ_VALUE, ptr->uni3PeriphCfg.PhAChnlOffset)));
ptr->adc.measured.fltPhB.raw = (tFloat)((ioctl(ptr->uni3PeriphCfg.PhBBaseAddr,ADC_READ_VALUE, ptr->uni3PeriphCfg.PhBChnlOffset)));
ptr->adc.measured.fltUdcb.raw = (tFloat)((ioctl(ptr->uni3PeriphCfg.UdcBaseAddr,ADC_READ_VALUE, ptr->uni3PeriphCfg.UdcChnlOffset)));

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

return(1);
}
case 1:
case 6:
default:
{
ptr->adc.measured.fltPhB.raw = (tFloat)((ioctl(ptr->uni3PeriphCfg.PhBBaseAddr,ADC_READ_VALUE, ptr->uni3PeriphCfg.PhBChnlOffset)));
ptr->adc.measured.fltPhC.raw = (tFloat)((ioctl(ptr->uni3PeriphCfg.PhCBaseAddr,ADC_READ_VALUE, ptr->uni3PeriphCfg.PhCChnlOffset)));
ptr->adc.measured.fltUdcb.raw = (tFloat)((ioctl(ptr->uni3PeriphCfg.UdcBaseAddr,ADC_READ_VALUE, ptr->uni3PeriphCfg.UdcChnlOffset)));

ptr->iAbcFbck.fltArg1 = 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);
ptr->iAbcFbck.fltArg2 = MLIB_Neg(MLIB_Sub(ptr->iAbcFbck.fltArg2,ptr->iAbcFbck.fltArg3));

return(1);
}
}
}

And i   right click the mouse,and jump to code as below:

/*------------------------------------------------------------------------*//*!
@brief Structure containing list of base addresses and offsets of particular
channel related to UNI3 connector and to PMSM application
*//*-------------------------------------------------------------------------*/
typedef struct
{
tS32 PhABaseAddr; // Phase A current analog input - ADC Base address
tS16 PhAChnlOffset; // Phase A current analog input - ADC channel offset
tS32 PhBBaseAddr; // Phase B current analog input - ADC Base address
tS16 PhBChnlOffset; // Phase B current analog input - ADC channel offset
tS32 PhCBaseAddr; // Phase C current analog input - ADC Base address
tS16 PhCChnlOffset; // Phase C current analog input - ADC channel offset
tS32 UdcBaseAddr; // Udc bus voltage analog input - ADC Base address
tS16 UdcChnlOffset; // Udc bus voltage analog input - ADC channel offset
tU16 alignCntr; // Alignment counter variable
tFloat alignVoltage;
tS32 flexPwmBaseAddr; // flexPWM Base address related to UNI3 connector
}uni3PeriphCfgPmsm_t;

There is a qusetion that how the define of PhABaseAddr link to the ADC Base address?

2 Replies

496 Views
dumitru-daniel_
NXP Employee
NXP Employee

Hi edenli

Just looking at the code - i see that ADC_Measure2Ph() is not used in the application. There is no call to this function. Instead the ADC_Measure3Ph() is used.

Nonetheless, the PhABaseAddr is a member of the uni3PeriphCfgPmsm_t structure which in turn is a member of pmsmDrive_t FOC PMSM structure.

Then based on this structure there are 2 other structures created M1 and M2 for both motors.

// declaration for UNI3_1 - default
DECLARATION(M1, UNI3_M1, POSPE_M1, CB_M1, RESOLVER_FBCK, ENCODER_FBCK) // declaration of the first motor

// declaration for UNI3_2 if enabled
#ifdef UNI3_2
DECLARATION(M2, UNI3_M2, POSPE_M2, CB_M2, RESOLVER_FBCK, ENCODER_FBCK) // declaration of the second motor
#endif

 

Then following the initialization sequence you should reach to this defines:

/* ADC setting related to the UNI3_ M1 connector*/
#define UNI3_M1_CFG_DEFAULT ADC1_BASE,ADC_CDR11_OFFSET,\
ADC1_BASE,ADC_CDR12_OFFSET,\
ADC0_BASE,ADC_CDR2_OFFSET,\
ADC0_BASE,ADC_CDR1_OFFSET,\
M1_ALIGN_DURATION,\
M1_ALIGN_VOLTAGE,\
FLEXPWM0_BASE

/* ADC setting related to the UNI3_ M2 connector*/
#define UNI3_M2_CFG_DEFAULT ADC0_BASE,ADC_CDR13_OFFSET,\
ADC1_BASE,ADC_CDR14_OFFSET,\
ADC1_BASE,ADC_CDR2_OFFSET,\
ADC0_BASE,ADC_CDR3_OFFSET,\
M2_ALIGN_DURATION,\
M2_ALIGN_VOLTAGE,\
FLEXPWM1_BASE

The ADC channel used is set via the ***_CDRxx_*** define.

Hope this helps!

Daniel

497 Views
edenli
Contributor V

Hi Daniel,

Thank you for your reply!

Best Regards!

Eden Li

0 Kudos