Pic 12 driving 2 12v relays, Pic reset problem

Thread Starter

Hoylegj

Joined Mar 10, 2016
26
Hi, I've built this and it works fine until I connect the motor, then it goes a bit pear shaped and the PIC randomly starts resetting. Without the motor the relays trigger fine and the voltages look good, but there must be a spike causing the reset. My other thought is cross feed on the board.

The transistors are BC337 and diodes are 1N4004 across the relays and these may be the problem, but I though I would ask if I have missed something else as well before I starting to switch components out and making a new board with better separation. Uses a purchased 12 to 5 volt regulator.

See attached pictures

Thanks for looking and helping.
IMAG0435_1024x745.jpg
volt_reg.jpg
 

AlbertHall

Joined Jun 4, 2014
8,818
You should have a decoupling capacitor, 100nF, across the PIC Vdd/Vss as close as possible to the chip. You will probably also need one of those on /MCLR.
 

AlbertHall

Joined Jun 4, 2014
8,818
Back emf diodes across the motor will improve the spikes you will need 4, and power smoothing capacitor across the pic supply.
TS can't put diodes across the motor as it is bi-directional. TS Could put 100nF across the motor terminals and from each terminal to the motor case (assuming it is metal).
 

Thread Starter

Hoylegj

Joined Mar 10, 2016
26
Also the relay contacts could be a problem, is there are reason you did not use Mosfets?
Most include integral diode.
Max.
Yes thanks that probably a good idea. Just never used them in this type of circuit, Will have a look and see if I can work out how to configure them to give the switching required.
 

Thread Starter

Hoylegj

Joined Mar 10, 2016
26
Hi, thanks for your comments so far, I've tried a 100nf cap across the pic without any joy, and waiting for other caps to turn up, so I thought I'd try and be more scientific, I have a cheap PC scope so I put that across the 5 volts to see what was going on. I'm getting 5.2v and when the reset happens it drops to 5.1. Now, the pic12f1840 data sheet says it will run down under 3 volts, so I don't understand what's causing the reset. I then left the circuit intact, relays attracted, but cut the power to the motor and just ran the pic circuit. This performed as expected and relay triggered and the correct voltages were switched. So I then ran the motor by connecting it directly to the battery ( motor cycle 12v) while the board was up and running and even that cause the pic to reset. This run is where I determined the 0.1 volt drop on the 5volt rail. The scope isn't showing a dirty power either. It's going to be something really silly !!!

Should a 0.1 volt drop cause the processor to reset, I don't think so, so now I'm stumped. Here's the config in case I'm missing something.. thanks in advance,

/* CONFIG1 */
#pragma config FOSC = INTOSC /* Oscillator Selection (INTOSC oscillator: I/O function on CLKIN pin) */
#pragma config WDTE = OFF /* Watchdog Timer Enable (WDT disabled) */
#pragma config PWRTE = OFF /* Power-up Timer Enable (PWRT disabled) */
#pragma config MCLRE = OFF /* MCLR Pin Function Select (MCLR/VPP pin function is MCLR) */
#pragma config CP = OFF /* Flash Program Memory Code Protection (Program memory code protection is disabled) */
#pragma config CPD = OFF /* Data Memory Code Protection (Data memory code protection is disabled) */
#pragma config BOREN = OFF /* Brown-out Reset Enable (Brown-out Reset disabled) */
#pragma config CLKOUTEN = OFF /* Clock Out Enable (CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin) */
#pragma config IESO = OFF /* Internal/External Switchover (Internal/External Switchover mode is disabled) */
#pragma config FCMEN = OFF /* Fail-Safe Clock Monitor Enable (Fail-Safe Clock Monitor is disabled) */

/* CONFIG2 */
#pragma config WRT = OFF /* Flash Memory Self-Write Protection (Write protection off) */
#pragma config PLLEN = OFF /* PLL Enable (4x PLL disabled) */
#pragma config STVREN = ON /* Stack Overflow/Underflow Reset Enable (Stack Overflow or Underflow will cause a Reset) */
#pragma config BORV = LO /* Brown-out Reset Voltage Selection (Brown-out Reset Voltage (Vbor), low trip point selected.) */
#pragma config LVP = OFF /* Low-Voltage Programming Enable (High-voltage on MCLR/VPP must be used for programming) */
 

Attachments

eetech00

Joined Jun 8, 2013
1,740
Hi, thanks for your comments so far, I've tried a 100nf cap across the pic without any joy, and waiting for other caps to turn up, so I thought I'd try and be more scientific, I have a cheap PC scope so I put that across the 5 volts to see what was going on. I'm getting 5.2v and when the reset happens it drops to 5.1. Now, the pic12f1840 data sheet says it will run down under 3 volts, so I don't understand what's causing the reset. I then left the circuit intact, relays attracted, but cut the power to the motor and just ran the pic circuit. This performed as expected and relay triggered and the correct voltages were switched. So I then ran the motor by connecting it directly to the battery ( motor cycle 12v) while the board was up and running and even that cause the pic to reset. This run is where I determined the 0.1 volt drop on the 5volt rail. The scope isn't showing a dirty power either. It's going to be something really silly !!!

Should a 0.1 volt drop cause the processor to reset, I don't think so, so now I'm stumped. Here's the config in case I'm missing something.. thanks in advance,

/* CONFIG1 */
#pragma config FOSC = INTOSC /* Oscillator Selection (INTOSC oscillator: I/O function on CLKIN pin) */
#pragma config WDTE = OFF /* Watchdog Timer Enable (WDT disabled) */
#pragma config PWRTE = OFF /* Power-up Timer Enable (PWRT disabled) */
#pragma config MCLRE = OFF /* MCLR Pin Function Select (MCLR/VPP pin function is MCLR) */
#pragma config CP = OFF /* Flash Program Memory Code Protection (Program memory code protection is disabled) */
#pragma config CPD = OFF /* Data Memory Code Protection (Data memory code protection is disabled) */
#pragma config BOREN = OFF /* Brown-out Reset Enable (Brown-out Reset disabled) */
#pragma config CLKOUTEN = OFF /* Clock Out Enable (CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin) */
#pragma config IESO = OFF /* Internal/External Switchover (Internal/External Switchover mode is disabled) */
#pragma config FCMEN = OFF /* Fail-Safe Clock Monitor Enable (Fail-Safe Clock Monitor is disabled) */

/* CONFIG2 */
#pragma config WRT = OFF /* Flash Memory Self-Write Protection (Write protection off) */
#pragma config PLLEN = OFF /* PLL Enable (4x PLL disabled) */
#pragma config STVREN = ON /* Stack Overflow/Underflow Reset Enable (Stack Overflow or Underflow will cause a Reset) */
#pragma config BORV = LO /* Brown-out Reset Voltage Selection (Brown-out Reset Voltage (Vbor), low trip point selected.) */
#pragma config LVP = OFF /* Low-Voltage Programming Enable (High-voltage on MCLR/VPP must be used for programming) */
Hi

1. I think you want MCLR = ON, so that the pin functions as a "reset" pin and is pulled up internally to VDD. A switch closure to ground will hold the PIC in reset. However, I would connect a 0.1uF cap and 10k resistor in series, cap to ground, resistor to +5, junction to reset pin and switch, to ensure noise doesn't trigger a reset when the switch is open.
2. Why are you using the reset pin as an on/off control? I guess I don't understand how that pin is being used.
3. Move the LED's to the collector of the corresponding NPN transistor, so current draw is thru the transistor instead of the PIC pins.
4. Place the 0.1uF cap across the VDD and VSS pins, It helps keeps noise out of the PIC supply pins.
5. Don't leave out the diodes mentioned in post #6.
6. Where is +5 volt supply coming from?
 
Last edited:

Thread Starter

Hoylegj

Joined Mar 10, 2016
26
Hi

1. I think you want MCLR = ON, so that the pin functions as a "reset" pin and is pulled up internally to VDD. A switch closure to ground will hold the PIC in reset. However, I would connect a 0.1uF cap and 10k resistor in series, cap to ground, resistor to +5, junction to reset pin and switch, to ensure noise doesn't trigger a reset when the switch is open.
2. Why are you using the reset pin as an on/off control? I guess I don't understand how that pin is being used.
3. Move the LED's to the collector of the corresponding NPN transistor, so current draw is thru the transistor instead of the PIC pins.
4. Place the 0.1uF cap across the VDD and VSS pins, It helps keeps noise out of the PIC supply pins.
5. Don't leave out the diodes mentioned in post #6.
6. Where is +5 volt supply coming from?
Thanks eetech, I will change a few bits as you say. Pin 1 was used because other pins were driving other features not shown. But I will try changing its use. Power supply is a 12 to 5v shop purchased regulator. See pic above. You make good points so I will rework and post my findings. Thank you.
 

Thread Starter

Hoylegj

Joined Mar 10, 2016
26
Thanks everyone for your comments, thought I'd post a update.
1) I tried caps as suggested, without any joy. So I then found the were not any caps on the motor I was using, so added caps there (3). Still no joy. So I'm now thinking if a relay or my PCB is causing it.
2) I thought I would take it back to a bread board, I did this and also used a mosfet instead of relays and it works now without resets, I'm waiting on a 'n' mosfet so I can change it to a 'H' bridge. Still have all the caps in place and will leave them now.
3) Will test the relays option on the bread board out of interest over the next few days
4) Will make a new PCB Version in the coming week with 'H' bridge mosfet's

again, thanks
 

WBahn

Joined Mar 31, 2012
24,974
Did you put in the external pullup resistor on MCLR that was suggested? You might even make it stronger and use a 1 kΩ resistor since it will only draw current when you are actively resetting the PIC.
 

Thread Starter

Hoylegj

Joined Mar 10, 2016
26
Did you put in the external pullup resistor on MCLR that was suggested? You might even make it stronger and use a 1 kΩ resistor since it will only draw current when you are actively resetting the PIC.
to be honest no forgot to try that, I test that as well. thanks
 

GopherT

Joined Nov 23, 2012
8,012
to be honest no forgot to try that, I test that as well. thanks
The 1k resistor from MCLR to 5V is critical. All other efforts are a wast of time until that is done. Right now MCLR is floating and essentially looks like one end of a capacitor connected to the MCLR input and the other acting like an antenna - ant static can cause your chip to reset.
 
Top