How to calculate AMCLIB_PMSMBemfObsrvAB_A32 in C programming without the library file.

Showing results for 
Search instead for 
Did you mean: 

How to calculate AMCLIB_PMSMBemfObsrvAB_A32 in C programming without the library file.

Contributor III

Hi I'm using my own board of MKV10Z32VLC7(CM0 based device). Unfortunately the AMCLIB_PMSMBemfObsrvAB_F16 is not available for CM0 based devices. It's based on FOC control of PMSM motor.165326_165326.jpgpastedImage_3.jpg


We are processing with the same processor because of low cost. Now we want to calculate the back-emf sin and cos components to find omega(rotor position) and theta(speed) using AMCLIB_AngleTrackObsrv_F16 function. Is there any methods or formulas to find the back-emf sin and cos components through c-programming.


Thanks in advance.

Labels (1)
4 Replies

NXP Employee
NXP Employee

Hi, of course as each function the sine and cosine components of BEMF can by calculated manually. In general it works according following equations:

f32TmpEObsrvAlpha= psCtrl_sCtrl_f32IAlpha_1 + (psCtrl_sCtrl_a32IGain + psCtrl_sCtrl_a32PGain) * (psUAlBe_f16Alpha - psCtrl_sIObsrv_f32Alpha)
f32TmpEObsrvBeta = psCtrl_sCtrl_f32IBeta_1 +  (psCtrl_sCtrl_a32IGain + psCtrl_sCtrl_a32PGain) * (psUAlBe_f16Beta  - psCtrl_sIObsrv_f32Beta)

f32TmpEObsrvAlpha= f32TmpEObsrvAlpha / sqrt(f32TmpEObsrvAlpha ^ 2 + f32TmpEObsrvAlpha ^ 2)
f32TmpEObsrvBeta = f32TmpEObsrvBeta  / sqrt(f32TmpEObsrvBeta ^ 2  + f32TmpEObsrvBeta ^ 2)

f32TmpIObsrvAlpha= a32IGain * psCtrl_sIObsrv_f32Alpha + a32UGain * psUAlBe_f16Alpha + psIAlBe_f16Beta  * f16Speed * a32WIGain + a32EGain * f32TmpEObsrvAlpha         
f32TmpIObsrvBeta = a32IGain * psCtrl_sIObsrv_f32Beta  +  a32UGain * psUAlBe_f16Beta - psIAlBe_f16Alpha * f16Speed * a32WIGain + a32EGain * f32TmpEObsrvBeta

Sin = -f32TmpEObsrvAlpha ...   for  f16Speed < 0 

Sin =  f32TmpEObsrvAlpha ...   for  f16Speed >= 0                                       
Cos= -f32TmpEObsrvBeta  ...   for  f16Speed <= 0

Cos= f32TmpEObsrvBeta    ...   for  f16Speed > 0

The results of some operation must be saturated or correctly shifted to obtain the right value range and in real there are some tricks to calculate the results with determined precision.

Contributor III


Above method is implemented in MC56F82726.

0 Kudos

Contributor III


The terms psCtrl_sCtrl_f32IAlpha_1, psCtrl_sCtrl_a32IGain, psCtrl_sCtrl_a32PGain etc., are available only in AMCLIB_PMSMBemfObsrvAB_F16 library file. Here in MKV10Z32VLC7 the files are missing so I can't able to find out these values.

There is no backemf observer available for ALPHA and BETA terms, available only for D and Q terms.

Here we are porting the code from MC56F82726 to MKV10Z32VLC7. AMCLIB_PMSMBemfObsrvAB_F16 is available in MC56F82726 but not in KV10.

In MC56F82726 we proceeded with the following format:

* First we have calculated the ABC phase current iABC

* Through Clark transformation iABC in converted to iAlpha and iBeta

* We have calculated the voltage of alpha and beta (vAlpha and vBeta)  and initial speed internally

* Using above iAlpha&iBeta, vAlpha&vBeta and speed in AMCLIB_PMSMBemfObsrvAB_F16 we have found out sin and cos components from ACLIB_BEMF_OBSRV_AB_T of AMCLIB_PMSMBemfObsrvAB_F16.

* From the sin and cos components we have calculated the angel and speed by using ACLIB_AngleTrackObsrv.

* Then we carried out park transformation, decoupling, parkinv transformation upto SVM.

The above flow is working correctly  in MC56F82726.

But while porting to KV10 the AMCLIB_PMSMBemfObsrvAB_F16 is not available only AMCLIB_PMSMBemfObsrvDQ is available. So I need to change the code based on the available library files.

In KV10 we have only AMCLIB_PMSMBemfObsrvDQ function, so how to process with the same to find out the angel and speed. What changes need to be done in code ??

0 Kudos

Contributor III

How to calculate the sin and cos components manually??                            Kinetis Motor Suite‌, Deactivated user‌ MarMipavelrechkubanbvicentegomezkhumphriMandardhaval‌‌‌‌‌‌‌, RHinnen‌,

0 Kudos