> From: John Waterman > [cut] > I carried on with the project and connected the outputs to solid state > relays which in turn control contactors using 110volt a.c. coils. Whenever > the 110volts was turned on the problem became considerably worse. I then > discovered that by replacing a sequence such as > > BCF PORTB,0 > BSF PORTB,1 > with > MOVLW 2 > MOVWF PORTB > the problem decreased dramatically. Not surprising. The output of port B did not have time to change in time for the next read-mod-write instruction. This happens with high clock speeds and moderate capacitive loading of the output, of the order of a nF or so. I always prefer to keep a shadow register for the desired state of a port if there is the slightest doubt about the port's ability to respond to command. > [cut] > go wrong in an unpredictable manner. I have put varistors across the > 110volt coils but with little or no effect. The PIC is inside a metal box > maybe around 10cms from the nearest contactor, and all the input cables are > screened - what more can I do? If you can't get rid of induced noise by using ferrite beads (as others have suggested) then as a last resort you can try using feed-through capacitors in conjunction with the other measures you are taking. Note that every cable going into the metal box, except ground, will need this treatment. You mentioned shielded cables. Check that you are not creating a ground loop by inadvertently using the cable shield as a current path. I.e. connect only one end of the shield, and ground everything at a common point or at least on a substantial conductor such as the chassis. Remember that noise can be bourne in on ground just as easily as signal or supply. Also, if you haven't already done so, you should put suppression capacitors/resistors (say 1uF, 10ohms) across the contactor points, since this will reduce fast risetimes of the inductive flyback voltage (as well as lengthening the contactor lifetime). In a similar vein, and if the application permits, use of thyristors will reduce commutation noise because they switch off at zero current. Motors can be difficult beasts to tame. I made a garage door opener which used a single phase AC motor and discrete logic. It worked - most of the time. The occasional problem caused the door to open and close a couple of times before coming to rest. Well, it turned out to be just plain old EMI coupling back through all the control lines. To this day I always stop the car before entering and ensure the door is staying put! Please keep me informed as to how you get on, since I am about to encounter on a very similar problem -- driving a PWM-controlled DC motor. Regards, SJH Canberra, Australia