-
HC32L176JETA Pcnt模块
使用PCNT模块给霍尔传感器脉冲计数时,采用官方例程单脉冲计数可用,双通道非交脉冲计数模式时,g_u32CircleCount=Pcnt_GetCnt();使用该函数观测计数值无变化。下图是所使用的例程}/**********************************************************************************\brief初始化外部GPIO引脚****\return无******************************************************************************/staticvoidApp_GpioInit(void){stc_gpio_cfg_tGpioInitStruct;DDL_ZERO_STRUCT(GpioInitStruct);Sysctrl_SetPeripheralGate(SysctrlPeripheralGpio,TRUE);GpioInitStruct.enDrv=GpioDrvH;GpioInitStruct.enDir=GpioDirIn;Gpio_Init(GpioPortB,GpioPin5,&GpioInitStruct);Gpio_SetAfMode(GpioPortB,GpioPin5,GpioAf6);//PB05作为PCNT_S0Gpio_Init(GpioPortB,GpioPin7,&GpioInitStruct);Gpio_SetAfMode(GpioPortB,GpioPin7,GpioAf7);//PB07作为PCNT_S1//GpioInitStruct.enDir=GpioDirOut;//Gpio_Init(STK_LED_PORT,STK_LED_PIN,&GpioInitStruct);//PD14配置成输出,控制板上蓝色LED//Gpio_WriteOutputIO(STK_LED_PORT,STK_LED_PIN,TRUE);}/**********************************************************************************\brief配置PCNT****\return无******************************************************************************/staticvoidApp_PcntInit(void){stc_pcnt_initstruct_tPcntInitStruct;DDL_ZERO_STRUCT(PcntInitStruct);Sysctrl_SetPeripheralGate(SysctrlPeripheralPcnt,TRUE);PcntInitStruct.Pcnt_S0Sel=PcntS0PNoinvert;//S0输入极性不取反PcntInitStruct.Pcnt_S1Sel=PcntS1PNoinvert;//S1输入极性不取反PcntInitStruct.Pcnt_Clk=PcntCLKPclk;//采样时钟PcntInitStruct.Pcnt_Mode=PcntSpecialMode;//双通道正交脉冲计数模式PcntInitStruct.Pcnt_FltEn=TRUE;//滤波使能PcntInitStruct.Pcnt_DebTop=5;/
2025-05-12 4