PDA

View Full Version : Random output upon TRISIO setup on '683



picster
- 2nd July 2009, 15:48
I'm getting random outputs on a GPIO after setting TRISIO on a 12F6883 PIC. Sometimes it initializes as a 0, other times as a 1.

Is there any way, other than setting it AFTER the fact, in ensuring it comes up in one state or the other? I don't want the initial pulse either, if I need to set it after the fact.

Thanks,

picster

sinoteq
- 2nd July 2009, 18:09
Hi
Let's say you want the PIC to start with all pins in a predefined state. The TRISIO reg is always set as inport at Power on Reset and Brown out Reset (datasheet page 10) so.....

1 Design the your hardware with 4.7k to 10k pull-down resistors on all IOs that you want to start with LOW level and put pull-up on all IOs that you want to start with High level. Because the TRISIO is set to %111111 all IOs at startup are inports and very high impedance. With no resistors they are floating and that is bad.

2 Set the GPIO reg to correct settings

3 Kick the TRISIO reg to make the pins in/outputs as your like.

This way the pic will start same every time and there are no extra pulses anywhere. The resistor values can differ from design to design but they are a good start.

picster
- 3rd July 2009, 13:51
I'll give writing to it,THEN setting TRISIO a try... I tried modifying TRISIO within the program previously and it gave me an error at compile time - I'm not sure why.

The high impedance state shouldn't have mattered for me - I was driving a reed relay (diode protected) with an active high, so it should have acted like a pull-down resistor at power-up time.

picster

Acetronics2
- 3rd July 2009, 14:00
Hi,

You will always have random OUTPUT state at power on ...

So, just Write

GPIO = % xxxxxxxx

BEFORE setting your Tris Register ...

and do not forget your inputs will be floating for some ms at startup ( hardware pull up or down resistors to place, i.e. when driving Mosfets ...)

Alain

EDIT : +1 with Sinoteq, then !!!

picster
- 6th July 2009, 13:34
Thanks guys, it worked like a charm. I'll have to add that to the mental archives for a standard approach.

picster