Hi,
We an encoder connected to Port H. The encoder is actually a 3 bits knob such that 2 bits are used to identify if the encoder is rotated clock wise or anti-clock wise and the 3rd Bit working as a push button to toggle between Course and Fine adjustment of power supply output current. The Knob part number is 427-121251AL121.
We are running following two interrupts;
- Interrupt 1 on GPIO_PIN_0: Output Current setting interrupt to detect the Knob is clockwise rotated or anti-clock wise. This interrupt is working fine and there are no bouncing effect
- as there is a 1kRx0.1uC filter on the signal.
- Interrupt 2 on GPIO_PIN_2: Coarse / Fine adjustment interrupt that is used to define the output current to be adjusted with a Coarse resolution or a Fine resolution. This interrupt triggers twice. There is no bouncing effect as there is a 1kRx0.1uC filter on the signal.
The Interrupt 1 works fine. It is set to trigger on Both edges of the pulse. As can be seen in the following code for Pin GPIO_PIN_0 defined as RSW_D0 pin;
void EncoderPulses_interrupt_enable(void)
{
IntMasterDisable();
GPIOPinTypeGPIOInput(ENC_PORT, RSW_D0);
GPIOPinTypeGPIOInput(ENC_PORT, RSW_D1);
GPIOPadConfigSet(ENC_PORT, RSW_D0, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);
GPIOPadConfigSet(ENC_PORT, RSW_D1, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); // Enable weak pullup resistor
GPIOIntDisable(ENC_PORT, RSW_D0); // Disable interrupt
GPIOIntClear(ENC_PORT, RSW_D0); // Clear pending interrupts
GPIOIntRegister(ENC_PORT, Encoder_IntHandler);
GPIOIntTypeSet(ENC_PORT, RSW_D0, GPIO_BOTH_EDGES);
GPIOIntEnable(ENC_PORT, RSW_D0); // Enable interrupt
IntMasterEnable();
}
The Interrupt 2 triggers twice each time it is activated. This interrupt is configured to trigger only on Falling edge. Following is the code for configuring the interrupt on Pin GPIO_PIN_2 defined as RSW_D2 pin.
void EncoderMode_interrupt_enable(void)
{
IntMasterDisable();
GPIOPinTypeGPIOInput(ENC_PORT, RSW_D2);
GPIOPadConfigSet(ENC_PORT, RSW_D2, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); // Enable weak pullup resistor
GPIOIntDisable(ENC_PORT, RSW_D2); // Disable interrupt
GPIOIntClear(ENC_PORT, RSW_D2); // Clear pending interrupts
GPIOIntRegister(ENC_PORT, Encoder_IntHandler);
GPIOIntTypeSet(ENC_PORT, RSW_D2, GPIO_FALLING_EDGE); // Configure falling edge trigger
GPIOIntEnable(ENC_PORT, RSW_D2); // Enable interrupt
IntMasterEnable();
}
Following is the Function invoked whenever the interrupt is triggered on either of the two Pins (e.g. GPIO_PIN_2 and/or GPIO_PIN_0)
void Encoder_IntHandler(void)
{
SysCtlDelay(1*17000);//Clear the Interrupt after the Delay to avoid multiple Interrupt entries.
if(GPIOIntStatus(ENC_PORT, false) & RSW_D0) //Check if the Interrupt is for RSW_D0 (GPIO_PIN_0) or RSW_D2 (GPIO_PIN_2)
{
uint8_t i,j;
GPIOIntClear(ENC_PORT, RSW_D0);
i = GPIOPinRead(ENC_PORT,RSW_D0);
j = GPIOPinRead(ENC_PORT,RSW_D1);
if (j==2){j = 1;} // When GPIO_PIN_1 is HIGH it GPIOPinRead() will report 0x2H. Replace it to 0x1H
//Detect if the Encoder is moved CC or ACC
if(i == j){EncoderServiceReqType = EncoderCCW;} //Encoder moved Anti-Clockwise
else{EncoderServiceReqType = EncoderCW;} //Encoder moved Clockwise
}
else
{
GPIOIntClear(ENC_PORT, RSW_D2);
EncoderServiceReqType = EncoderMBtn;
}
EncoderServiceReqFlag = 1;
}
The definitions are;
#define ENC_PORT GPIO_PORTH_BASE #define RSW_D0 GPIO_PIN_0 // Interrupt 1 Pin. #define RSW_D1 GPIO_PIN_1 #define RSW_D2 GPIO_PIN_2 //Interrupt 2 Pin. Encoder Push Button to switch between Fine and Coarse adjustment
I thank you all for your help.
Regards,
Sahil