This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

background loop & state machine with cpu timer 0/1/2

Other Parts Discussed in Thread: TMS320F28035

In FOC example I know that we run mainISR in RAM which is interrupted with ADC but,
My questions :
what is background loop?
Why are 3 cpu timers (0/1/2) runed in this example? Do they count to special values?
What is “STATE-MACHINE SEQUENCING AND SYNCRONIZATION FOR SLOW BACKGROUND TASKS” ?
What is duty of these functions and pointers during mainISR execution ?
where does background loop execute ? in Flash or RAM?


// State Machine function prototypes
//------------------------------------
// Alpha states
void A0(void);    //state A0
void B0(void);    //state B0
void C0(void);    //state C0

// A branch states
void A1(void);    //state A1
void A2(void);    //state A2
void A3(void);    //state A3

// B branch states
void B1(void);    //state B1
void B2(void);    //state B2
void B3(void);    //state B3

// C branch states
void C1(void);    //state C1
void C2(void);    //state C2
void C3(void);    //state C3

// Variable declarations
void (*Alpha_State_Ptr)(void);    // Base States pointer
void (*A_Task_Ptr)(void);        // State pointer A branch
void (*B_Task_Ptr)(void);        // State pointer B branch
void (*C_Task_Ptr)(void);        // State pointer C branch


Best Wishes,
Ali Karimi

  • what is background loop?
    A: All no running in ISR (interrupt subroutine) codes, and in themain() loop.

    Why are 3 cpu timers (0/1/2) run in this example? Do they count to special values?
    A: Just an example code, you might use any timer, or only one or two CPU timer to implement. And you could set the timer period based on the requirement of your system control.

    What is “STATE-MACHINE SEQUENCING AND SYNCHRONIZATION FOR SLOW BACKGROUND TASKS”?
    A: As replied to you above, an example sequence control implementation, the timer with a different period to achieve different execution frequency.

    What is the duty of these functions and pointers during mainISR execution?
    A: It's the period of timer if the bandwith of mainISR is not occupied totally.

    where does background loop execute ? in Flash or RAM?
    A: Supports both, depends on your requirement.
  • Thank you so much Yanming Luo,

    Let us talk about HVACI Sensorless Example on TMS320F28035. Are below sentences true? (After sentences, I am going to ask 2 questions.)
    1) “Main” and “Alpha/A/B/C states” execute in Flash (background).
    2) Only “MainISR” executes in RAM.
    3) In each “infinite loop” (for(;;)), (*Alpha_State_Ptr)(); recalls:
    - in first time: A0 then A1 (CPU Timer 0 for mSec1)
    - in second time: B0 then B1(CPU Timer 1 for mSec5)
    - in third time: C0 then C1(CPU Timer 2 for mSec50)

    - in forth time: A0 then A2
    - in fifth time:B0 then B2
    - in sixth time:C0 then C2

    - in seventh time:A0 then A3
    - in eighth time:B0 then B3
    - in ninth time:C0 then C3

    - in tenth time: repeats
    4)
    and my questions:
    1) What is relation between “MainISR” timing and “(*Alpha_State_Ptr)();” timing ?( What does happen if “MainISR” does not ends before “(*Alpha_State_Ptr)();” ending ?)
    2) Why Timer0 is 1msec and Timer1 is 5msec and Timer2 is 50msec?


    Best Wishes,
    My email address : ali.karimi6586@gmail.com
    Ali karimi
  • As replied to you above,
    1. Not critical timing relationship, it's not must-have for motor drive, just used for some states and faults check.
    2. The timers for background loop are not critical in the example project, you could change it based on your requirement.
  • Hi,

    I am really confused and i need answers of this post. please somebody illustrate it for me.
    i understood that i can use even only one of timers and does not matter which timers.
    but i need answer of the other parts.

    Best Regards
    Ali Karimi
  • Suppose your two questions should be replied above. Could you please have more description if you have any further questions?
    Btw, mainISR will be trigged by an interrupt, it has the higher priority than any background code, so all codes in background loop must wait for the mainISR ends, and then execute continuously. As you see in the example project, all the state machines code are executed in the background loop.
  • Hi Yanming,

    As you told above :"Not critical timing relationship, it's not must-have for motor drive, just used for some states and faults check"
    -can you mention some of those states and faults? where do we need to have background loop 1msec or 5msec or 50msec?
    -does background loop execute in Flash?

    thank you for your patient

    Best Wishes,

    Ali

  • 1. No any core algorithm of motor control is executed in the background loop in the example project, just in mainISR. You could add some the fault of the power module, or enable/disable the flag to run the motor drive without critical timing requirement that depends on your requirement.
    2. As replied to you above, it can be executed in RAM or FLASH that depends on the configuration of the project. The example project supports both options with different build configurations.
  • thank you so much dear Yanming,

    I am confused about one thing.

    suppose a part of code(it is not ISR) is running in RAM (we used MemCopy function to copy it to RAM) and the other part of code is running on Flash.
    1.do both parts work parallel?
    2.where can they work parallel and when can not? (does any latency or delay exist for executing software codes (like mathematical
    algorithm) and hardware duty (like blinking a GPIO or timers)?)
  • 1. As you known, the codes should be executed sequentially in an embedded controller, the code in an ISR will interrupt the execution code in background loop, and will back the ground loop after all the code in ISR completed the execution. You might have a look at below link to get more information.
    processors.wiki.ti.com/.../Category:C2000_Training
    processors.wiki.ti.com/.../C2000_One-Day_Workshop

    2. Not always if it's done in a single core controller.
  • Hello dare Yanming,

    I understood.you are right. as you mentioned, a single core embedded micro controller executes codes sequentially.
    thank you so much.

    Best wishes,
    Ali