Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Analyze FOC timing of AMCBLDC and AMC2C #80

Closed
Nicogene opened this issue Feb 2, 2024 · 6 comments
Closed

Analyze FOC timing of AMCBLDC and AMC2C #80

Nicogene opened this issue Feb 2, 2024 · 6 comments
Assignees
Labels
domain-firmware Pertains to FW development team-fix Activity performed by Team FIX

Comments

@Nicogene
Copy link
Member

Nicogene commented Feb 2, 2024

          Let me try to recap what I got from a F2F alignment with @sgiraz.
  1. There's pretty much NO difference between using STD or CMSIS ops on AMCBLDC and AMC2C.
  2. On the AMCBLDC, the FOC is taking up $8$ $\mu s$ and NOT $17$ $\mu s$. The difference is represented by the ADC operations.
  3. FOC takes up $14$ $\mu s$ on AMC2C, longer than on AMCBLDC.
  • Point 1 completes this issue ✅ We go with STD. See FOC: use STD instead of CMSIS #75.
  • Follow-up question on Point 2: "Why does ADC last that long compared to FOC? Is there any margin for improvement?"
  • Follow-up question on Point 3: "Why is AMC2C slower than AMCBLDC?" We know this is an ongoing study and we're probably at the right point to contact ST.

cc @Nicogene @sgiraz @marcoaccame @maggia80 @mfussi66

Originally posted by @pattacini in #67 (comment)

@Nicogene

This comment was marked as off-topic.

@Nicogene Nicogene added team-fix Activity performed by Team FIX domain-firmware Pertains to FW development labels Feb 2, 2024
@Nicogene Nicogene changed the title Analyze ADC timing of AMCBLDC and AMC2C Analyze FOC timing of AMCBLDC and AMC2C Feb 2, 2024
@sgiraz
Copy link
Contributor

sgiraz commented Feb 7, 2024

➡️ On AMCBLDC

In point 2 I want to remark that the $8.3$ $\mu s$ are taken to execute the AMC_BLDC_step_FOC() function when the control mode is IDLE.
When the control mode is set to CURRENT instead, it takes $10.7$ $\mu s$, see the scope plot below:

TEK00004

I Apologize for the mistake/confusion!

By the way, the EventViewer shows that the whole DMA interrupt takes about $15$ $\mu s$ :

Screenshot 2024-02-07 163653

Measuring with the scope we got $13.1$ $\mu s$ measuring the whole onCurrents_FOC_innerloop function:

TEK00005

...And $14.34$ $\mu s$ considering the whole DMA:

TEK00006

static void adc2_HalfTransferComplete_cb(ADC_HandleTypeDef *hadc)
{
    // TODO: start measuring from here
    
    GPIOB->BSRR = (uint32_t)0x0020; // 0x0004

    
#if defined(MOTORHAL_changes) 
    rawCph1 = adc2_Buffer[0].cph1;
    rawCph2 = adc2_Buffer[0].cph2;
    rawCph3 = adc2_Buffer[0].cph3;
    pwmSetCurrents_cb(rawCph1, rawCph2, rawCph3);
#if !defined(MOTORHALCONFIG_DONTUSE_RUNTIMECURR_FILTERING)
    analogMovingAverageFromISR(&cph1Filter, rawCph1); 
    analogMovingAverageFromISR(&cph2Filter, rawCph2);
    analogMovingAverageFromISR(&cph3Filter, rawCph3);   
    

#endif    
#else
    rawCph1 = adc2_Buffer[0].cph1;
    rawCph2 = adc2_Buffer[0].cph2;
    rawCph3 = adc2_Buffer[0].cph3;
    pwmSetCurrents_cb(rawCph1, rawCph2, rawCph3);
    analogMovingAverageFromISR(&cph1Filter, rawCph1);
    analogMovingAverageFromISR(&cph2Filter, rawCph2);
    analogMovingAverageFromISR(&cph3Filter, rawCph3);
#endif

    GPIOB->BRR = (uint32_t)0x0020; // 0x0004
}

In summary (when in CURRENT control mode):

AMC_BLDC_step_FOC() function $10.7$ $\mu s$
onCurrents_FOC_innerloop function $13.1$ $\mu s$
the whole DMA $14.34$ $\mu s$

cc @Nicogene @pattacini @marcoaccame @mfussi66

@sgiraz
Copy link
Contributor

sgiraz commented Feb 8, 2024

➡️ AMC2C (66.6 KHz)

When the control mode is set to CURRENT instead, the AMC_BLDC_step_FOC() function takes $20$ $\mu s$, see the scope plot below:

TEK00007

The the whole onCurrents_FOC_innerloop function takes $25.45$ $\mu s$:

TEK00008

The whole DMA takes $26.86$ $\mu s$:

TEK00009

With the EventViewer we got about $29$ $\mu s$ :

Screenshot 2024-02-08 111525

In summary (when in CURRENT control mode):

AMC_BLDC_step_FOC() function $20$ $\mu s$
onCurrents_FOC_innerloop function $25.45$ $\mu s$
the whole DMA $26.86$ $\mu s$

cc @pattacini @marcoaccame @maggia80 @Nicogene

@Nicogene
Copy link
Member Author

Nicogene commented Feb 8, 2024

Great analysis @sgiraz !

To summarize we have

AMC2C (66.6 KHz) AMCBLDC
AMC_BLDC_step_FOC() function $20$ $\mu s$ $10.7$ $\mu s$
onCurrents_FOC_innerloop function $25.45$ $\mu s$ $13.1$ $\mu s$
the whole DMA $26.86$ $\mu s$ $14.34$ $\mu s$

"Why is AMC2C slower than AMCBLDC?" We know this is an ongoing study and we're probably at the right point to contact ST.

A ~ 2x factor seems a lot, maybe it is the case of contacting ST

@Nicogene
Copy link
Member Author

The analysis of @sgiraz pointed out an important timing issue on amc2c, and this will be further investigate contacting ST, after that we hopefully know how to align the performance of the two boards.

Closing.

@pattacini
Copy link
Member

Interesting timing for a comparison:

image

Source: https://www.mathworks.com/campaigns/offers/next/field-oriented-control-techniques-white-paper.html

Note

We're not that bad, after all!

cc @marcoaccame @sgiraz @mfussi66 @Nicogene @maggia80

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain-firmware Pertains to FW development team-fix Activity performed by Team FIX
Projects
None yet
Development

No branches or pull requests

3 participants