Is there any example code for checking Encoder counting?

Hi all. I'm planning to do my work with several motors, and they need to change their angles at times.
I'm gonna use PID position control (with Arduino code).

To do so, first of all, I'm trying to use encoder but I'm not sure it works.
The motor is Maxon DCX geared brushed motor with encoder. Gear ratio is 16:1 and the resolution is 1024, so I'm a little afraid that arduino can miss the interrupt signal when motor rotates.
So, I'm trying to test if the encoder works well(if counting works), but not sure with which code to use.
Can anyone recommend the link or simple code?
Thanx.

#define encA 2
#define encB 3

volatile int enc0 = 0;
int en1 = 5; // motor1 enable
int dir1 = 4; // motor1 direction
int pwm1 = 6; // motor1 pwm
int btn1 = 10; // digital pin 10

int btn_state1 = 0;

unsigned long preMillis = 0;
int sample = 50;
double dt = sample*0.001;
double u, pwm = 0;
double dpp = 360/1024; // degree per pulse
double pos1 = dpp/10; // movement of 10' 
double theta = 0;

// position control
double error1 = 0;
double error1_old = 0;
double error1_dot = 0;
double error1_sum = 0;
double theta1_dum = 0;

// PID Coefficient
double kp1 = 1.15;
double kd1 = 0.08;
double ki1 = 0.8;
double kp2 = 1.0;
double kd2 = 0.03;
double ki2 = 0.1;

void setup()
{
  pinMode(btn1, INPUT);
  pinMode(en1, OUTPUT);
  pinMode(dir1, OUTPUT);
  pinMode(encA, INPUT);
  digitalWrite(encA, HIGH);
  pinMode(encB, INPUT);
  digitalWrite(encB, HIGH);
  attachInterrupt(0, doEncoder_Expanded, CHANGE);
  Serial.begin(9600);
  Serial.println("start");
}

void loop()
{
  btn_state1 = digitalRead(btn1);
  
  unsigned long currentMillis = millis();
  if (currentMillis - preMillis >= sample)
  {
    preMillis = currentMillis;
    
    theta = enc0;
    
    // movement of 10' //
    if(btn_state1 == HIGH)
    {
      error1 = (pos1-theta);
      error1_dot = (error1-error1_old)/dt;
      error1_sum = error1_sum + error1*dt;
      
      digitalWrite(en1,HIGH);
      
      if (error1 >= 0){
        digitalWrite(dir1,HIGH);
        u = kp1*error1 + (kd1*error1_dot) + ki1*error1_sum;}
      
      else if (error1 < 0) {
        u = kp2*error1 + (kd2*error1_dot) + ki2*error1_sum;}
        
        pwm = constrain(u,0,150);
        analogWrite(pwm1,pwm);
        error1_old = error1;
        theta1_dum = theta;
    }
    
    else {
      digitalWrite(en1,LOW);
      error1, error1_dot, error1_sum, enc0, u = 0;}
      
  }
}

void doEncoder_Expanded() {
  if (digitalRead(encA) == HIGH) {
    if (digitalRead(encB) == LOW) {
      enc0 = enc0 -1;
    }
    else {enc0 = enc0 + 1;}
  }
  else {
    if (digitalRead(encB) == LOW) {
      enc0 = enc0 + 1;
    }
    else {enc0 = enc0 - 1;}
  }
}

This is code for 10 degree position control when the button on the breadboard is pressed. But it doesn’t work at all… the motor rotates over 10 degree and it is supposed to rotate whenever I press the button but it is not.
I think there’s a lot of problems, but don’t know where to start.

I am in a similar situation to you, I ended up just using an encoder counting IC.

I got one from robogaia, works well.

The motor is Maxon DCX geared brushed motor with encoder. Gear ratio is 16:1 and the resolution is 1024, so I'm a little afraid that arduino can miss the interrupt signal when motor rotates.

There's no need to be afraid, do the maths and work out the maximum interrupt frequency. You can handle interrupts in a few us
if you keep the code tight and use direct port manipulation. With an encoder you have the choice of whether to interrupt on every
transition or on every-other transition. Is the encoder before or after the gearbox?

I'm not sure which one is before/after..
the sequence is : motor shaft(which rotates)-gearbox-motor body(?)-encoder