TMC249A DATASHEET (Rev. 2.20 / 2019-AUG-21) 27
www.trinamic.com
10 Microstep Resolution
After choosing the desired microstep resolution the microcontroller sends digital values for each
microstep current via SPI. The following example shows how to initialize microsteps via SPI.
SINE WAVE TABLE
- The sine wave table below is used for 4-bit microstepping.
- The absolute values are left-shifted by one bit.
- Bit 0 is the sign bit (phase direction bit).
- Bit 5 is the mixed decay bit. It is set when the absolute value is falling.
FUNCTION
The function in the example below generates the microsteps. The values are read from the sine wave
table and output to the TMC249 (via SPI interface.) Call this function with the ccw parameter set to 1
(to step in negative direction) or with ccw set to 0 (to step in positive direction). The function can be
called in a timer interrupt, too.
SENDING VALUES VIA SPI
Set the CS line of the TMC249 low and send out the value of io by SPI (MSB first). Thereafter, set the
CS line high again.
EXAMPLE FOR GENERATING MICROSTEPS USING THE TMC249
UCHAR sinus_tab[64]={0x00, 0x02, 0x06, 0x08, 0x0c, 0x0e, 0x10, 0x14,
0x16, 0x18, 0x18, 0x1a, 0x1c, 0x1c, 0x1e, 0x1e,
0x3e, 0x3e, 0x3e, 0x3c, 0x3c, 0x3a, 0x38, 0x38,
0x36, 0x34, 0x30, 0x2e, 0x2c, 0x28, 0x26, 0x22,
0x01, 0x03, 0x07, 0x09, 0x0d, 0x0f, 0x11, 0x15,
0x17, 0x19, 0x19, 0x1b, 0x1d, 0x1d, 0x1f, 0x1f,
0x3f, 0x3f, 0x3f, 0x3d, 0x3d, 0x3b, 0x39, 0x39,
0x37, 0x35, 0x31, 0x2f, 0x2d, 0x29, 0x27, 0x23};
volatile UCHAR PhaseCount=0;
void step(char ccw)
{
UINT MixedDecayXOR=0, io;
if(!ccw)
{
PhaseCount++;
}
else
{ //The "Mixed Decay" bits must be reversed when running in CCW
direction
PhaseCount--;
MixedDecayXOR=0x820;
}
io=((sinus_tab[PhaseCount & 63]<<6 | sinus_tab[(PhaseCount+16) &
63]) ^ MixedDecayXOR);
}