📄 gdic.c
字号:
/*****************************************************
gdic.c - Initializes the GDIC
----------------------------------------------------
*****************************************************/
#include "hidef.h" /* this file declares symbols user by the CodeWarrior environment */
#include "XDP512Regs.h"
#include "Globals.h"
#include "GDIC.h"
/*************************************************************************************/
#pragma MESSAGE DISABLE C5703 /* diable warning on not using the parameter of the function */
static void uSDelay(uint Delay)
{
/* Variable Declarations */
/* Begin Function uSDelay() */
#asm
uSLoop: ldx #12
XLoop: dbne x,XLoop
nop
dbne d,uSLoop
#endasm
//#endif
} /* end uSDelay */
/************************************************************************************/
void Delay_mSec(uint msec)
{
/* Variable Declarations */
uint loop;
/* Begin Function Delay_mSec() */
for (loop = 0; loop<msec; loop++)
uSDelay(1000); /* delay 1ms */
} /* end Delay_mSec */
/************************************************************************************/
static void GDICReset(uchar resettime)
{
/* Variable Declarations */
/* Begin Function GDICReset() */
RegBase->PORTT &= ~GDICLRst; /* assert the left GDIC reset line */
uSDelay(resettime);
RegBase->PORTT |= GDICLRst; /* negate the left GDIC reset line */
RegBase->PORTT &= ~GDICRRst; /* assert the right GDIC reset line */
uSDelay(resettime);
RegBase->PORTT |= GDICRRst; /* negate the right GDIC reset line */
} /* end GDICReset */
/************************************************************************************/
static uint SendGDICCmd(uint CmdWord, uchar GDIC)
{
/* Variable Declarations */
uint Status; /* data returned from the GDIC */
/* Begin Function SendGDICCmd() */
uSDelay(5); /* ensure we meet communication timing requirements */
if (GDIC == GDICLeft) /* command being sent to the left GDIC gages? */
RegBase->PORTT &= ~GDICLCS; /* yes. assert the left GDIC chip select */
else
RegBase->PORTT &= ~GDICRCS; /* no. assert the right GDIC chip select */
RegBase->SPI0.SR;
RegBase->SPI0.DR = CmdWord >> 8; /* send the first byte of the command */
while ((RegBase->SPI0.SR & SPIF) == 0)
;
Status = RegBase->SPI0.DR << 8;
RegBase->SPI0.DR = CmdWord & 0x00ff;
while ((RegBase->SPI0.SR & SPIF) == 0)
;
Status += RegBase->SPI0.DR;
if (GDIC == GDICLeft) /* command sent to the left GDIC gages? */
RegBase->PORTT |= GDICLCS; /* yes. negate the left GDIC chip select */
else
RegBase->PORTT |= GDICRCS; /* no. negate the right GDIC chip select */
return(Status);
} /* end SendGDICCmd */
/************************************************************************************/
static void GDICCalibrate(uint CalPulseWidth)
{
/* Variable Declarations */
/* Begin Function GDICCalibrate() */
(void)SendGDICCmd(PECCRConfgVal + EnClkCal, GDICLeft); /* enable clock calibration in left GDIC */
(void)SendGDICCmd(PECCRConfgVal + EnClkCal, GDICRight); /* enable clock calibration in right GDIC */
RegBase->PORTT &= ~GDICLCS; /* assert the left GDIC chip select */
uSDelay(CalPulseWidth);
RegBase->PORTT |= GDICLCS; /* negate the left GDIC chip select */
RegBase->PORTT &= ~GDICRCS; /* assert the right GDIC chip select */
uSDelay(CalPulseWidth);
RegBase->PORTT |= GDICRCS; /* negate the right GDIC chip select */
(void)SendGDICCmd(PECCRConfgVal, GDICLeft); /* disable clock calibration in left GDIC */
(void)SendGDICCmd(PECCRConfgVal, GDICRight); /* disable clock calibration in right GDIC */
} /* end GDICCalibrate */
/************************************************************************************/
static void DoRTZ(uchar WhichGage, uint Multiplier, uint PreloadValue, uint BlankingTime, uint StepTime)
{
/* Variable Declarations */
uchar WhichGDIC; /* holds the value GDICLeft or GDICRight, derrived from WhichGage */
uint RTZCmdWord; /* holds the RTZ command word */
uint RtnStat; /* holds the device status returned by SendGDICCmd() */
/* Begin Function DoRTZ() */
WhichGDIC = WhichGage >> 1; /* GDIC is contained in bit 1 */
WhichGage &= 0x01; /* gage number contained in bit 0 */
RTZCmdWord = RTZCmd + RTZEnable + WhichGage; /* build the RTZ command word */
Multiplier = Multiplier << 11; /* shift Multiplier bits into the proper location */
PreloadValue = PreloadValue << 5; /* shift PreloadValue bits into the proper location */
BlankingTime = BlankingTime << 4; /* shift BlankingTime bits into the proper location */
(void)SendGDICCmd(RTZCnfgCmd + Multiplier + PreloadValue + BlankingTime + StepTime, WhichGDIC); /* initialize the RTZ Configuration Register */
(void)SendGDICCmd(RTZCmdWord, WhichGDIC); /* return the selected gage to it's 0 position */
do {
RtnStat = SendGDICCmd(StatusCmd, WhichGDIC);
} while ((RtnStat & (RTZ0 + RTZ1)) != 0); /* wait for the gage on the GDIC to get to its '0' position */
} /* end DoRTZ */
/************************************************************************************/
static void ZeroPointers(void)
{
/* Variable Declarations */
uint RtnStat;
uchar x;
/* Begin Function ZeroPointers() */
(void)SendGDICCmd(MaxVelCmd + VelG0 + VelG1 + VelMax, GDICLeft);
(void)SendGDICCmd(MaxVelCmd + VelG0 + VelG1 + VelMax, GDICRight);
(void)SendGDICCmd(Gage0PosCmd + FastResponse + FullSweep, GDICLeft); /* do a full sweep of the gage */
(void)SendGDICCmd(Gage1PosCmd + FastResponse + FullSweep, GDICLeft);
(void)SendGDICCmd(Gage0PosCmd + FastResponse + FullSweep, GDICRight);
(void)SendGDICCmd(Gage1PosCmd + FastResponse + FullSweep, GDICRight);
do {
RtnStat = SendGDICCmd(StatusCmd, GDICLeft);
} while ((RtnStat & (CMD0 + CMD1)) != 0); /* wait for both gages on the left GDIC to get to their '0 position */
do {
RtnStat = SendGDICCmd(StatusCmd, GDICRight);
} while ((RtnStat & (CMD0 + CMD1)) != 0); /* wait for both gages on the right GDIC to get to their '0 position */
(void)SendGDICCmd(PECCRConfgVal + Pos0CCW + EnClkCal, GDICLeft); /* apply settings to left gage 0 */
(void)SendGDICCmd(PECCRConfgVal + Pos1CCW + EnClkCal, GDICLeft); /* apply settings to left gage 1 */
(void)SendGDICCmd(PECCRConfgVal + Pos0CCW + EnClkCal, GDICRight); /* apply settings to right gage 0 */
(void)SendGDICCmd(PECCRConfgVal + Pos1CCW + EnClkCal, GDICRight); /* apply settings to right gage 1 */
for (x = LSmallGage; x <= RSmallGage; x++) /* perform a true RTZ on each of the gages */
DoRTZ(x, 2, 6, 1, 1);
} /* end ZeroPointers */
/************************************************************************************/
void GDICInit(void)
{
/* Variable Declarations */
/* Begin Function GDICInit() */
GDICReset(100); /* reset both the GDICs with a 100 us pulse */
(void)SendGDICCmd(PECCRConfgVal + Pos0CW + EnClkCal, GDICLeft); /* apply settings to left gage 0 */
(void)SendGDICCmd(PECCRConfgVal + Pos1CW + EnClkCal, GDICLeft); /* apply settings to left gage 1 */
(void)SendGDICCmd(PECCRConfgVal + Pos0CW + EnClkCal, GDICRight); /* apply settings to right gage 0 */
(void)SendGDICCmd(PECCRConfgVal + Pos1CW + EnClkCal, GDICRight); /* apply settings to right gage 1 */
GDICCalibrate(8);
(void)SendGDICCmd(PECCRConfgVal + Pos0CW, GDICLeft); /* disable clock calibration */
(void)SendGDICCmd(PECCRConfgVal + Pos0CW, GDICRight); /* disable clock calibration */
ZeroPointers(); /* set the pointers fully CCW */
GDICData.GDICCmdState = LSmallGage;
GDICData.CmdByteIndex = 0;
} /* end GDICInit */
/************************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -