analogdevicesinc / TMC-API

TRINAMIC's IC API
MIT License
188 stars 83 forks source link

How to perform full steps or half steps with the TMC5130-EVAL board ? #22

Closed marlesus closed 2 years ago

marlesus commented 2 years ago

Hello,

I am struggling to configure the standard TMC5130-EVAL board to run a stepper motor with full steps or half-steps, but so far I could not do that. Is it somehow "nailed" that the standard EVAL board (together with the standard Landungsbrücke) works with 256 microstepping only? Do I need to modify something on the board, in order to be able to configure the MRES register to a smaller microstepping number? Some help/code example would be highly appreciated! I cannot create an account on the trinamic official blog (the Registration option does not seem available, unfortunately).

Best regards, Paul

Lionheart1810 commented 2 years ago

The EvalBoard works with every microstep resolution. It is configurable by setting the mresX bits in the CHOPCONF register (0x6C). By default, (mres3, mres2, mres1, mres0) is set to (0, 0, 0, 0) within the chip, resulting in a microstep resolution of 256 microsteps / fullstep. Additionally, CHOPCONF (0x6C) is set to a predefined value during API configuration routine, which is also setting the microstep resolution to 256. After configuration is complete, you can set the predefined registers as you want. The state can be checked by either polling tmc5130->config->state (tmc5130 being the TMC5130 API instance, only after calling tmc5130_init(...), or by setting a callback function with tmc5130_setCallback(...), which will be called on configuration completion.

Approach 1:

void TMC5130_init(void)
{
  // ...
  tmc5130_init(&TMC5130, 0, &config, &tmc5130_defaultRegisterResetState[0]);
}

static void periodicJob(uint32_t tick)
{
  tmc5130_periodicJob(&TMC5130, tick);
  if(TMC5130.config->state == CONFIG_READY)
    TMC5130_FIELD_WRITE(&TMC5130, TMC5130_CHOPCONF, TMC5130_MRES_MASK, TMC5130_MRES_SHIFT, 0b1010); // Replace 0b1010 with your value
}

Approach 2 is already implemented in the TMC-EvalSystem project (configCallback(...) in TMC5130_eval.c).