Need help to control correctly DFRobot motor shield, especially direction change

Hi all,
I bought a DFRobot duemilanove compatible board and a DC motor shield by DFRObot based on the L298P IC.
Here is the sketch I use (it is very basic, I am just beginning ;-):

//Arduino PWM Speed Control?
int E1 = 5;  
int M1 = 4;
int E2 = 6;                        
int M2 = 7;                          
 
void setup()
{
    pinMode(M1, OUTPUT);  
    pinMode(M2, OUTPUT);
}
 
void loop()
{
  int value;
  for(value = 0 ; value <= 255; value+=5)
  {
    analogWrite(E1, value);   //PWM Speed Control
    analogWrite(E2, value);   //PWM Speed Control
    delay(30);
  }
  delay(2000);
  for(value = 255 ; value >= 0; value-=5)
  {
    analogWrite(E1, value);   //PWM Speed Control
    analogWrite(E2, value);   //PWM Speed Control
    delay(30);
  }
  
  digitalWrite(M1, HIGH);  
  digitalWrite(E1, HIGH);      
  delay(50);
  for(value = 0 ; value <= 100; value+=5)
  {
    analogWrite(E1, value);   //PWM Speed Control
    analogWrite(E2, value);   //PWM Speed Control
    delay(30);
  }
  delay(1000);
  for(value = 100 ; value >= 0; value-=5)
  {
    analogWrite(E1, value);   //PWM Speed Control
    analogWrite(E2, value);   //PWM Speed Control
    delay(30);
  }
  digitalWrite(E1, HIGH);
  digitalWrite(M1, LOW);      
  delay(50);
}

It works: the robot goes straight for a while then turns on itself and again straight... BUT after a while it just goes straight as if the motor shield was confused. Moreover it takes some time but not always the same amount of time before this happens.
I have two power sources: one 9v battery to power the arduino and a 6 1,2v batteries to power the motor itself, the board has jumpers for that. Both sources share the same ground as advised.
So I think I do not correctly control the shield, especially the motor direction changing. Can anbody tell me how exactly I am supposed to change motor direction? And if I overlooked something else that could be a problem?
TIA

Digital 6, Motor 1 PWM control. Digital 7, Motor 1 Direction control. dsfdsgdsga. Sample Code. //This motor shield use Pin 6,5,7,4 to control the motor // Simply ... 'w','d','x' to control the motor // www.dfrobot.com // Last ... //You can change the speed, such as Motor(50,true) Motor2(100,true); ...