PDA

View Full Version : Power up reset



ShawnB
- 24th November 2009, 14:16
Hello,

I am programing a PIC16F886 with inputs on Ports A and C, and outputs on Port B. I am trying to figure out how to keep the output form going high during power up. I have found in the PIC data sheets where it talks about the different resets; Power-On, MCLR, BOR, etc. Which you can set using register CONFIG1 and CONFIG2. I have not been able determine how to set these using software; though I have tried to set them using MPLAB under the configure menu. I have enabled MCLR, BOR, and Time-ON Delay, but the output still ramdomly turn on.

Could I get some recommendations as to how to keep the output low during power-up?

Thanks,
Shawn

Acetronics2
- 24th November 2009, 14:37
Hi,

During power up ...

all pins are INPUTS ( say floating ! ) ... till you turn them to outputs.

So ...

1) place some pullup or pulldown ( to suit your application ) resistors to fix the outputs ( may be inputs too, depends on circuitry ahead ... ) levels while they are " uncontrolled "

2) program output and input levels required ( PORTx = % 11001010 i.e )

3) THEN program inputs and outputs ( TRISx = % 00110110 i.e )

This way ... outputs are fully under control ... Even if Pic is taken off from its socket !!!


Alain

ShawnB
- 24th November 2009, 16:17
Hi Acetronics,

My current port configuration setup:

'*** PIC16F886 CONFIGURATION *************************

OSCCON = %01100000

ANSEL = %00000011
TRISA = %11111111

ANSELH = %00000000
TRISB = %00000000

TRISC = %11111111

So I should look at adding PORTx = 0 before the TRISx register to clear the port register?

Is this good programming practice (newbe question)?

I have pull-down resistors on the input but not on the outputs, so I can look at adding those.

ErnieM
- 24th November 2009, 17:17
So I should look at adding PORTx = 0 before the TRISx register to clear the port register?

Is this good programming practice (newbe question)?

I have pull-down resistors on the input but not on the outputs, so I can look at adding those.

By all means clear the ports before changing TRISx. The MC data sheet on this part defines the port pins as UNDEFINED after power-up.

It is definitely good programming practice, even on parts where the data sheet says the pins should be in the state you think you want.

Output pull downs are probably the way to go, just make sure you have enough current to drive them, and they take enough current to actually pull down the input they drive.

Acetronics2
- 24th November 2009, 18:00
So I should look at adding PORTx = 0 before the TRISx register to clear the port register?

Is this good programming practice (newbe question)?

I have pull-down resistors on the input but not on the outputs, so I can look at adding those.

Hi, Shawn

Clearing PORTx is not the way ...

but you must set PORTx to get a SAFE and KNOWN state at your Program start ...

so, if you have a PNP transistor driving something ... it's driving port initial state MUST be a "1" state with a Pullup resistor ... for the transistor NOT to conduct.

I already had the "gag" with an electronic ignition :

@ Power UP the guy had programmed a CLEAR Port.

and after he had preset the Port pin to 1 ... as the transistor driven was a PNP ...


so, When turning the contact Key ... often an explosion occured in a cylinder : not so good , hey ???

The Good practice is to ensure a SAFE initial state ... processor placed or not.

Alain

ShawnB
- 25th November 2009, 18:02
Acetronics,

I made the changes you recommended and that appears to have corrected the problem.

I do have a questions regarding how the MCLR and BOR fuction work. If either or both are enabled, what happens on power-on? In the data sheets it appears to me that it sets all the ports to 0. Where on a power-on leaves the ports unchanged. Does one have priority over the others or are there all reseting at the same time?

Thanks,
Shawn

Acetronics2
- 25th November 2009, 19:52
Hi, Shawn

MCLR is the " Manual reset " pin

BOR is the " Voltage Supply weakness " reset ... to avoid unwanted behaviour.


Now ...

MCLR has "absolute priority" over everything ...


Remember all ports are left inputs @ Power-Up and nothing is sure until you write what you want to get ...

Alain