CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Rs232 acts weird!!!

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
vladtess



Joined: 14 May 2011
Posts: 26

View user's profile Send private message

Rs232 acts weird!!!
PostPosted: Mon Apr 23, 2012 11:54 pm     Reply with quote

Hello fellows. This may be an inappropriate place for this but please hear me out.

I have a PIC18 connected to a different pic16 via SPI and a PC terminal via RS232 using a USB to TTL module by Prolific. Anyway. The PIC18 project turns off an on 120V relays (using a transistor).

All works great as intended: relays turn on and off as needed through SPI and RS232 and all is great: lights go on and off, my amp works on and off. However!! Any time I turn on some form of motor, such as AC 120 V motor, or an AC drill, or even 12V fan for the computer, the USB to TTL module acts weird!!!!!!!!!

Basically, the GUI stops responding when I turn on and off the motors two or three times. SPI always works fine!

Then I took one of the classic UART PCI cards (<1995) and used a MAX232 and everything works as charm (except limited baud of course).

I am guessing that motor somehow interferes with the USB to TTL module, is that possible?!!! And what can be done to prevent it?

Thanks much!!!
Ttelmah



Joined: 11 Mar 2010
Posts: 19504

View user's profile Send private message

PostPosted: Tue Apr 24, 2012 2:09 am     Reply with quote

This sounds a classic 'noise' problem.
There have been quite a few posts here about this and variants in the past, and millions (probably billions), on the web as a whole....

The problem is that it won't be a simple 'this is causing it' answer. Several things could be causing the problem:

First, are you sure it is when you turn the device 'on', rather than _off_?.
Basically, anything containing an inductor (read your relay coils, motors, etc. etc..), has the property, that when you _disconnect_ power feeding into it, the magnetic field inside contains significant energy, which has to go somewhere. The problem is that with nothing connected to take this energy, the voltage across the inductor rises, until it finds somewhere to go. This is how things like camera flashguns develop 500 volts, from only a little 6v battery!. This is sometimes referred to as 'flyback'.
So, first thing to do, is triple check whether in fact anything has to be attached to cause the problem - you might just be getting a spike from the relay coil!. This is why transistors driving relays should have a diode across the relay coil, to take this energy.
Then test again and prove if it is when the device switches on or off.

If it is still when things turn 'on', and a device has to be present, you have ruled out the relay coil as the problem, and also flyback energy from the devices themselves - same problem applies to this as to the relay coil, which results typically in the relay 'arcing' as it switches off - common solution is a 'snubber' network across the contact to kill this - without this, relays get killed quite quickly, and the arc itself acts as a radio transmitter affecting local equipment....

If it is when you switch 'on', then instead of the flyback problems, you have two possible other things. The first is 'inrush'. Many things (motors, cold lamp bulbs etc. etc..), draw far more current when you first switch on, than when they are running. This if why fuses often blow when things are first switched. This current pulse, will cause supply lines to droop on other kit attached to the same power, but also, wires adjacent to wires delivering this power, will act as transformers, and get significant voltages induced in them. The sharpness of the current pulse, will depend on 'when' in the mains cycle the device is turned on. If the mains waveform is at 'zero' when the device turns on, there is a fairly gentle rise as the waveform ramps up. If instead the waveform is at max voltage at the moment the device switches, you get a much nastier pulse - this is why industrial controllers have circuitry to implement 'zero voltage switching', only turning devices off/on at the zero points. Once 'on', you have the separate issues that the device itself may generate some interference (particularly brushed motors), and currents flowing in the wires to the device, can again form an effective transformer to other nearby wires, coupling voltages into these.
Finally you have the question of what is earthed where?. Your USB adapter will be effectively earthed to the PC, which may well be floating from the mains (if a laptop), or connected at it's plug. Your kit then is earthed somewhere else. The power kit is then earthed at a third location. When this switches 'on', the current surge will create voltage differences between the other pieces of kit, which can result in incorrect operation.

You need to look at several things:

Wires to power kit, should be twisted together, and kept separate from signal wires.
Then earths should all go back to _one_ point.
Then consider shielding data wires (with a shield grounded back to the earth point).
Then add trap diodes to the relay coils.
Finally add snubber networks to the contacts.

These should give you a basic 'start' in building to avoid noise problems.

Best Wishes
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Tue Apr 24, 2012 9:14 am     Reply with quote

I would look carefully at your ground connections first. Remember all wires have resistance. If you have motor currents going through a ground wire, especially current spikes from turning on or off, then the two ends of the wire will be at different voltages.

Any RS232, TTL or SPI input looks at the voltage difference between the input pin and that chips ground pin. If that ground pin is at a different voltage from the transmitter chips ground pin then the receiver will see that ground difference as a signal difference.

The solution is a single point ground also called a supernode or star grounding. Very big ground wires help, but not as much as running the grounds correctly in the first place.

USB has differential signal wires that ideally should eliminate that problem. But in reality a big enough ground shift can even affect USB connections.
_________________
The search for better is endless. Instead simply find very good and get the job done.
vladtess



Joined: 14 May 2011
Posts: 26

View user's profile Send private message

PostPosted: Tue Apr 24, 2012 7:54 pm     Reply with quote

Thanks for your replies!

Basically here's the setup:

I have a supply running through a transformer that powers the PIC and relays. Relays are used with the Diodes to protect transistors, so relays are not a problem, because when I turn on/off non-motor devices, there are no problems. Relays simply closes the loop to power external devices and are completely isolated from the PIC (transformer powering PIC and relays). The PIC's ground is NOT connected to the outlet Ground.

And yes, I tested and realized that only when the motor powers down does the module stop responding. If I wait a few second are powering down, everything works wells.

Please do note that I use SPI at DIV_2 @ 4MHz and it is NOT affected at all, so is old RS232 method (PCI card). Only when the USB to TTL is used.

I will try to use some EM protection, get the protected USB cable as well as protect the USB to TTL module as well and I'll tell you how it goes.

Thanks a lot for all of your help!!
vladtess



Joined: 14 May 2011
Posts: 26

View user's profile Send private message

PostPosted: Tue Apr 24, 2012 11:17 pm     Reply with quote

Hello fellas!

So I have tried shielding of the RS232 module, its wiring, but nothing helped.

However while testing with other forms of RS232, I discovered that if I connect +5 with both, PIC and the RS232 module no interference was made!!!

Please explain this to me if anyone can! Why do I need a +5?!! It worked fine without it: only with GND, RX, and TX, but interference was vast.

Thanks much!!!!!!!
Ttelmah



Joined: 11 Mar 2010
Posts: 19504

View user's profile Send private message

PostPosted: Wed Apr 25, 2012 1:16 am     Reply with quote

Without it, the module is having to get it's 5v, from the USB cable. Suggests this is where the noise problem lies. If the cable is even of moderate length, there will be some droop in this rail. Assume the PC only feeds this with perhaps 4.8v, and there is half a volt loss in the cable, then you are only getting perhaps 4.3v. Then make a guess that the module goes wrong if the supply drops below 4v. Only takes 0.3v of induced noise on this supply line, to have problems appearing.....
Now all of the figures there are just guesses, but they give the idea.

Best Wishes
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group