CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Fastest way to set outputs to 0 on power up

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
dazlogan



Joined: 19 Oct 2003
Posts: 24
Location: Cambridge, UK

View user's profile Send private message Send e-mail

Fastest way to set outputs to 0 on power up
PostPosted: Mon Dec 08, 2003 1:08 pm     Reply with quote

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

View user's profile Send private message Send e-mail

PostPosted: Mon Dec 08, 2003 1:14 pm     Reply with quote

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

View user's profile Send private message Send e-mail

?
PostPosted: Mon Dec 08, 2003 1:22 pm     Reply with quote

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

View user's profile Send private message Send e-mail

PostPosted: Mon Dec 08, 2003 1:26 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Dec 08, 2003 2:12 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Dec 08, 2003 3:59 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Dec 08, 2003 4:00 pm     Reply with quote

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
PostPosted: Mon Dec 08, 2003 5:05 pm     Reply with quote

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

View user's profile Send private message Send e-mail

thanks!
PostPosted: Tue Dec 09, 2003 4:06 pm     Reply with quote

Thanks Hans and everyone else.

My problem is cured !. Most appreciated.

Regards,
Darren
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group