/**************************************************************************************/
/* 函数名 : zPulse_Cmd_Init()
/* 功能 : z轴外部脉冲指令检测初始化
/* 返回值 :
/* 参数 :
/* 备注 :
/**************************************************************************************/
void zPulse_Cmd_Init()
{
GPIO_InitTypeDef GPIO_InitStructure; //结构体变量
EXTI_InitTypeDef EXTI_InitStructure;
//重定义PC6和PC7为定时器3的1和2通道
GPIO_PinRemapConfig(GPIO_FullRemap_TIM3,ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
// C6:ENA C7:ENB
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOC, &GPIO_InitStructure);
TIM3->ARR = 32768; //设置编码器计数上限
if(Bn_L[3] == 2)
//四倍计数
TIM_EncoderInterfaceConfig( TIM3, TIM_EncoderMode_TI12, TIM_ICPolarity_Rising, TIM_ICPolarity_Rising ); // Configures the encoder mode TI1 for TIM4
else if(Bn_L[3] == 1)
{
TIM_EncoderInterfaceConfig( TIM3, TIM_EncoderMode_TI1, TIM_ICPolarity_Rising, TIM_ICPolarity_Rising ); // Configures the encoder mode TI1 for TIM4
//先清除该寄存器后八位
TIM3->SMCR = TIM3->SMCR & 0xff88;
//设置外部触发
TIM3->SMCR = TIM3->SMCR | 0x67;
if(!rd_io(Pz_CMD_DIR))
//低电平向下计数
TIM3->CR1 = TIM3->CR1 | 0x10;
else
//高电平向上计数
TIM3->CR1 = TIM3->CR1 & 0xef;
//设置方向中断
GPIO_EXTILineConfig( GPIO_PortSourceGPIOC, GPIO_PinSource6 ); //设置Z相中断
EXTI_InitStructure.EXTI_Line = EXTI_Line6;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init( &EXTI_InitStructure );
}
TIM_Cmd( TIM3, ENABLE ); //使能TIM3
}
/* 函数名 : zPulse_Cmd_Init()
/* 功能 : z轴外部脉冲指令检测初始化
/* 返回值 :
/* 参数 :
/* 备注 :
/**************************************************************************************/
void zPulse_Cmd_Init()
{
GPIO_InitTypeDef GPIO_InitStructure; //结构体变量
EXTI_InitTypeDef EXTI_InitStructure;
//重定义PC6和PC7为定时器3的1和2通道
GPIO_PinRemapConfig(GPIO_FullRemap_TIM3,ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
// C6:ENA C7:ENB
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOC, &GPIO_InitStructure);
TIM3->ARR = 32768; //设置编码器计数上限
if(Bn_L[3] == 2)
//四倍计数
TIM_EncoderInterfaceConfig( TIM3, TIM_EncoderMode_TI12, TIM_ICPolarity_Rising, TIM_ICPolarity_Rising ); // Configures the encoder mode TI1 for TIM4
else if(Bn_L[3] == 1)
{
TIM_EncoderInterfaceConfig( TIM3, TIM_EncoderMode_TI1, TIM_ICPolarity_Rising, TIM_ICPolarity_Rising ); // Configures the encoder mode TI1 for TIM4
//先清除该寄存器后八位
TIM3->SMCR = TIM3->SMCR & 0xff88;
//设置外部触发
TIM3->SMCR = TIM3->SMCR | 0x67;
if(!rd_io(Pz_CMD_DIR))
//低电平向下计数
TIM3->CR1 = TIM3->CR1 | 0x10;
else
//高电平向上计数
TIM3->CR1 = TIM3->CR1 & 0xef;
//设置方向中断
GPIO_EXTILineConfig( GPIO_PortSourceGPIOC, GPIO_PinSource6 ); //设置Z相中断
EXTI_InitStructure.EXTI_Line = EXTI_Line6;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init( &EXTI_InitStructure );
}
TIM_Cmd( TIM3, ENABLE ); //使能TIM3
}