ETPU SM

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

ETPU SM

1,447 Views
christofer_ft
Contributor II

Greetings,

 

Does anyone have a working eTPU   SM (Stepper Motor) example?

I trying to use the MCU MPC5777C  . My intention was to use ETPUB Channels 7 to 10.

 

I am trying to control a stepper based on AN2869. But I think I didn't understand something. The motor flags never return to zero. after calling fs_etpu_sm_get_cp(...). Which seems to be returning some random values.

 

Maybe the problem is the desired position, I trying to pass the possible values for HALF STEP config, or I think so {0x0E0E0E, 0x1C1C1C, 0x383838, 0x707070, 0xE0E0E0, 0x1C1C1C, 0x383838}.

 

Some external definitions

/*====== The FS_ETPU_SM_2PHASE_HALF_STEP configuration predefines: =====*/
#define FS_ETPU_SM_CFG_1_CHANNELS 4
#define FS_ETPU_SM_CFG_1_FM FS_ETPU_SM_HALF_STEP
#define FS_ETPU_SM_CFG_1_PIN_SEQUENCE 0x070707
/* can be replaced by rotated versions:
0x0E0E0E, 0x1C1C1C, 0x383838, 0x707070, 0xE0E0E0, 0x1C1C1C, 0x383838 */

 

My code (I don't know how to paste code here, it messed up a bit):

void StepperDemo(int32_t steps) {
#define SM_ETPU_CHANNEL(x) (64 + (x))
#define SM_ACCEL_TABLE_SIZE 1

static const pin_settings_config_t etpuBPinMux[] = {
    {
        .base              = SIU,
        .pinPortIdx        = 154u,
        .mux               = PORT_MUX_PRIMARY,
        .outputBuffer      = PORT_OUTPUT_BUFFER_ENABLED,
        .slewRateCtrl      = HALF_STRENGTH_WITH_SLEWRATE_CONTROL,
        .openDrain         = PORT_OPEN_DRAIN_DISABLED,
        .hysteresis        = PORT_HYSTERESYS_DISABLED,
        .driveSelect       = PORT_MINIMUM_DRIVE_STRENGTH,
        .inputBuffer       = PORT_INPUT_BUFFER_DISABLED,
        .pullConfig        = PORT_INTERNAL_PULL_UP_ENABLED,
    },
    {
        .base              = SIU,
        .pinPortIdx        = 155u,
        .mux               = PORT_MUX_PRIMARY,
        .outputBuffer      = PORT_OUTPUT_BUFFER_ENABLED,
        .slewRateCtrl      = HALF_STRENGTH_WITH_SLEWRATE_CONTROL,
        .openDrain         = PORT_OPEN_DRAIN_DISABLED,
        .hysteresis        = PORT_HYSTERESYS_DISABLED,
        .driveSelect       = PORT_MINIMUM_DRIVE_STRENGTH,
        .inputBuffer       = PORT_INPUT_BUFFER_DISABLED,
        .pullConfig        = PORT_INTERNAL_PULL_UP_ENABLED,
    },
    {
        .base              = SIU,
        .pinPortIdx        = 156u,
        .mux               = PORT_MUX_PRIMARY,
        .outputBuffer      = PORT_OUTPUT_BUFFER_ENABLED,
        .slewRateCtrl      = HALF_STRENGTH_WITH_SLEWRATE_CONTROL,
        .openDrain         = PORT_OPEN_DRAIN_DISABLED,
        .hysteresis        = PORT_HYSTERESYS_DISABLED,
        .driveSelect       = PORT_MINIMUM_DRIVE_STRENGTH,
        .inputBuffer       = PORT_INPUT_BUFFER_DISABLED,
        .pullConfig        = PORT_INTERNAL_PULL_UP_ENABLED,
    },
    {
        .base              = SIU,
        .pinPortIdx        = 157u,
        .mux               = PORT_MUX_PRIMARY,
        .outputBuffer      = PORT_OUTPUT_BUFFER_ENABLED,
        .slewRateCtrl      = HALF_STRENGTH_WITH_SLEWRATE_CONTROL,
        .openDrain         = PORT_OPEN_DRAIN_DISABLED,
        .hysteresis        = PORT_HYSTERESYS_DISABLED,
        .driveSelect       = PORT_MINIMUM_DRIVE_STRENGTH,
        .inputBuffer       = PORT_INPUT_BUFFER_DISABLED,
        .pullConfig        = PORT_INTERNAL_PULL_UP_ENABLED,
    },
};

static struct {
enum {
StepperState_Init,
StepperState_Idle,
StepperState_Moving,
} state;
} data;

static const uint16_t accel_tbl[SM_ACCEL_TABLE_SIZE] = {
1
};

switch (data.state) {
case StepperState_Init: {
uint32_t frequency;
Clocks_GetFreq(ETPU1_CLK, &frequency);

PINS_DRV_Init(ARRAYSIZE(etpuBPinMux), etpuBPinMux);

if (FS_ETPU_ERROR_NONE == fs_etpu_sm_init(SM_ETPU_CHANNEL(7), FS_ETPU_SM_2PHASE_HALF_STEP,
FS_ETPU_SM_CFG_1_PIN_SEQUENCE, (frequency / 1000), (frequency / 5500), accel_tbl,
ARRAYSIZE(accel_tbl)))
{
fs_etpu_sm_enable(SM_ETPU_CHANNEL(7), FS_ETPU_PRIORITY_LOW);
data.state = StepperState_Idle;
}
break;
}
case StepperState_Idle: {
uint24_t curPos = fs_etpu_sm_get_cp(SM_ETPU_CHANNEL(7));
uint24_t desPos = fs_etpu_sm_get_dp(SM_ETPU_CHANNEL(7));

if (steps) {
fs_etpu_sm_set_dp(SM_ETPU_CHANNEL(7), steps);
data.state = StepperState_Moving;
}
break;
}
case StepperState_Moving: {
uint8_t flags = fs_etpu_sm_get_flags(SM_ETPU_CHANNEL(7));

uint24_t curPos = fs_etpu_sm_get_cp(SM_ETPU_CHANNEL(7));
uint24_t desPos = fs_etpu_sm_get_dp(SM_ETPU_CHANNEL(7));

if ((flags & FS_ETPU_SM_STEPPING) == FS_ETPU_SM_STEPPING_OFF) {
data.state = StepperState_Idle;
}
break;
}
}

#undef SM_ACCEL_TABLE_SIZE
#undef SM_ETPU_CHANNEL(x)
}

 

Best Regards,

Christofer

Tags (3)
0 Kudos
Reply
2 Replies

1,419 Views
petervlna
NXP TechSupport
NXP TechSupport

Hello,

I was talking to only person who was working on the drivers for eTPU and he is not able to help here.

I can only offer you SW support via official NXP web:

https://www.nxp.com/support/support/nxp-engineering-services:SW-SUPPORT

or you can try reaching out your NXP FAE/Sales if you have one for help.

Best regards,

Peter

0 Kudos
Reply

1,410 Views
christofer_ft
Contributor II
Hello Peter,

Thanks for your answer.

I've managed of understand some of it. Just missing the acceleration table. And why it never stops for certain values of desired position.

Best regards,

Christofer
0 Kudos
Reply