View previous topic :: View next topic |
Author |
Message |
dazlogan
Joined: 19 Oct 2003 Posts: 24 Location: Cambridge, UK
|
Fastest way to set outputs to 0 on power up |
Posted: Mon Dec 08, 2003 1:08 pm |
|
|
Hi everyone,
I need to set several outputs to 0 (low) on power up as an absolute priority. I am wondering - what is the fastest way of doing this in code please anyone?
Thanks
Regards,
Darren |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Mon Dec 08, 2003 1:14 pm |
|
|
Well, that depends. If it is an entire port, then just setting that port to 0 is fast. If setting only 1 output then setting that output to 0 is probably the fastest. If setting more than 1 output but less than 8, setting the port to a known state is fast or you can even 'AND' the port with a mask of 1's and 0's. |
|
|
dazlogan
Joined: 19 Oct 2003 Posts: 24 Location: Cambridge, UK
|
? |
Posted: Mon Dec 08, 2003 1:22 pm |
|
|
Hi Mark,
Thanks.
Let's say port_a, port_b and port_c all need to go low.
Being more specific - is it best to put something like:
main () {
output_a(0x00);
output_b(0x00);
output_c(0x00);
or is there a quicker way of doing it? |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Mon Dec 08, 2003 1:26 pm |
|
|
That's about the fastest way that I know. You can probably save a couple of instructions by using "fast_io" and setting the TRIS registers all at one time. |
|
|
Neutone
Joined: 08 Sep 2003 Posts: 839 Location: Houston
|
|
Posted: Mon Dec 08, 2003 2:12 pm |
|
|
Have a look at the datasheet and see what the powerup timer does. During powerup all port pins are inputs and a pull down resistor will keep you safe but thats a hardware fix. |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Mon Dec 08, 2003 3:59 pm |
|
|
By default the ports power up in tri-state. So if you put a pull down resistor on them they will power up in a low state before the processor even comes out of reset. They will stay low untill your code makes them otherwise. _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
Haplo
Joined: 06 Sep 2003 Posts: 659 Location: Sydney, Australia
|
|
Posted: Mon Dec 08, 2003 4:00 pm |
|
|
And as Neutone said all the ports are set to input on power-up, so before setting them to zero you have to configure them as outputs (if you are using #use fast_IO). |
|
|
Guest
|
Using code |
Posted: Mon Dec 08, 2003 5:05 pm |
|
|
Hardware is the best choice, however to make sure each port is LOW (or high as you please) Set the ouput before setting the TRIS .
This is about the fastest way I know, if Port A if more cirtical than Port C then output that first.
#use fast_io(a)
#use fast_io(b)
#use fast_io(c)
#byte portA = 0XF80 // for PIC18 series
#byte portB = 0XF81
#byte portC = 0XF82
#byte TRIS_A = 0XF92 // for PIC18 series
#byte TRIS_B = 0XF93
#byte TRIS_C = 0XF94
void main()
{
portA = portB = portC = 0; // set low before changing TRIS
TRIS_A = TRIS_B = TRIS_C = 0; // all outputs are low NO glitches
other code..
}
That's abut 600nS at 40MHz...
Here's the LST file for it.
.................... portA = 0;
0012: CLRF F80
.................... portB = 0;
0014: CLRF F81
.................... portC = 0; // set low before changing TRIS
0016: CLRF F82
.................... TRIS_A = 0;
0018: CLRF F92
.................... TRIS_B = 0;
001A: CLRF F93
.................... TRIS_C = 0; // all outputs are low NO glitches
001C: CLRF F94
hansw |
|
|
dazlogan
Joined: 19 Oct 2003 Posts: 24 Location: Cambridge, UK
|
thanks! |
Posted: Tue Dec 09, 2003 4:06 pm |
|
|
Thanks Hans and everyone else.
My problem is cured !. Most appreciated.
Regards,
Darren |
|
|
|