H-bridge Motor circuit and Serial port error

Hi everyone
Here I use the following webpage to implement a h-bridge motor circuit with Arduino.
http://www.mcmanis.com/chuck/robotics/tutorial/h-bridge/bjt-circuit.html

The differences with mine are optocouplers&resistors and 24V DC and Arduino Mega.

Flickr ? good_wise ? bjt-schematic (1)

I use TLP512-2 optocoupler and 300ohm resistor to drive the optocouplers.
datasheet: TLP521-2 pdf, TLP521-2 Description, TLP521-2 Datasheet, TLP521-2 view ::: ALLDATASHEET :::

Writing some code to drive it as the motor run between forward and stop with 1 sec interval,
which the control pins are *EN=1 FORWARD=1 REVERSE=0(stop)
*EN=0 FORWARD=1 REVERSE=0(forward)

void setup(){
  pinMode(2,OUTPUT);//FORWARD pin
  pinMode(3,OUTPUT);//BACKWARD pin
  pinMode(4,OUTPUT);//*EN pin
  digitalWrite(2,HIGH);//FOWARD initially
  digitalWrite(3,LOW);
}
void loop(){
  digitalWrite(4,HIGH);//stop
  delay(1000);   //1 sec interval
  digitalWrite(4,LOW);//running forward
  delay(1000);   //1 sec interval
}

Here comes problem
Every time the motor was running, the serial port became corrupted.
For example, here is the situation when i push the upload button in IDE.
IDE keep in uploading status, then output some error message.

Flickr ? good_wise ? uploading

Then I push the upload button again , IDE tells the COM port is already in use.

Flickr ? good_wise ? uploadingcomport
Now the Serial monitor button also become unavailable, no pop up window appears.

All upon error situation become normal until I turn off the 24 power supply and replug the arduino's usb line, or I writing the code that the motor is in stop status.
The error status occurs only when motor running.

As a conclusion, I think this is a electric problem , but seems unreasonable sence I had use the optocouper to isolate the Arduino 5V-system and external 24V-system,especially there's only 3 control pins(FWD,REV,*EN) are connected with arduino,no common gnd with 24v's V-.

Anyone can help and knowing the reason???

Here is the implement picture:

Flickr ? good_wise ? IMG_20120809_113800

Just because you have isolated the drive circuit does not stop airborne interference from the motor.
Add supply decoupling to both the arduino and motor supply. Also put a small capacitor across the motor.

Does power decoupling means adding the capacitors cross these pins between??
[arduino's 5v&gnd] , [24v power v+&v-] , [3 signal&arduino gnd].
I suppose to put 0.1uf at these pins.

where's the capacitor should put cross the motor? Is it means put two capacitor forward(long leg/short leg) and reverse(short leg/long leg) between the motor ??

You need to read:-
http://www.thebox.myzen.co.uk/Tutorial/De-coupling.html
Try with just capacitors and if that doesn't work go for the Pi circuit, that s the last one on the page.

Is it means put two capacitor forward(long leg/short leg) and reverse(short leg/long leg) between the motor ??

No, just use one ceramic non polarised capacitor across the motor.

Have you successfully tested your h-bridge without the arduino connected? Have you been able to upload your code to the arduino without the h-bridge connected to the arduino?

This sort of problem is typically noise coupling on the supplies. Specifically if you have the grounds of the 24V supply connected to the ground of the 5V arduino supply you get a phenomena called 'ground bounce' as the motor brushes make and break contact. (fun tip you can run that through a transformer and make a tachometer out of it). The usual solution is to put a small inductor (coil) between the ground of the motor supply and the ground of the digital supply. (although with opto isolation they can be not connected at all). Another thing you can do is to put a capacitor across the motor terminals (.1 - .5 pF) which will suppress some of the brush noise, and a larger capacitor (between 100uF and 300uF) between the 24V+ and the motor ground on the bread board near the transistors. This keeps spikes from going back to the power supply.

--Chuck