rotary encoder

I want to read a rotary encoder using arduino UNO R3.

Model of rotary encoder:
autonics E50S8-500-3-T-24

autonics E50S8-1000-3-T-24
The code that i used is:

//PIN's definition
#define encoder0PinA  2
#define encoder0PinB  3

volatile int encoder0Pos = 0;
volatile boolean PastA = 0;
volatile boolean PastB = 0;

void setup() 
  Serial.begin (9600);

  pinMode(encoder0PinA, INPUT);
  //turn on pullup resistor
  //digitalWrite(encoder0PinA, HIGH); //ONLY FOR SOME ENCODER(MAGNETIC)!!!! 
  pinMode(encoder0PinB, INPUT); 
  //turn on pullup resistor
  //digitalWrite(encoder0PinB, HIGH); //ONLY FOR SOME ENCODER(MAGNETIC)!!!! 
  PastA = (boolean)digitalRead(encoder0PinA); //initial value of channel A;
  PastB = (boolean)digitalRead(encoder0PinB); //and channel B

//To speed up even more, you may define manually the ISRs
// encoder A channel on interrupt 0 (arduino's pin 2)
  attachInterrupt(0, doEncoderA, RISING);
// encoder B channel pin on interrupt 1 (arduino's pin 3)
  attachInterrupt(1, doEncoderB, CHANGE); 


void loop()
{  Serial.println(encoder0Pos);
 //your staff....ENJOY! :D

//you may easily modify the code  get quadrature..
//..but be sure this whouldn't let Arduino back! 
void doEncoderA()
     PastB ? encoder0Pos--:  encoder0Pos++;

void doEncoderB()
     PastB = !PastB; 

I took the code from :

my wiring is:

A output → digital pin2 of arduino uno
B outpot–>digital pin3 of arduino uno
+V → +12V of power supply
GND–> GND of power supply and GND pin of arduino uno.

but it does not work well. In E50S8-500-3-T-24 model, when i set the power supply on 7 v , it work well, But in data sheet told that the voltage must be 12!!!
And in E50S8-1000-3-T-24 model, it does not work correct anyways. I need to use 1000 puls encoder.

What am i doing wrong ??

Excuse my English
thank you.

I need to use 1000 pulse encoder.

You are using an algorithm which only reads 1/4 of the possible quadrature changes. Do you need the 1000 ppr model, or can you just read more available quadrature states from the 500 ppr model?

You can/will damage the Arduino when applying more than 5.5v to a digital input pin. The totem pole output on your encoder is putting out the encoder supply voltage (12-24 vdc) for a HIGH.

You are going to need a voltage divider or an optocoupler on the outputs.