encoder reading problem

I am using the following code to read the encoder data in arduino uno using LS7184 decoder. It works ok when the motor is actuated through outside power supply. When I use the motor driver to actuate the motor sending PWM and direction signals through arduino the encoders data are not good. I changed the arduino uno but the same result.
If someone can help me to solve this problem.
Thank you

const int clkPinA = 2;
const int dirPinA = 4;
const int DirPIN=12; // Motor direction pin
const int PWMPin=10; // pwm
volatile int encoderACount = 0;
volatile boolean changeFlag = false;
int command;
void setup() {
Serial.begin(9600);
pinMode(clkPinA, INPUT);
pinMode(dirPinA, INPUT);
pinMode(DirPIN, OUTPUT);
pinMode(PWMPin, OUTPUT);
attachInterrupt(0, encoderIntA, RISING);
}

void loop() {
if (changeFlag) {
changeFlag = false;
Serial.println(encoderACount);
}
command=30;
analogWrite(PWMPin,command);
digitalWrite(DirPIN,LOW);
}

void encoderIntA() {
if (digitalRead(dirPinA) == HIGH)
encoderACount++;
else
encoderACount--;
changeFlag = true;
}