1322 lines
25 KiB
C
1322 lines
25 KiB
C
|
|
|
|||
|
|
|
|||
|
|
#define _IN_TMC260_C
|
|||
|
|
#include "tmc260.h"
|
|||
|
|
|
|||
|
|
//-------------------------------------------------------------------------
|
|||
|
|
|
|||
|
|
#if (TMC260_DRV_NUM != 0)
|
|||
|
|
|
|||
|
|
//-------------------------------------------------------------------------
|
|||
|
|
|
|||
|
|
#include "trigger.h"
|
|||
|
|
#include "shell.h"
|
|||
|
|
#include "inout.h"
|
|||
|
|
|
|||
|
|
//-------------------------------------------------------------------------
|
|||
|
|
|
|||
|
|
|
|||
|
|
//------------------------------------------------------------------------
|
|||
|
|
|
|||
|
|
typedef struct
|
|||
|
|
{
|
|||
|
|
TSpiCtrlConfig spiCtrlConfig;
|
|||
|
|
TStepDirConfig stepDirConfig;
|
|||
|
|
TChopperConfig chopperConfig;
|
|||
|
|
TSmartEnergyControl smartEnergyControl;
|
|||
|
|
TStallGuardConfig stallGuardConfig;
|
|||
|
|
TDriverConfig driverConfig;
|
|||
|
|
|
|||
|
|
TReadStatus readStatus;
|
|||
|
|
u32 readData;
|
|||
|
|
}TCConfig;
|
|||
|
|
|
|||
|
|
//------------------------------------------------------------------------
|
|||
|
|
|
|||
|
|
TCConfig g_tcConfig[TMC260_DRV_NUM];
|
|||
|
|
|
|||
|
|
//------------------------------------------------------------------------
|
|||
|
|
|
|||
|
|
#define SReadWrite(cs, dat) SpiReadWrite(cs, dat, 20) // <20><>д20λ<30><CEBB><EFBFBD><EFBFBD>
|
|||
|
|
|
|||
|
|
void SpiCsOff(SpiCs cs)
|
|||
|
|
{
|
|||
|
|
#if (TMC260_DRV_NUM >= 1)
|
|||
|
|
SetDriver1CsOff();
|
|||
|
|
#endif
|
|||
|
|
#if (TMC260_DRV_NUM >= 2)
|
|||
|
|
SetDriver2CsOff();
|
|||
|
|
#endif
|
|||
|
|
#if (TMC260_DRV_NUM >= 3)
|
|||
|
|
SetDriver3CsOff();
|
|||
|
|
#endif
|
|||
|
|
#if (TMC260_DRV_NUM >= 4)
|
|||
|
|
SetDriver4CsOff();
|
|||
|
|
#endif
|
|||
|
|
#if (TMC260_DRV_NUM >= 5)
|
|||
|
|
SetDriver5CsOff();
|
|||
|
|
#endif
|
|||
|
|
#if (TMC260_DRV_NUM >= 6)
|
|||
|
|
SetDriver6CsOff();
|
|||
|
|
#endif
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void SpiCsOn(SpiCs cs)
|
|||
|
|
{
|
|||
|
|
SpiCsOff(cs);
|
|||
|
|
|
|||
|
|
switch(cs)
|
|||
|
|
{
|
|||
|
|
case SC_MOTO1:
|
|||
|
|
#if (TMC260_DRV_NUM >= 1)
|
|||
|
|
SetDriver1CsOn();
|
|||
|
|
#endif
|
|||
|
|
break;
|
|||
|
|
case SC_MOTO2:
|
|||
|
|
#if (TMC260_DRV_NUM >= 2)
|
|||
|
|
SetDriver2CsOn();
|
|||
|
|
#endif
|
|||
|
|
break;
|
|||
|
|
case SC_MOTO3:
|
|||
|
|
#if (TMC260_DRV_NUM >= 3)
|
|||
|
|
SetDriver3CsOn();
|
|||
|
|
#endif
|
|||
|
|
break;
|
|||
|
|
case SC_MOTO4:
|
|||
|
|
#if (TMC260_DRV_NUM >= 4)
|
|||
|
|
SetDriver4CsOn();
|
|||
|
|
#endif
|
|||
|
|
break;
|
|||
|
|
case SC_MOTO5:
|
|||
|
|
#if (TMC260_DRV_NUM >= 5)
|
|||
|
|
SetDriver5CsOn();
|
|||
|
|
#endif
|
|||
|
|
break;
|
|||
|
|
case SC_MOTO6:
|
|||
|
|
#if (TMC260_DRV_NUM >= 6)
|
|||
|
|
SetDriver6CsOn();
|
|||
|
|
#endif
|
|||
|
|
break;
|
|||
|
|
default:
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3> SPI <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӳ<EFBFBD><D3B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֧<EFBFBD><D6A7>64λ
|
|||
|
|
uint64_t SpiReadWrite(SpiCs cs, uint64_t dat, u8 bitlen)
|
|||
|
|
{
|
|||
|
|
int i;
|
|||
|
|
uint64_t rslt;
|
|||
|
|
uint64_t mod;
|
|||
|
|
|
|||
|
|
SClockHigh();
|
|||
|
|
SpiCsOn(cs); // Ƭѡ<C6AC><D1A1>Ч<EFBFBD><D0A7><EFBFBD><EFBFBD>ʼִ<CABC>ж<EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD>
|
|||
|
|
|
|||
|
|
rslt = 0;
|
|||
|
|
mod = 0x01;
|
|||
|
|
mod <<= (bitlen-1);
|
|||
|
|
|
|||
|
|
for(i = 0; i < bitlen; i++)
|
|||
|
|
{
|
|||
|
|
// <20><><EFBFBD>ú<EFBFBD><C3BA><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
if ((dat&mod) != 0)
|
|||
|
|
{
|
|||
|
|
SMdoDataOne();
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
SMdoDataZero();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
SClockLow(); // <20><><EFBFBD><EFBFBD>Ϊ<EFBFBD>͵<EFBFBD>ƽ<EFBFBD><C6BD><EFBFBD>½<EFBFBD><C2BD><EFBFBD>оƬ<C6AC><D7BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
SClockHigh(); // <20><><EFBFBD><EFBFBD>Ϊ<EFBFBD>ߵ<EFBFBD>ƽ<EFBFBD><C6BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>оƬ<D0BE><C6AC>ȡ<EFBFBD><C8A1><EFBFBD>úõ<C3BA><C3B5><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|
|||
|
|
if (SMdiRead() != 0) // <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
|
|||
|
|
{
|
|||
|
|
rslt |= mod;
|
|||
|
|
}
|
|||
|
|
mod >>= 1;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
SpiCsOff(cs);
|
|||
|
|
//printf("SPI cs =0x%x, data =0x%x, rslt = 0x%x \r\n",cs,dat,rslt);
|
|||
|
|
|
|||
|
|
return(rslt);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//------------------------------------------------------------------------
|
|||
|
|
|
|||
|
|
int GetIdxFormCs(SpiCs moto)
|
|||
|
|
{
|
|||
|
|
int idx = moto - 1;
|
|||
|
|
if (idx < 0 || idx >= TMC260_DRV_NUM)
|
|||
|
|
{
|
|||
|
|
printf("not support moto idx\r\n");
|
|||
|
|
return -1;
|
|||
|
|
}
|
|||
|
|
return idx;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//------------------------------------------------------------------------
|
|||
|
|
// ϸ<><CFB8><EFBFBD><EFBFBD><EFBFBD>ó<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD>ӳ<EFBFBD><D3B3><EFBFBD>
|
|||
|
|
void WriteStepDirConfig(SpiCs moto)
|
|||
|
|
{
|
|||
|
|
u32 temp;
|
|||
|
|
int idx;
|
|||
|
|
idx = GetIdxFormCs(moto);
|
|||
|
|
if (idx < 0)
|
|||
|
|
{
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
temp = DRVCTRL0;
|
|||
|
|
|
|||
|
|
if (g_tcConfig[idx].stepDirConfig.intpol != 0)
|
|||
|
|
{
|
|||
|
|
temp |= INTPOL; // ʹ<><CAB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>16<31><36>Ƶ<EFBFBD><C6B5><EFBFBD><EFBFBD>
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (g_tcConfig[idx].stepDirConfig.dEdge != 0)
|
|||
|
|
{
|
|||
|
|
temp |= DEDGE; // ʹ<><CAB9>˫<EFBFBD><CBAB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (g_tcConfig[idx].stepDirConfig.mRes > MRES1)
|
|||
|
|
{
|
|||
|
|
g_tcConfig[idx].stepDirConfig.mRes = MRES1;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
temp |= g_tcConfig[idx].stepDirConfig.mRes;
|
|||
|
|
|
|||
|
|
g_tcConfig[idx].readData = SReadWrite(moto, temp);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//------------------------------------------------------------------------
|
|||
|
|
// SPI <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|
|||
|
|
void WriteSpiCtrlConfig(SpiCs moto)
|
|||
|
|
{
|
|||
|
|
u32 temp;
|
|||
|
|
int idx;
|
|||
|
|
idx = GetIdxFormCs(moto);
|
|||
|
|
if (idx < 0)
|
|||
|
|
{
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
temp = DRVCTRL1;
|
|||
|
|
|
|||
|
|
if (g_tcConfig[idx].spiCtrlConfig.polarityA != 0)
|
|||
|
|
{
|
|||
|
|
temp |= PHA;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (g_tcConfig[idx].spiCtrlConfig.currentA > 255)
|
|||
|
|
{
|
|||
|
|
g_tcConfig[idx].spiCtrlConfig.currentA = 255;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
temp |= ((u32)g_tcConfig[idx].spiCtrlConfig.currentA) << 9;
|
|||
|
|
|
|||
|
|
if (g_tcConfig[idx].spiCtrlConfig.polarityB != 0)
|
|||
|
|
{
|
|||
|
|
temp |= PHB;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (g_tcConfig[idx].spiCtrlConfig.currentB > 255)
|
|||
|
|
{
|
|||
|
|
g_tcConfig[idx].spiCtrlConfig.currentB = 255;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
temp |= ((u32)g_tcConfig[idx].spiCtrlConfig.currentB);
|
|||
|
|
|
|||
|
|
g_tcConfig[idx].readData = SReadWrite(moto, temp);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
//------------------------------------------------------------------------
|
|||
|
|
// ն<><D5B6><EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|
|||
|
|
void WriteChopperConfig(SpiCs moto)
|
|||
|
|
{
|
|||
|
|
u32 temp;
|
|||
|
|
int idx;
|
|||
|
|
idx = GetIdxFormCs(moto);
|
|||
|
|
if (idx < 0)
|
|||
|
|
{
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
temp = CHOPCONF;
|
|||
|
|
|
|||
|
|
if (g_tcConfig[idx].chopperConfig.blankTime > 3)
|
|||
|
|
{
|
|||
|
|
g_tcConfig[idx].chopperConfig.blankTime = 3;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (g_tcConfig[idx].chopperConfig.hysteresisDecay > 3)
|
|||
|
|
{
|
|||
|
|
g_tcConfig[idx].chopperConfig.hysteresisDecay = 3;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (g_tcConfig[idx].chopperConfig.hysteresisEnd > 15)
|
|||
|
|
{
|
|||
|
|
g_tcConfig[idx].chopperConfig.hysteresisEnd = 15;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (g_tcConfig[idx].chopperConfig.hysteresisStart > 7)
|
|||
|
|
{
|
|||
|
|
g_tcConfig[idx].chopperConfig.hysteresisStart = 7;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (g_tcConfig[idx].chopperConfig.tOff > 15)
|
|||
|
|
{
|
|||
|
|
g_tcConfig[idx].chopperConfig.tOff = 15;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
temp |= ((u32)g_tcConfig[idx].chopperConfig.blankTime) << 15;
|
|||
|
|
|
|||
|
|
if (g_tcConfig[idx].chopperConfig.chopperMode != 0)
|
|||
|
|
{
|
|||
|
|
temp |= CHM;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (g_tcConfig[idx].chopperConfig.randomTOff != 0)
|
|||
|
|
{
|
|||
|
|
temp |= RNDTF;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
temp |= ((u32)g_tcConfig[idx].chopperConfig.hysteresisDecay) << 11;
|
|||
|
|
temp |= ((u32)g_tcConfig[idx].chopperConfig.hysteresisEnd) << 7;
|
|||
|
|
temp |= ((u32)g_tcConfig[idx].chopperConfig.hysteresisStart) << 4;
|
|||
|
|
if (g_tcConfig[idx].chopperConfig.enable != 0)
|
|||
|
|
{
|
|||
|
|
temp |= ((u32)g_tcConfig[idx].chopperConfig.tOff);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
g_tcConfig[idx].readData = SReadWrite(moto, temp);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//------------------------------------------------------------------------
|
|||
|
|
// <20><><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƴ<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD>ӳ<EFBFBD><D3B3><EFBFBD>
|
|||
|
|
void WriteStallGuardConfig(SpiCs moto)
|
|||
|
|
{
|
|||
|
|
u32 temp;
|
|||
|
|
int idx;
|
|||
|
|
idx = GetIdxFormCs(moto);
|
|||
|
|
if (idx < 0)
|
|||
|
|
{
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
temp = SGCSCONF;
|
|||
|
|
|
|||
|
|
// 8 λ<>з<EFBFBD><D0B7><EFBFBD><EFBFBD><EFBFBD>תΪ7λ<37>з<EFBFBD><D0B7><EFBFBD><EFBFBD><EFBFBD>, 7λ<37>з<EFBFBD><D0B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>7λ<37>ͷ<EFBFBD><CDB7><EFBFBD>λ<EFBFBD><CEBB><EFBFBD><EFBFBD>(-64--63<36><33>֮<EFBFBD><D6AE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬ<EFBFBD><CDAC>
|
|||
|
|
if (g_tcConfig[idx].stallGuardConfig.stallGuardThreshold > 63)
|
|||
|
|
{
|
|||
|
|
g_tcConfig[idx].stallGuardConfig.stallGuardThreshold = 63;
|
|||
|
|
}
|
|||
|
|
else if (g_tcConfig[idx].stallGuardConfig.stallGuardThreshold < -64)
|
|||
|
|
{
|
|||
|
|
g_tcConfig[idx].stallGuardConfig.stallGuardThreshold = -64;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if(g_tcConfig[idx].stallGuardConfig.filterEnable != 0)
|
|||
|
|
{
|
|||
|
|
temp |= SFILT;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
temp |= (((u32) g_tcConfig[idx].stallGuardConfig.stallGuardThreshold & 0x7f) << 8);
|
|||
|
|
temp |= (g_tcConfig[idx].stallGuardConfig.currentScale & 0x1F);
|
|||
|
|
|
|||
|
|
g_tcConfig[idx].readData = SReadWrite(moto, temp);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//------------------------------------------------------------------------
|
|||
|
|
// <20><><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƴ<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
void WriteSmartEnergyConfig(SpiCs moto)
|
|||
|
|
{
|
|||
|
|
u32 temp;
|
|||
|
|
int idx;
|
|||
|
|
idx = GetIdxFormCs(moto);
|
|||
|
|
if (idx < 0)
|
|||
|
|
{
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
temp = SMARTEN;
|
|||
|
|
|
|||
|
|
if (g_tcConfig[idx].smartEnergyControl.smartIMin != 0)
|
|||
|
|
{
|
|||
|
|
temp |= SEIMIN;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (g_tcConfig[idx].smartEnergyControl.smartDownStep > 3)
|
|||
|
|
{
|
|||
|
|
g_tcConfig[idx].smartEnergyControl.smartDownStep = 3;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (g_tcConfig[idx].smartEnergyControl.smartStallLevelMax > 15)
|
|||
|
|
{
|
|||
|
|
g_tcConfig[idx].smartEnergyControl.smartStallLevelMax = 15;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (g_tcConfig[idx].smartEnergyControl.smartUpStep > 3)
|
|||
|
|
{
|
|||
|
|
g_tcConfig[idx].smartEnergyControl.smartUpStep = 3;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (g_tcConfig[idx].smartEnergyControl.smartStallLevelMin > 15)
|
|||
|
|
{
|
|||
|
|
g_tcConfig[idx].smartEnergyControl.smartStallLevelMin = 15;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
temp |= ((u32)g_tcConfig[idx].smartEnergyControl.smartDownStep) << 13;
|
|||
|
|
temp |= ((u32)g_tcConfig[idx].smartEnergyControl.smartStallLevelMax) << 8;
|
|||
|
|
temp |= ((u32)g_tcConfig[idx].smartEnergyControl.smartUpStep) << 5;
|
|||
|
|
temp |= ((u32)g_tcConfig[idx].smartEnergyControl.smartStallLevelMin);
|
|||
|
|
|
|||
|
|
g_tcConfig[idx].readData = SReadWrite(moto, temp);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
//------------------------------------------------------------------------
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƼĴ<C6BC><C4B4><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|
|||
|
|
void WriteDriverConfig(SpiCs moto)
|
|||
|
|
{
|
|||
|
|
u32 temp;
|
|||
|
|
int idx;
|
|||
|
|
idx = GetIdxFormCs(moto);
|
|||
|
|
if (idx < 0)
|
|||
|
|
{
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
temp = DRVCONF;
|
|||
|
|
|
|||
|
|
if (g_tcConfig[idx].driverConfig.testMode != 0)
|
|||
|
|
{
|
|||
|
|
temp |= TST;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
temp |= ((u32)g_tcConfig[idx].driverConfig.slopeHighSide & 0x03) << 14;
|
|||
|
|
temp |= ((u32)g_tcConfig[idx].driverConfig.slopeLowSide & 0x03) << 12;
|
|||
|
|
|
|||
|
|
if (g_tcConfig[idx].driverConfig.protectionDisable != 0)
|
|||
|
|
{
|
|||
|
|
temp |= DISS2G;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
temp |= ((u32)g_tcConfig[idx].driverConfig.protectionTimer & 0x03) << 8;
|
|||
|
|
|
|||
|
|
if (g_tcConfig[idx].driverConfig.stepDirDisable != 0)
|
|||
|
|
{
|
|||
|
|
temp |= SDOFF;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (g_tcConfig[idx].driverConfig.vSenseScale != 0)
|
|||
|
|
{
|
|||
|
|
temp |= VSENSE;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
temp |= ((u32) g_tcConfig[idx].driverConfig.readBackSelect & 0x03) << 4;
|
|||
|
|
|
|||
|
|
g_tcConfig[idx].readData = SReadWrite(moto, temp);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//------------------------------------------------------------------------
|
|||
|
|
// <20><>ȡ״̬<D7B4><CCAC><EFBFBD><EFBFBD>ֵ
|
|||
|
|
|
|||
|
|
void ReadDriverState(SpiCs moto)
|
|||
|
|
{
|
|||
|
|
int idx;
|
|||
|
|
idx = GetIdxFormCs(moto);
|
|||
|
|
if (idx < 0)
|
|||
|
|
{
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
WriteDriverConfig(moto);
|
|||
|
|
|
|||
|
|
switch(g_tcConfig[idx].driverConfig.readBackSelect) // <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,0:<><CEA2>λ<EFBFBD><CEBB>,1:<3A><><EFBFBD><EFBFBD>ֵ0--9λ, 2:<3A><><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5>5λ(5--9λ)<29><><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5>С
|
|||
|
|
{
|
|||
|
|
case 0: // 0 A<><41><EFBFBD><CEA2>λ<EFBFBD><CEBB>
|
|||
|
|
{
|
|||
|
|
g_tcConfig[idx].readStatus.phases = (g_tcConfig[idx].readData >> 18) & 0x01; // STEP/DIRģʽ<C4A3>µļ<C2B5><C4BC><EFBFBD>λ; 0<><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>OA1<41><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>OA2<41><32><EFBFBD>š<EFBFBD> 1<><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>OA2<41><32><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>OA1<41><31><EFBFBD>š<EFBFBD>
|
|||
|
|
g_tcConfig[idx].readStatus.mSteps = (g_tcConfig[idx].readData >> 10) & 0x1FF; // <20><>ȦA<C8A6><41><EFBFBD><EFBFBD><EFBFBD>ұ<EFBFBD><D2B1>е<EFBFBD><EFBFBD><CEA2>λ<EFBFBD><CEBB>
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
case 1: // 1 <20><><EFBFBD><EFBFBD>ֵ
|
|||
|
|
{
|
|||
|
|
g_tcConfig[idx].readStatus.stallGuard = (g_tcConfig[idx].readData >> 10) & 0x3FF;
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
case 2: // 2<><32><EFBFBD>ظ<EFBFBD>5λ<35><CEBB><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5>С
|
|||
|
|
{
|
|||
|
|
g_tcConfig[idx].readStatus.stallGuard &= 0x1f;
|
|||
|
|
g_tcConfig[idx].readStatus.stallGuard |= (g_tcConfig[idx].readData >> 10) & 0x3E0;
|
|||
|
|
g_tcConfig[idx].readStatus.smartEnergy = (g_tcConfig[idx].readData >> 10) & 0x1f;
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
g_tcConfig[idx].readStatus.flags = g_tcConfig[idx].readData & 0xff; // ͣ<>ٱ<EFBFBD>־λ<D6BE><CEBB><EFBFBD><EFBFBD>, STEP<45><50><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//------------------------------------------------------------------------
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|
|||
|
|
void InitMotorDrivers(SpiCs moto)
|
|||
|
|
{
|
|||
|
|
int idx;
|
|||
|
|
|
|||
|
|
idx = moto-1;
|
|||
|
|
if (idx < 0 || idx >= TMC260_DRV_NUM)
|
|||
|
|
{
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
memset(&(g_tcConfig[idx]), 0, sizeof(TCConfig));
|
|||
|
|
|
|||
|
|
g_tcConfig[idx].stallGuardConfig.filterEnable = 1; // ʧ<><CAA7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˲<EFBFBD> 0:<3A><>ģʽ<C4A3><CABD>1: 4<><34>fullstep<65>˲<EFBFBD>
|
|||
|
|
g_tcConfig[idx].stallGuardConfig.stallGuardThreshold = 2; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>-64~63<36><33>ֵԽ<D6B5><D4BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Խ<EFBFBD>ͣ<EFBFBD><CDA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С<EFBFBD><D0A1>-10
|
|||
|
|
g_tcConfig[idx].stallGuardConfig.currentScale = 1; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0~31
|
|||
|
|
WriteStallGuardConfig(moto); // 0xd020a
|
|||
|
|
|
|||
|
|
g_tcConfig[idx].driverConfig.slopeHighSide = 2; // <20>Ϲ<EFBFBD><CFB9>ʹܿ<CAB9><DCBF><EFBFBD>б<EFBFBD><D0B1>0:<3A><>С3: <20><><EFBFBD><EFBFBD>
|
|||
|
|
g_tcConfig[idx].driverConfig.slopeLowSide = 2; // <20>¹<EFBFBD><C2B9>ʹܿ<CAB9><DCBF><EFBFBD>б<EFBFBD><D0B1>0:<3A><>С3: <20><><EFBFBD><EFBFBD>
|
|||
|
|
g_tcConfig[idx].driverConfig.protectionDisable = 0; // 0:<3A><>·<EFBFBD><C2B7><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9> 1:<3A><>ʹ<EFBFBD><CAB9>
|
|||
|
|
g_tcConfig[idx].driverConfig.protectionTimer = 0; // <20><>·<EFBFBD><C2B7><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>0: 3.2uS, 1: 1.6uS, 2: 1.2uS, 3: 0.8uS
|
|||
|
|
g_tcConfig[idx].driverConfig.stepDirDisable = 0; // 0: <20><><EFBFBD>巽<EFBFBD><E5B7BD>ģʽ<C4A3><CABD>1:SPIģʽ
|
|||
|
|
g_tcConfig[idx].driverConfig.vSenseScale = 0; // <20><><EFBFBD><EFBFBD><EFBFBD>ο<EFBFBD><CEBF><EFBFBD>ѹ<EFBFBD><D1B9>0: 305mV, 1: 165mV
|
|||
|
|
g_tcConfig[idx].driverConfig.readBackSelect = 1; // <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,0:<><CEA2>λ<EFBFBD><CEBB>,1:<3A><><EFBFBD><EFBFBD>ֵ0--9λ, 2:<3A><><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5>5λ(5--9λ)<29><><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5>С
|
|||
|
|
WriteDriverConfig(moto); // 0xea010
|
|||
|
|
|
|||
|
|
g_tcConfig[idx].smartEnergyControl.smartIMin = 1; // <20><><EFBFBD>ܿ<EFBFBD><DCBF><EFBFBD><EFBFBD><EFBFBD>С<EFBFBD><D0A1><EFBFBD><EFBFBD>0: 1/2, 1: 1/4
|
|||
|
|
g_tcConfig[idx].smartEnergyControl.smartDownStep = 0; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٶ<EFBFBD>0: 32, 1: 8, 2: 2, 3: 1
|
|||
|
|
g_tcConfig[idx].smartEnergyControl.smartStallLevelMax = 0; // <20><>λ<EFBFBD><CEBB>ȫ<EFBFBD><C8AB><EFBFBD><EFBFBD>0~15
|
|||
|
|
g_tcConfig[idx].smartEnergyControl.smartUpStep = 0; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٶ<EFBFBD>0: 1, 1: 2, 2: 4, 3: 8
|
|||
|
|
g_tcConfig[idx].smartEnergyControl.smartStallLevelMin = 0; // <20><>λ<EFBFBD><CEBB>ȫ<EFBFBD><C8AB><EFBFBD><EFBFBD>0~15
|
|||
|
|
WriteSmartEnergyConfig(moto); // 0xa8000
|
|||
|
|
|
|||
|
|
g_tcConfig[idx].stepDirConfig.intpol = 0; // 16<31><36>Ƶģʽ
|
|||
|
|
g_tcConfig[idx].stepDirConfig.dEdge = 0; // ˫<><CBAB><EFBFBD><EFBFBD>ģʽ
|
|||
|
|
g_tcConfig[idx].stepDirConfig.mRes = MRES4; // ϸ<><CFB8><EFBFBD><EFBFBD>
|
|||
|
|
WriteStepDirConfig(moto); // 0x0
|
|||
|
|
|
|||
|
|
g_tcConfig[idx].chopperConfig.blankTime = 1; // ն<><D5B6><EFBFBD>հ<EFBFBD>ʱ<EFBFBD>䣬Ҳ<E4A3AC><D2B2><EFBFBD>ǹض<C7B9>ʱ<EFBFBD>䣬0: 16, 1: 24, 2: 36, 3: 54
|
|||
|
|
g_tcConfig[idx].chopperConfig.chopperMode = 0; // 0: ն<><D5B6>ģʽ, 1: <20><>ϵ<EFBFBD><CFB5>ģʽ<C4A3><CABD>һ<EFBFBD><D2BB>ѡ<EFBFBD><D1A1>0
|
|||
|
|
g_tcConfig[idx].chopperConfig.hysteresisDecay = 0; // ˥<><CBA5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0...3, 0:fast decrement 3:very slow decrement
|
|||
|
|
g_tcConfig[idx].chopperConfig.hysteresisEnd = 3; // <20><><EFBFBD><EFBFBD>˥<EFBFBD><CBA5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD> 0...15
|
|||
|
|
g_tcConfig[idx].chopperConfig.hysteresisStart = 3; // <20><><EFBFBD><EFBFBD>˥<EFBFBD><CBA5><EFBFBD><EFBFBD>ʼֵ<CABC><D6B5><EFBFBD><EFBFBD> 0...7
|
|||
|
|
g_tcConfig[idx].chopperConfig.tOff = 5; // ն<><D5B6><EFBFBD><EFBFBD>˥<EFBFBD><CBA5>ʱ<EFBFBD>䣬Ӱ<E4A3AC>쿪<EFBFBD><ECBFAA>Ƶ<EFBFBD><C6B5>
|
|||
|
|
g_tcConfig[idx].chopperConfig.enable = 1; // mosfet<65><74><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
WriteChopperConfig(moto); // 0x881b5
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//------------------------------------------------------------------------------------------------------------------------------------------------
|
|||
|
|
|
|||
|
|
|
|||
|
|
//------------------------------------------------------------------------
|
|||
|
|
// ϸ<CEA2><CFB8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӳ<EFBFBD><D3B3><EFBFBD>
|
|||
|
|
void SetStepDirMStepRes(SpiCs moto, u32 microstepResolution)
|
|||
|
|
{
|
|||
|
|
int idx;
|
|||
|
|
idx = GetIdxFormCs(moto);
|
|||
|
|
if (idx < 0)
|
|||
|
|
{
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
g_tcConfig[idx].stepDirConfig.mRes = microstepResolution;
|
|||
|
|
WriteStepDirConfig(moto);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//
|
|||
|
|
void SetStepDirInterpolation(SpiCs moto, u32 interpolation)
|
|||
|
|
{
|
|||
|
|
int idx;
|
|||
|
|
idx = GetIdxFormCs(moto);
|
|||
|
|
if (idx < 0)
|
|||
|
|
{
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
g_tcConfig[idx].stepDirConfig.intpol = interpolation;
|
|||
|
|
WriteStepDirConfig(moto);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//
|
|||
|
|
void SetStepDirDoubleEdge(SpiCs moto, u32 doubleEdge)
|
|||
|
|
{
|
|||
|
|
int idx;
|
|||
|
|
idx = GetIdxFormCs(moto);
|
|||
|
|
if (idx < 0)
|
|||
|
|
{
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
g_tcConfig[idx].stepDirConfig.dEdge = doubleEdge;
|
|||
|
|
WriteStepDirConfig(moto);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//
|
|||
|
|
u32 GetStepDirMStepRes(SpiCs moto)
|
|||
|
|
{
|
|||
|
|
int idx;
|
|||
|
|
idx = GetIdxFormCs(moto);
|
|||
|
|
if (idx < 0)
|
|||
|
|
{
|
|||
|
|
return 0;
|
|||
|
|
}
|
|||
|
|
return g_tcConfig[idx].stepDirConfig.mRes;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//
|
|||
|
|
u32 GetStepDirInterpolation(SpiCs moto)
|
|||
|
|
{
|
|||
|
|
int idx;
|
|||
|
|
idx = GetIdxFormCs(moto);
|
|||
|
|
if (idx < 0)
|
|||
|
|
{
|
|||
|
|
return 0;
|
|||
|
|
}
|
|||
|
|
return g_tcConfig[idx].stepDirConfig.intpol;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//
|
|||
|
|
u32 GetStepDirDoubleEdge(SpiCs moto)
|
|||
|
|
{
|
|||
|
|
int idx;
|
|||
|
|
idx = GetIdxFormCs(moto);
|
|||
|
|
if (idx < 0)
|
|||
|
|
{
|
|||
|
|
return 0;
|
|||
|
|
}
|
|||
|
|
return g_tcConfig[idx].stepDirConfig.dEdge;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//------------------------------------------------------------------------
|
|||
|
|
//
|
|||
|
|
void SetChopperBlankTime(SpiCs moto, u32 blankTime)
|
|||
|
|
{
|
|||
|
|
int idx;
|
|||
|
|
idx = GetIdxFormCs(moto);
|
|||
|
|
if (idx < 0)
|
|||
|
|
{
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
g_tcConfig[idx].chopperConfig.blankTime = blankTime;
|
|||
|
|
WriteChopperConfig(moto);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//
|
|||
|
|
void SetChopperMode(SpiCs moto, u32 mode)
|
|||
|
|
{
|
|||
|
|
int idx;
|
|||
|
|
idx = GetIdxFormCs(moto);
|
|||
|
|
if (idx < 0)
|
|||
|
|
{
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
g_tcConfig[idx].chopperConfig.chopperMode = mode;
|
|||
|
|
WriteChopperConfig(moto);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//
|
|||
|
|
void SetChopperRandomTOff(SpiCs moto, u32 randomTOff)
|
|||
|
|
{
|
|||
|
|
int idx;
|
|||
|
|
idx = GetIdxFormCs(moto);
|
|||
|
|
if (idx < 0)
|
|||
|
|
{
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
g_tcConfig[idx].chopperConfig.randomTOff = randomTOff;
|
|||
|
|
WriteChopperConfig(moto);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//
|
|||
|
|
void SetChopperHysteresisDecay(SpiCs moto, u32 hysteresisDecay)
|
|||
|
|
{
|
|||
|
|
int idx;
|
|||
|
|
idx = GetIdxFormCs(moto);
|
|||
|
|
if (idx < 0)
|
|||
|
|
{
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
g_tcConfig[idx].chopperConfig.hysteresisDecay = hysteresisDecay;
|
|||
|
|
WriteChopperConfig(moto);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//
|
|||
|
|
void SetChopperHysteresisEnd(SpiCs moto, u32 hysteresisEnd)
|
|||
|
|
{
|
|||
|
|
int idx;
|
|||
|
|
idx = GetIdxFormCs(moto);
|
|||
|
|
if (idx < 0)
|
|||
|
|
{
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
g_tcConfig[idx].chopperConfig.hysteresisEnd = hysteresisEnd;
|
|||
|
|
WriteChopperConfig(moto);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//
|
|||
|
|
void SetChopperHysteresisStart(SpiCs moto, u32 hysteresisStart)
|
|||
|
|
{
|
|||
|
|
int idx;
|
|||
|
|
idx = GetIdxFormCs(moto);
|
|||
|
|
if (idx < 0)
|
|||
|
|
{
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
g_tcConfig[idx].chopperConfig.hysteresisStart = hysteresisStart;
|
|||
|
|
WriteChopperConfig(moto);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//
|
|||
|
|
void SetChopperTOff(SpiCs moto, u32 tOff)
|
|||
|
|
{
|
|||
|
|
int idx;
|
|||
|
|
idx = GetIdxFormCs(moto);
|
|||
|
|
if (idx < 0)
|
|||
|
|
{
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
g_tcConfig[idx].chopperConfig.tOff = tOff;
|
|||
|
|
WriteChopperConfig(moto);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void SetChopperEnable(SpiCs moto, u32 enable)
|
|||
|
|
{
|
|||
|
|
int idx;
|
|||
|
|
idx = GetIdxFormCs(moto);
|
|||
|
|
if (idx < 0)
|
|||
|
|
{
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
g_tcConfig[idx].chopperConfig.enable = enable;
|
|||
|
|
WriteChopperConfig(moto);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//
|
|||
|
|
u32 GetChopperBlankTime(SpiCs moto)
|
|||
|
|
{
|
|||
|
|
int idx;
|
|||
|
|
idx = GetIdxFormCs(moto);
|
|||
|
|
if (idx < 0)
|
|||
|
|
{
|
|||
|
|
return 0;
|
|||
|
|
}
|
|||
|
|
return g_tcConfig[idx].chopperConfig.blankTime;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//
|
|||
|
|
u32 GetChopperMode(SpiCs moto)
|
|||
|
|
{
|
|||
|
|
int idx;
|
|||
|
|
idx = GetIdxFormCs(moto);
|
|||
|
|
if (idx < 0)
|
|||
|
|
{
|
|||
|
|
return 0;
|
|||
|
|
}
|
|||
|
|
return g_tcConfig[idx].chopperConfig.chopperMode;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//
|
|||
|
|
u32 GetChopperRandomTOff(SpiCs moto)
|
|||
|
|
{
|
|||
|
|
int idx;
|
|||
|
|
idx = GetIdxFormCs(moto);
|
|||
|
|
if (idx < 0)
|
|||
|
|
{
|
|||
|
|
return 0;
|
|||
|
|
}
|
|||
|
|
return g_tcConfig[idx].chopperConfig.randomTOff;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//
|
|||
|
|
u32 GetChopperHysteresisDecay(SpiCs moto)
|
|||
|
|
{
|
|||
|
|
int idx;
|
|||
|
|
idx = GetIdxFormCs(moto);
|
|||
|
|
if (idx < 0)
|
|||
|
|
{
|
|||
|
|
return 0;
|
|||
|
|
}
|
|||
|
|
return g_tcConfig[idx].chopperConfig.hysteresisDecay;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//
|
|||
|
|
u32 GetChopperHysteresisEnd(SpiCs moto)
|
|||
|
|
{
|
|||
|
|
int idx;
|
|||
|
|
idx = GetIdxFormCs(moto);
|
|||
|
|
if (idx < 0)
|
|||
|
|
{
|
|||
|
|
return 0;
|
|||
|
|
}
|
|||
|
|
return g_tcConfig[idx].chopperConfig.hysteresisEnd;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//
|
|||
|
|
u32 GetChopperHysteresisStart(SpiCs moto)
|
|||
|
|
{
|
|||
|
|
int idx;
|
|||
|
|
idx = GetIdxFormCs(moto);
|
|||
|
|
if (idx < 0)
|
|||
|
|
{
|
|||
|
|
return 0;
|
|||
|
|
}
|
|||
|
|
return g_tcConfig[idx].chopperConfig.hysteresisStart;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//
|
|||
|
|
u32 GetChopperTOff(SpiCs moto)
|
|||
|
|
{
|
|||
|
|
int idx;
|
|||
|
|
idx = GetIdxFormCs(moto);
|
|||
|
|
if (idx < 0)
|
|||
|
|
{
|
|||
|
|
return 0;
|
|||
|
|
}
|
|||
|
|
return g_tcConfig[idx].chopperConfig.tOff;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
u32 GetChopperEnable(SpiCs moto)
|
|||
|
|
{
|
|||
|
|
int idx;
|
|||
|
|
idx = GetIdxFormCs(moto);
|
|||
|
|
if (idx < 0)
|
|||
|
|
{
|
|||
|
|
return 0;
|
|||
|
|
}
|
|||
|
|
return g_tcConfig[idx].chopperConfig.enable;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//------------------------------------------------------------------------
|
|||
|
|
//
|
|||
|
|
void SetSmartEnergyIMin(SpiCs moto, u32 smartIMin)
|
|||
|
|
{
|
|||
|
|
int idx;
|
|||
|
|
idx = GetIdxFormCs(moto);
|
|||
|
|
if (idx < 0)
|
|||
|
|
{
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
g_tcConfig[idx].smartEnergyControl.smartIMin = smartIMin;
|
|||
|
|
WriteSmartEnergyConfig(moto);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//
|
|||
|
|
void SetSmartEnergyDownStep(SpiCs moto, u32 smartDownStep)
|
|||
|
|
{
|
|||
|
|
int idx;
|
|||
|
|
idx = GetIdxFormCs(moto);
|
|||
|
|
if (idx < 0)
|
|||
|
|
{
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
g_tcConfig[idx].smartEnergyControl.smartDownStep = smartDownStep;
|
|||
|
|
WriteSmartEnergyConfig(moto);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//
|
|||
|
|
void SetSmartEnergyStallLevelMax(SpiCs moto, u32 stallLevelMax)
|
|||
|
|
{
|
|||
|
|
int idx;
|
|||
|
|
idx = GetIdxFormCs(moto);
|
|||
|
|
if (idx < 0)
|
|||
|
|
{
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
g_tcConfig[idx].smartEnergyControl.smartStallLevelMax = stallLevelMax;
|
|||
|
|
WriteSmartEnergyConfig(moto);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//
|
|||
|
|
void SetSmartEnergyUpStep(SpiCs moto, u32 smartUpStep)
|
|||
|
|
{
|
|||
|
|
int idx;
|
|||
|
|
idx = GetIdxFormCs(moto);
|
|||
|
|
if (idx < 0)
|
|||
|
|
{
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
g_tcConfig[idx].smartEnergyControl.smartUpStep = smartUpStep;
|
|||
|
|
WriteSmartEnergyConfig(moto);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//
|
|||
|
|
void SetSmartEnergyStallLevelMin(SpiCs moto, u32 stallLevelMin)
|
|||
|
|
{
|
|||
|
|
int idx;
|
|||
|
|
idx = GetIdxFormCs(moto);
|
|||
|
|
if (idx < 0)
|
|||
|
|
{
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
g_tcConfig[idx].smartEnergyControl.smartStallLevelMin = stallLevelMin;
|
|||
|
|
WriteSmartEnergyConfig(moto);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//
|
|||
|
|
u32 GetSmartEnergyIMin(SpiCs moto)
|
|||
|
|
{
|
|||
|
|
int idx;
|
|||
|
|
idx = GetIdxFormCs(moto);
|
|||
|
|
if (idx < 0)
|
|||
|
|
{
|
|||
|
|
return 0;
|
|||
|
|
}
|
|||
|
|
return g_tcConfig[idx].smartEnergyControl.smartIMin;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//
|
|||
|
|
u32 GetSmartEnergyDownStep(SpiCs moto)
|
|||
|
|
{
|
|||
|
|
int idx;
|
|||
|
|
idx = GetIdxFormCs(moto);
|
|||
|
|
if (idx < 0)
|
|||
|
|
{
|
|||
|
|
return 0;
|
|||
|
|
}
|
|||
|
|
return g_tcConfig[idx].smartEnergyControl.smartDownStep;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//
|
|||
|
|
u32 GetSmartEnergyStallLevelMax(SpiCs moto)
|
|||
|
|
{
|
|||
|
|
int idx;
|
|||
|
|
idx = GetIdxFormCs(moto);
|
|||
|
|
if (idx < 0)
|
|||
|
|
{
|
|||
|
|
return 0;
|
|||
|
|
}
|
|||
|
|
return g_tcConfig[idx].smartEnergyControl.smartStallLevelMax;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//
|
|||
|
|
u32 GetSmartEnergyUpStep(SpiCs moto)
|
|||
|
|
{
|
|||
|
|
int idx;
|
|||
|
|
idx = GetIdxFormCs(moto);
|
|||
|
|
if (idx < 0)
|
|||
|
|
{
|
|||
|
|
return 0;
|
|||
|
|
}
|
|||
|
|
return g_tcConfig[idx].smartEnergyControl.smartUpStep;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//
|
|||
|
|
u32 GetSmartEnergyStallLevelMin(SpiCs moto)
|
|||
|
|
{
|
|||
|
|
int idx;
|
|||
|
|
idx = GetIdxFormCs(moto);
|
|||
|
|
if (idx < 0)
|
|||
|
|
{
|
|||
|
|
return 0;
|
|||
|
|
}
|
|||
|
|
return g_tcConfig[idx].smartEnergyControl.smartStallLevelMin;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//------------------------------------------------------------------------
|
|||
|
|
//
|
|||
|
|
void SetStallGuardFilter(SpiCs moto, u32 enable)
|
|||
|
|
{
|
|||
|
|
int idx;
|
|||
|
|
idx = GetIdxFormCs(moto);
|
|||
|
|
if (idx < 0)
|
|||
|
|
{
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
g_tcConfig[idx].stallGuardConfig.filterEnable = enable;
|
|||
|
|
WriteStallGuardConfig(moto);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//
|
|||
|
|
void SetStallGuardThreshold(SpiCs moto, s32 threshold)
|
|||
|
|
{
|
|||
|
|
int idx;
|
|||
|
|
idx = GetIdxFormCs(moto);
|
|||
|
|
if (idx < 0)
|
|||
|
|
{
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
g_tcConfig[idx].stallGuardConfig.stallGuardThreshold = threshold;
|
|||
|
|
WriteStallGuardConfig(moto);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//
|
|||
|
|
void SetStallGuardCurrentScale(SpiCs moto, u32 currentScale)
|
|||
|
|
{
|
|||
|
|
int idx;
|
|||
|
|
idx = GetIdxFormCs(moto);
|
|||
|
|
if (idx < 0)
|
|||
|
|
{
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
g_tcConfig[idx].stallGuardConfig.currentScale = currentScale;
|
|||
|
|
WriteStallGuardConfig(moto);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//
|
|||
|
|
u32 GetStallGuardFilter(SpiCs moto)
|
|||
|
|
{
|
|||
|
|
int idx;
|
|||
|
|
idx = GetIdxFormCs(moto);
|
|||
|
|
if (idx < 0)
|
|||
|
|
{
|
|||
|
|
return 0;
|
|||
|
|
}
|
|||
|
|
return g_tcConfig[idx].stallGuardConfig.filterEnable;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//
|
|||
|
|
s32 GetStallGuardThreshold(SpiCs moto)
|
|||
|
|
{
|
|||
|
|
int idx;
|
|||
|
|
idx = GetIdxFormCs(moto);
|
|||
|
|
if (idx < 0)
|
|||
|
|
{
|
|||
|
|
return 0;
|
|||
|
|
}
|
|||
|
|
return g_tcConfig[idx].stallGuardConfig.stallGuardThreshold;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//
|
|||
|
|
u32 GetStallGuardCurrentScale(SpiCs moto)
|
|||
|
|
{
|
|||
|
|
int idx;
|
|||
|
|
idx = GetIdxFormCs(moto);
|
|||
|
|
if (idx < 0)
|
|||
|
|
{
|
|||
|
|
return 0;
|
|||
|
|
}
|
|||
|
|
return g_tcConfig[idx].stallGuardConfig.currentScale;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//------------------------------------------------------------------------
|
|||
|
|
//
|
|||
|
|
void SetDriverSlopeHighSide(SpiCs moto, u32 slopeHighSide)
|
|||
|
|
{
|
|||
|
|
int idx;
|
|||
|
|
idx = GetIdxFormCs(moto);
|
|||
|
|
if (idx < 0)
|
|||
|
|
{
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
g_tcConfig[idx].driverConfig.slopeHighSide = slopeHighSide;
|
|||
|
|
WriteDriverConfig(moto);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//
|
|||
|
|
void SetDriverSlopeLowSide(SpiCs moto, u32 slopeLowSide)
|
|||
|
|
{
|
|||
|
|
int idx;
|
|||
|
|
idx = GetIdxFormCs(moto);
|
|||
|
|
if (idx < 0)
|
|||
|
|
{
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
g_tcConfig[idx].driverConfig.slopeHighSide = slopeLowSide;
|
|||
|
|
WriteDriverConfig(moto);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//
|
|||
|
|
void SetDriverDisableProtection(SpiCs moto, u32 disableProtection)
|
|||
|
|
{
|
|||
|
|
int idx;
|
|||
|
|
idx = GetIdxFormCs(moto);
|
|||
|
|
if (idx < 0)
|
|||
|
|
{
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
g_tcConfig[idx].driverConfig.protectionDisable = disableProtection;
|
|||
|
|
WriteDriverConfig(moto);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//
|
|||
|
|
void SetDriverProtectionTimer(SpiCs moto, u32 protectionTimer)
|
|||
|
|
{
|
|||
|
|
int idx;
|
|||
|
|
idx = GetIdxFormCs(moto);
|
|||
|
|
if (idx < 0)
|
|||
|
|
{
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
g_tcConfig[idx].driverConfig.protectionTimer = protectionTimer;
|
|||
|
|
WriteDriverConfig(moto);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//
|
|||
|
|
void SetDriverStepDirectionOff(SpiCs moto, u32 sDOff)
|
|||
|
|
{
|
|||
|
|
int idx;
|
|||
|
|
idx = GetIdxFormCs(moto);
|
|||
|
|
if (idx < 0)
|
|||
|
|
{
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
g_tcConfig[idx].driverConfig.stepDirDisable = sDOff;
|
|||
|
|
WriteDriverConfig(moto);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//
|
|||
|
|
void SetDriverVSenseScale(SpiCs moto, u32 scale)
|
|||
|
|
{
|
|||
|
|
int idx;
|
|||
|
|
idx = GetIdxFormCs(moto);
|
|||
|
|
if (idx < 0)
|
|||
|
|
{
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
g_tcConfig[idx].driverConfig.vSenseScale = scale;
|
|||
|
|
WriteDriverConfig(moto);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//
|
|||
|
|
void SetDriverReadSelect(SpiCs moto, u32 readSelect)
|
|||
|
|
{
|
|||
|
|
int idx;
|
|||
|
|
idx = GetIdxFormCs(moto);
|
|||
|
|
if (idx < 0)
|
|||
|
|
{
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
g_tcConfig[idx].driverConfig.readBackSelect = readSelect;
|
|||
|
|
WriteDriverConfig(moto);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//
|
|||
|
|
void SetDriverTestMode(SpiCs moto, u32 testMode)
|
|||
|
|
{
|
|||
|
|
int idx;
|
|||
|
|
idx = GetIdxFormCs(moto);
|
|||
|
|
if (idx < 0)
|
|||
|
|
{
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
g_tcConfig[idx].driverConfig.testMode = testMode;
|
|||
|
|
WriteDriverConfig(moto);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//
|
|||
|
|
u32 GetDriverSlopeHighSide(SpiCs moto)
|
|||
|
|
{
|
|||
|
|
int idx;
|
|||
|
|
idx = GetIdxFormCs(moto);
|
|||
|
|
if (idx < 0)
|
|||
|
|
{
|
|||
|
|
return 0;
|
|||
|
|
}
|
|||
|
|
return g_tcConfig[idx].driverConfig.slopeHighSide;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//
|
|||
|
|
u32 GetDriverSlopeLowSide(SpiCs moto)
|
|||
|
|
{
|
|||
|
|
int idx;
|
|||
|
|
idx = GetIdxFormCs(moto);
|
|||
|
|
if (idx < 0)
|
|||
|
|
{
|
|||
|
|
return 0;
|
|||
|
|
}
|
|||
|
|
return g_tcConfig[idx].driverConfig.slopeLowSide;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//
|
|||
|
|
u32 GetDriverDisableProtection(SpiCs moto)
|
|||
|
|
{
|
|||
|
|
int idx;
|
|||
|
|
idx = GetIdxFormCs(moto);
|
|||
|
|
if (idx < 0)
|
|||
|
|
{
|
|||
|
|
return 0;
|
|||
|
|
}
|
|||
|
|
return g_tcConfig[idx].driverConfig.protectionDisable;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//
|
|||
|
|
u32 GetDriverProtectionTimer(SpiCs moto)
|
|||
|
|
{
|
|||
|
|
int idx;
|
|||
|
|
idx = GetIdxFormCs(moto);
|
|||
|
|
if (idx < 0)
|
|||
|
|
{
|
|||
|
|
return 0;
|
|||
|
|
}
|
|||
|
|
return g_tcConfig[idx].driverConfig.protectionTimer;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//
|
|||
|
|
u32 GetDriverStepDirectionOff(SpiCs moto)
|
|||
|
|
{
|
|||
|
|
int idx;
|
|||
|
|
idx = GetIdxFormCs(moto);
|
|||
|
|
if (idx < 0)
|
|||
|
|
{
|
|||
|
|
return 0;
|
|||
|
|
}
|
|||
|
|
return g_tcConfig[idx].driverConfig.stepDirDisable;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//
|
|||
|
|
u32 GetDriverVSenseScale(SpiCs moto)
|
|||
|
|
{
|
|||
|
|
int idx;
|
|||
|
|
idx = GetIdxFormCs(moto);
|
|||
|
|
if (idx < 0)
|
|||
|
|
{
|
|||
|
|
return 0;
|
|||
|
|
}
|
|||
|
|
return g_tcConfig[idx].driverConfig.vSenseScale;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//
|
|||
|
|
u32 GetDriverReadSelect(SpiCs moto)
|
|||
|
|
{
|
|||
|
|
int idx;
|
|||
|
|
idx = moto-1;
|
|||
|
|
idx = GetIdxFormCs(moto);
|
|||
|
|
if (idx < 0)
|
|||
|
|
{
|
|||
|
|
return 0;
|
|||
|
|
}
|
|||
|
|
return g_tcConfig[idx].driverConfig.readBackSelect;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//
|
|||
|
|
u32 GetDriverTestMode(SpiCs moto)
|
|||
|
|
{
|
|||
|
|
int idx;
|
|||
|
|
idx = GetIdxFormCs(moto);
|
|||
|
|
if (idx < 0)
|
|||
|
|
{
|
|||
|
|
return 0;
|
|||
|
|
}
|
|||
|
|
return g_tcConfig[idx].driverConfig.testMode;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//------------------------------------------------------------------------
|
|||
|
|
|
|||
|
|
u32 GetPhases(SpiCs moto)
|
|||
|
|
{
|
|||
|
|
int idx;
|
|||
|
|
idx = GetIdxFormCs(moto);
|
|||
|
|
if (idx < 0)
|
|||
|
|
{
|
|||
|
|
return 0;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return g_tcConfig[idx].readStatus.phases;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//------------------------------------------------------------------------
|
|||
|
|
u32 GetMStepPos(SpiCs moto)
|
|||
|
|
{
|
|||
|
|
int idx;
|
|||
|
|
idx = GetIdxFormCs(moto);
|
|||
|
|
if (idx < 0)
|
|||
|
|
{
|
|||
|
|
return 0;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return g_tcConfig[idx].readStatus.mSteps;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//------------------------------------------------------------------------
|
|||
|
|
u32 GetStallGuard(SpiCs moto)
|
|||
|
|
{
|
|||
|
|
int idx;
|
|||
|
|
idx = GetIdxFormCs(moto);
|
|||
|
|
if (idx < 0)
|
|||
|
|
{
|
|||
|
|
return 0;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return g_tcConfig[idx].readStatus.stallGuard;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//------------------------------------------------------------------------
|
|||
|
|
u32 GetSmartEnergy(SpiCs moto)
|
|||
|
|
{
|
|||
|
|
int idx;
|
|||
|
|
idx = GetIdxFormCs(moto);
|
|||
|
|
if (idx < 0)
|
|||
|
|
{
|
|||
|
|
return 0;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return g_tcConfig[idx].readStatus.smartEnergy;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//------------------------------------------------------------------------
|
|||
|
|
//
|
|||
|
|
u32 GetDriverFlag(SpiCs moto)
|
|||
|
|
{
|
|||
|
|
int idx;
|
|||
|
|
idx = GetIdxFormCs(moto);
|
|||
|
|
if (idx < 0)
|
|||
|
|
{
|
|||
|
|
return 0;
|
|||
|
|
}
|
|||
|
|
return g_tcConfig[idx].readStatus.flags;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//
|
|||
|
|
void DriveDisable(SpiCs moto)
|
|||
|
|
{
|
|||
|
|
SetChopperEnable(moto, 0);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//
|
|||
|
|
void DriveEnable(SpiCs moto)
|
|||
|
|
{
|
|||
|
|
SetChopperEnable(moto, 1);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//----------------------------------------------------------------------------------------------------------------------------------------------
|
|||
|
|
|
|||
|
|
|
|||
|
|
//------------------------------------------------------------------------
|
|||
|
|
|
|||
|
|
//------------------------------------------------------------------------
|
|||
|
|
|
|||
|
|
|
|||
|
|
void InitTmc260(void)
|
|||
|
|
{
|
|||
|
|
InitMotorDrivers(SC_MOTO1);
|
|||
|
|
InitMotorDrivers(SC_MOTO2);
|
|||
|
|
InitMotorDrivers(SC_MOTO3);
|
|||
|
|
InitMotorDrivers(SC_MOTO4);
|
|||
|
|
InitMotorDrivers(SC_MOTO5);
|
|||
|
|
InitMotorDrivers(SC_MOTO6);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//------------------------------------------------------------------------
|
|||
|
|
|
|||
|
|
int GetResConfigFromLvnum(int subd)
|
|||
|
|
{
|
|||
|
|
switch(subd)
|
|||
|
|
{
|
|||
|
|
case 1: // 1ϸ<31><CFB8>
|
|||
|
|
return MRES1;
|
|||
|
|
case 2: // 2ϸ<32><CFB8>
|
|||
|
|
return MRES2;
|
|||
|
|
case 4: // 4ϸ<34><CFB8>
|
|||
|
|
return MRES4;
|
|||
|
|
case 8: // 8ϸ<38><CFB8>
|
|||
|
|
return MRES8;
|
|||
|
|
case 16: // 16ϸ<36><CFB8>
|
|||
|
|
return MRES16;
|
|||
|
|
case 32: // 32ϸ<32><CFB8>
|
|||
|
|
return MRES32;
|
|||
|
|
case 64: // 64ϸ<34><CFB8>
|
|||
|
|
return MRES64;
|
|||
|
|
case 128: // 128ϸ<38><CFB8>
|
|||
|
|
return MRES128;
|
|||
|
|
case 256: // 256ϸ<36><CFB8>
|
|||
|
|
return MRES256;
|
|||
|
|
default:
|
|||
|
|
return MRES256;
|
|||
|
|
};
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
#endif
|
|||
|
|
|
|||
|
|
|