PSoC 5, Counter UpCnt & DwnCnt mode as an Encoder

336 Views Asked by At

I am new in the Stack Overflow community, I hope that you can help me with this issue. I am trying to read an encoder without using interrupts. The solution that came to my mind is to use a counter that, using PSoC, can be selected with the UpCnt & DwnCnt mode. Pin_encoder_B and Pin_encoder_A are my two signal wires that go high and down according to the rotation of my encoder. I am using Pin_encoder_A as clock, when it turns up I look at the Pin_encoder_B, if Pin_encoder_B and Pin_encoder_A are equal or disequal I understand if my encoder is tourning clockwise or counterclockwise and I should be able to decrement or increment my counter properly. I have tried almost everything but the function Counter_ReadCounter(); (in my code Counter_Logic_ReadCounter();) returns me always the period value. I cannot understand how to fix it. Can someone tell me what is wrong in my code? Thank you all.

int main(void)
{
CyGlobalIntEnable;
UART_Start();
Counter_Logic_Start();
Timer_Start();
isr_sin_StartEx(Custom_ISR_SIN);
Pos_senza_isr=0;

for(;;)
{
}

}

#include "InterruptRoutine.h"
#include "project.h"

CY_ISR(Custom_ISR_SIN){
Timer_ReadStatusRegister();
Pos_senza_isr=Counter_Logic_ReadCounter();
sprintf(DataBuffer, "%ld\r\n", Pos_senza_isr);
UART_PutString(DataBuffer);
}
enter image description here

1

There are 1 best solutions below

1
JAGADISH K On

You can use a Quadrature decoder component, which takes care of your said requirement.