/*
*********************************************************************************************************
* 78K0/Dx2 Reference Design
*
* (c) Copyright 2010.01, NEC Electronics China Automotive Business Unit
* All Rights Reserved
*
* File : zpd.c
* By : Zhao Kun
* Version : V1.0
* Announcement:
* This program should be used on your own responsibility.
* NEC Electronics Corporation assumes no responsibility for any losses
* incurred by customers or third parties arising from the use of this file.
*********************************************************************************************************
*/
/**********include files********************************************************************************/
#include "common.h"
#include "motor_variable.h"
#include "led.h"
#include "Dx2Ref_cfg.h"
/**********registers definition for stepper motor control ***********************************************/
#define MCNTC0 *(uchar *)(0xF9C0)
#if MOTOR1
#define MCMP10 *(uchar *)(0xF9C2)
#define MCMP11 *(uchar *)(0xF9C3)
#define MCMP1HW *(uint *)(0xF9C2)
#define MCMPC1 *(uchar *)(0xF9CA)
#endif
#if MOTOR2
#define MCMP20 *(uchar *)(0xF9C4)
#define MCMP21 *(uchar *)(0xF9C5)
#define MCMP2HW *(uint *)(0xF9C4)
#define MCMPC2 *(uchar *)(0xF9CC)
#endif
#if MOTOR3
#define MCMP30 *(uchar *)(0xF9C6)
#define MCMP31 *(uchar *)(0xF9C7)
#define MCMP3HW *(uint *)(0xF9C6)
#define MCMPC3 *(uchar *)(0xF9CE)
#endif
#if MOTOR4
#define MCMP40 *(uchar *)(0xF9C8)
#define MCMP41 *(uchar *)(0xF9C9)
#define MCMP4HW *(uint *)(0xF9C8)
#define MCMPC4 *(uchar *)(0xF9F8)
#endif
#if ZPDFUNCTION
#define ZPDS0 *(uchar *)(0xF9FC)
#define ZPDS1 *(uchar *)(0xF9FD)
#define CMPCTL *(uchar *)(0xF9FE)
#define ZPDEN *(uchar *)(0xF9FF)
#endif
/**********variables definition**************************************************************************/
extern const uchar MicroStepTbl[3][24];
#if ZPDFUNCTION
#define TAC_TIMESLICE1 2
#define TAC_TIMESLICE2 1
#define TAC_TIMESLICE3 5
#define SPD_TIMESLICE1 3
#define SPD_TIMESLICE2 2
#define SPD_TIMESLICE3 3
#define OIL_TIMESLICE1 3
#define OIL_TIMESLICE2 2
#define OIL_TIMESLICE3 3
#define TMP_TIMESLICE1 6
#define TMP_TIMESLICE2 1
#define TMP_TIMESLICE3 1
bit SPD_ZPDFlag;
bit TAC_ZPDFlag;
bit TMP_ZPDFlag;
bit OIL_ZPDFlag;
#if 1
const uchar ZPD_Tab[3][4] = {
{ 200, 0, 200, 0},
{ 0, 200, 0, 200},
{0x11, 0x10, 0x53, 0x12},
};
#else
const uchar ZPD_Tab[3][4] = {
{ 255, 0, 255, 0},
{ 97, 217, 97, 217},
{0x11, 0x10, 0x53, 0x12},
};
#endif
/*******************************************************************************************************
## Module: zpd.c
## Function: SPD_ZPD_loop()
## Description: this function is to realize the ZPD function of 1st meter
## Parameter: None
## Return£º void
*******************************************************************************************************/
#if MOTOR1
__callt void TAC_ZPD_loop()
{
uchar mpmpc,i;
if(TAC_TablePtr == 0x03)
{
mpmpc = MCMPC1 & 0x20;
if(mpmpc != 0)
{
NOP();
ZPDEN = 0x00;
MCMPC1 &= 0xBF;
NOP();
NOP();
MCMPC1 |= 0x40;
NOP();
NOP();
NOP();
mpmpc = MCMPC1 & 0x20;
}
else
{
TAC_ZPDFlag = 0;
}
}
for( i = 0; i<TAC_TIMESLICE3; i++ )
{
while(!TP4CC0IF);
TP4CC0IF = 0;
}
mpmpc = MCMPC1 & 0x10; /* Transfer ENable n(Motor conveyer control) */
if(mpmpc == 0)
{
if(TAC_TablePtr == 0x02)
{
PM8.3 = 1;
}
else
{
PM8.3 = 0;
}
MCMP10 = ZPD_Tab[0][TAC_TablePtr]; /*Sin */
MCMP11 = ZPD_Tab[1][TAC_TablePtr]; /*Cos */
MCMPC1 = ZPD_Tab[2][TAC_TablePtr];
for( i = 0; i<TAC_TIMESLICE1; i++ ) // 2 msec wait
{
while(!TP4CC0IF);
TP4CC0IF = 0;
}
if(TAC_TablePtr == 0x02)
{
PM8.3 = 1;
ZPDS0 |= 0x0b; //ZPD flag detection voltage setting register
ZPDEN |= 0x01; //ZPD comparator enable
}
else
{
PM8.3 = 0;
ZPDS0 = 0x00;
ZPDEN = 0x00;
}
TAC_TablePtr ++;
TAC_TablePtr = TAC_TablePtr % 4;
}
}
#endif
/*******************************************************************************************************
## Module: zpd.c
## Function: TAC_ZPD_loop()
## Description: this function is to realize the ZPD function of 2nd meter
## Parameter: None
## Return£º void
*******************************************************************************************************/
#if MOTOR3
__callt void SPD_ZPD_loop()
{
uchar mpmpc,i;
if(SPD_TablePtr == 0x03)
{
mpmpc = MCMPC3 & 0x20;
if(mpmpc != 0)
{
NOP();
ZPDEN = 0x00;
MCMPC3 &= 0xBF;
NOP();
NOP();
MCMPC3 |= 0x40;
NOP();
NOP();
NOP();
mpmpc = MCMPC3 & 0x20;
}
else
{
SPD_ZPDFlag = 0;
}
}
for( i = 0; i<SPD_TIMESLICE3; i++ )
{
while(!TP4CC0IF);
TP4CC0IF = 0;
}
mpmpc = MCMPC3 & 0x10; /* Transfer ENable n(Motor conveyer control) */
if(mpmpc == 0)
{
if(SPD_TablePtr == 0x02)
{
PM9.3 = 1;
}
else
{
PM9.3 = 0;
}
MCMP30 = ZPD_Tab[0][SPD_TablePtr]; /*Sin */
MCMP31 = ZPD_Tab[1][SPD_TablePtr]; /*Cos */
MCMPC3 = ZPD_Tab[2][SPD_TablePtr];
for( i = 0; i<SPD_TIMESLICE1; i++ ) // 2 msec wait
{
while(!TP4CC0IF);
TP4CC0IF = 0;
}
if(SPD_TablePtr == 0x02)
{
PM9.3 = 1;
ZPDS1 |= 0x0c; //ZPD flag detection voltage setting register
ZPDEN |= 0x04; //ZPD comparator enable
}
else
{
PM9.3 = 0;
ZPDS1 = 0x00;
ZPDEN = 0x00;
}
SPD_TablePtr ++;
SPD_TablePtr = SPD_TablePtr % 4;
}
}
#endif
/*******************************************************************************************************
## Module: zpd.c
## Function: OIL_ZPD_loop()
## Description: this function is to realize the ZPD function of 3rd meter
## Parameter: None
## Return£º void
*******************************************************************************************************/
#if MOTOR2
__callt void OIL_ZPD_loop()
{
uchar mpmpc,i;
if(OIL_TablePtr == 0x01)
{
mpmpc = MCMPC3 & 0x20;
if(mpmpc != 0)
{
NOP();
ZPDEN = 0x00;
MCMPC3 &= 0xBF;
NOP();
NOP();
MCMPC3 |= 0x40;
NOP();
NOP();
NOP();
mpmpc = MCMPC3 & 0x20;
}
else
{
OIL_ZPDFlag = 0;
}
}
for( i = 0; i<OIL_TIMESLICE3; i++ )
{
while(!TP4CC0IF);
TP4CC0IF = 0;
}
mpmpc = MCMPC3 & 0x10; /* Transfer ENable n(Motor conveyer control) */
if(mpmpc == 0)
{
if(OIL_TablePtr == 0x02)
{
PM9.3 = 1;
}
else
{
PM9.3 = 0;
}
MCMP30 = ZPD_Tab[0][OIL_TablePtr]; /*Sin */
MCMP31 = ZPD_Tab[1][OIL_TablePtr]; /*Cos */
MCMPC3 = ZPD_Tab[2][OIL_TablePtr];
for( i = 0; i<OIL_TIMESLICE1; i++ ) // 2 msec wait
{
while(!TP4CC0IF);
TP4CC0IF = 0;
}
if(OIL_TablePtr == 0x02)
{
PM9.3 = 1;
ZPDS1 |= 0x0c; //ZPD flag detection voltage setting register
ZPDEN |= 0x04; //ZPD comparator enable
}
else
{
PM9.3 = 0;
ZPDS1 = 0x00;
ZPDEN = 0x00;
}
// OIL_TablePtr ++;
OIL_TablePtr --;
OIL_TablePtr = OIL_TablePtr % 4;
}
}
#endif
/*******************************************************************************************************
## Module: zpd.c
## Function: TMP_ZPD_loop()
## Description: this function is to realize the ZPD function of 4th meter
## Parameter: None
## Return£º void
*******************************************************************************************************/
#if MOTOR4
__callt void TMP_ZPD_loop()
{
uchar mpmpc,i;
static uchar number=1;
if(TMP_TablePtr == 0x01)
{
mpmpc = MCMPC4 & 0x20;
if(mpmpc != 0)
{
NOP(
zpd.rar_zpd_zpd.c_步进电机零位
版权申诉
150 浏览量
2022-09-22
22:31:31
上传
评论
收藏 2KB RAR 举报
![avatar](https://profile-avatar.csdnimg.cn/dabc422b995e4f93b0df429caef6266e_weixin_42656416.jpg!1)
四散
- 粉丝: 54
- 资源: 1万+