📄 d_output.r
字号:
*AT91C_TC0_CMR = *AT91C_TC0_CMR | AT91C_TC_LDRA_RISING; /* RA loading register set */\
*AT91C_AIC_IDCR = TIMER_0_ID12; /* Disable interrupt */\
AT91C_AIC_SVR[12] = (unsigned int)CaptureCInt; \
AT91C_AIC_SMR[12] = 0x05; /* Enable trigger on level */\
*AT91C_AIC_ICCR = TIMER_0_ID12; /* Clear interrupt register PID12*/\
*AT91C_TC0_IDR = 0xFF; /* Disable all interrupt from TC0 */\
*AT91C_TC0_IER = 0x80; /* Enable interrupts from external trigger */\
*AT91C_AIC_IECR = TIMER_0_ID12; /* Enable interrupt from TC0 */\
*AT91C_TC0_CCR = 0x00; /* Clear registers before setting */\
*AT91C_TC0_CCR = AT91C_TC_CLKEN; /* Enable clock */\
}
__ramfunc void CaptureAInt(void)
{
if (*AT91C_TC1_SR & AT91C_TC_MTIOA)
{
if (*AT91C_PIOA_PDSR & MOTOR_A_DIR)
{
MotorTachoValue[0].MotorDirection = REVERSE; //Motor is running reverse
MotorTachoValue[0].TachoCountTable--;
}
else
{
MotorTachoValue[0].MotorDirection = FORWARD; //Motor is running forward
MotorTachoValue[0].TachoCountTable++;
}
}
else
{
if (*AT91C_PIOA_PDSR & MOTOR_A_DIR)
{
MotorTachoValue[0].MotorDirection = FORWARD;
MotorTachoValue[0].TachoCountTable++;
}
else
{
MotorTachoValue[0].MotorDirection = REVERSE;
MotorTachoValue[0].TachoCountTable--;
}
}
}
__ramfunc void CaptureBInt(void)
{
if (*AT91C_TC2_SR & AT91C_TC_MTIOA)
{
if (*AT91C_PIOA_PDSR & MOTOR_B_DIR)
{
MotorTachoValue[1].MotorDirection = REVERSE; //Motor is running reverse
MotorTachoValue[1].TachoCountTable--;
}
else
{
MotorTachoValue[1].MotorDirection = FORWARD; //Motor is running forward
MotorTachoValue[1].TachoCountTable++;
}
}
else
{
if (*AT91C_PIOA_PDSR & MOTOR_B_DIR)
{
MotorTachoValue[1].MotorDirection = FORWARD;
MotorTachoValue[1].TachoCountTable++;
}
else
{
MotorTachoValue[1].MotorDirection = REVERSE;
MotorTachoValue[1].TachoCountTable--;
}
}
}
//__ramfunc void CaptureBInt(void)
//{
// if (((bool)(*AT91C_TC2_SR & AT91C_TC_MTIOA))==((bool)(*AT91C_PIOA_PDSR & MOTOR_B_DIR)))
// {
// MotorTachoValue[1].MotorDirection = REVERSE; //Motor is running reverse
// MotorTachoValue[1].TachoCountTable--;
// }
// else
// {
// MotorTachoValue[1].MotorDirection = FORWARD; //Motor is running reverse
// MotorTachoValue[1].TachoCountTable++;
// }
//}
__ramfunc void CaptureCInt(void)
{
if (*AT91C_TC0_SR & AT91C_TC_MTIOA)
{
if (*AT91C_PIOA_PDSR & MOTOR_C_DIR)
{
MotorTachoValue[2].MotorDirection = REVERSE; //Motor is running reverse
MotorTachoValue[2].TachoCountTable--;
}
else
{
MotorTachoValue[2].MotorDirection = FORWARD; //Motor is running forward
MotorTachoValue[2].TachoCountTable++;
}
}
else
{
if (*AT91C_PIOA_PDSR & MOTOR_C_DIR)
{
MotorTachoValue[2].MotorDirection = FORWARD;
MotorTachoValue[2].TachoCountTable++;
}
else
{
MotorTachoValue[2].MotorDirection = REVERSE;
MotorTachoValue[2].TachoCountTable--;
}
}
}
#define OUTPUTExit {\
*AT91C_AIC_IDCR = TIMER_0_ID12 | TIMER_1_ID13 | TIMER_2_ID14; /* Disable interrupts for the timers */\
*AT91C_AIC_ICCR = TIMER_0_ID12 | TIMER_1_ID13 | TIMER_2_ID14; /* Clear penting interrupt register for timers*/\
*AT91C_PMC_PCDR = TIMER_0_ID12 | TIMER_1_ID13 | TIMER_2_ID14; /* Disable the clock for each of the timers*/\
*AT91C_PIOA_PER = MOTOR_A_DIR | MOTOR_A_INT | MOTOR_B_DIR | MOTOR_B_INT | MOTOR_C_DIR | MOTOR_C_INT; /* Enable PIO on PA15, PA11, PA26, PA09, PA27 & PA08 */\
*AT91C_PIOA_ODR = MOTOR_A_DIR | MOTOR_A_INT | MOTOR_B_DIR | MOTOR_B_INT | MOTOR_C_DIR | MOTOR_C_INT; /* Set to input PA15, PA11, PA26, PA09, PA27 & PA08 */\
*AT91C_PIOA_PPUDR = MOTOR_A_DIR | MOTOR_A_INT | MOTOR_B_DIR | MOTOR_B_INT | MOTOR_C_DIR | MOTOR_C_INT; /* Enable Pullup on PA15, PA11, PA26, PA09, PA27 & PA08 */\
}
#define TACHOCountReset(MotorNr) {\
MotorTachoValue[MotorNr].TachoCountTable = 0;\
MotorTachoValue[MotorNr].TachoCountTableOld = 0;\
}
#define TACHOCaptureReadResetAll(MotorDataA,MotorDataB,MotorDataC){\
MotorDataA = (MotorTachoValue[MOTOR_A].TachoCountTable - MotorTachoValue[MOTOR_A].TachoCountTableOld);\
MotorTachoValue[MOTOR_A].TachoCountTableOld = MotorTachoValue[MOTOR_A].TachoCountTable;\
MotorDataB = (MotorTachoValue[MOTOR_B].TachoCountTable - MotorTachoValue[MOTOR_B].TachoCountTableOld);\
MotorTachoValue[MOTOR_B].TachoCountTableOld = MotorTachoValue[MOTOR_B].TachoCountTable;\
MotorDataC = (MotorTachoValue[MOTOR_C].TachoCountTable - MotorTachoValue[MOTOR_C].TachoCountTableOld);\
MotorTachoValue[MOTOR_C].TachoCountTableOld = MotorTachoValue[MOTOR_C].TachoCountTable;\
}
#define GetMotorDirection(MotorNr) MotorTachoValue[MotorNr].MotorDirection
#endif
#ifdef PCWIN
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -