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 support@ccsinfo.com

What's the fastest speed possible to switch output ports?

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



Joined: 21 Nov 2006
Posts: 129

View user's profile Send private message

What's the fastest speed possible to switch output ports?
PostPosted: Sat May 12, 2007 7:56 pm     Reply with quote

I'm using a 16F684 at 8mHz internal clock speed to manage incoming and outgoing communications between 3 different RS-232 devices.

I haven't done the math for what would be possible if the ports could switch at the same speed as the clock speed. Before I do that, I'd like to know, what's the fastest that the output ports can be switched? Is it as fast as the clock is running, plus some overhead time for the processor to execute the commands?

The fastest communications I can get are 9600 baud. Shouldn't I be able to get faster than that? Here's the while loop I'm performing everything in so you can see how I'm doing things:

Code:
while(TRUE) {
          restart_wdt();
         
          mode = 0x00;
         
          shift_left(&mode,1,input(S1)); // comm select line 1
          shift_left(&mode,1,input(S0)); // comm select line 2

          if(mode==0b00000000) {
               if(input(Tx1)) {
                    output_high(Rx2);
                    output_high(Rx3);
               }
               else {
                    output_low(Rx2);
                    output_low(Rx3);
               }
               
               if(input(Tx2) && (input(Tx3) || Tx3_inactive)) output_high(Rx1);
               else output_low(Rx1);
          }
          else if(mode==0b00000001) {
               if(input(Tx1)) output_high(Rx2);
               else output_low(Rx2);
               
               if(input(Tx2)) output_high(Rx1);
               else output_low(Rx1);
          }
          else if(mode==0b00000010) {
               if(input(Tx1)) output_high(Rx3);
               else output_low(Rx3);

               if(input(Tx3)) output_high(Rx1);
               else output_low(Rx1);
          }
          else {
               if(input(Tx2)) output_high(Rx3);
               else output_low(Rx3);

               if(input(Tx2) && (input(Tx3) || Tx3_inactive)) output_high(Rx1);
               else output_low(Rx1);
               
               if(input(Tx3)) output_high(Rx2);
               else output_low(Rx2);
          }
     }


Thanks in advance.
Steve H
Guest







PostPosted: Sat May 12, 2007 9:34 pm     Reply with quote

Depends...

If you just write a quick loop that toggles a pin - then it's fast. But who needs that? No we need and want code running too.

This is easy to figure out - each instruction takes one processor cycle (There are some exceptions - see the data sheet). One processor cycle is the clock divided by 4. Compile your program and look at the LST file - then just count the instructions.

Another thing I do is I have a quick demo board setup - so I can run code on actual hardware - toggle pins, etc. This makes it easy to measure timing with a scope, etc. all at a moments notice if need be.

HTH - Steve H.
Ttelmah
Guest







PostPosted: Sun May 13, 2007 3:12 am     Reply with quote

Add another 'key' factor to this.
The IO mode.
If you select 'standard_io' (the default), the compiler adds the extra instructions to select the IO direction, to every IO instruction. So, a command like:
Code:

output_high(PIN_A0);

is translated into a command to set TRISA bit0 to a zero, then set bit0 of PORTA to a 1.
However if you select 'fast_io', and then perform the same instruction, the extra TRIS control is not added (it is assumed that _you_ have already setup the TRIS register as you want), and the instruction just becomes the operation to set bit0 of PORTA.

Best Wishes
evsource



Joined: 21 Nov 2006
Posts: 129

View user's profile Send private message

PostPosted: Mon May 14, 2007 5:40 am     Reply with quote

Ttelmah wrote:
Add another 'key' factor to this.
The IO mode.
If you select 'standard_io' (the default), the compiler adds the extra instructions to select the IO direction, to every IO instruction. So, a command like:
Code:

output_high(PIN_A0);

is translated into a command to set TRISA bit0 to a zero, then set bit0 of PORTA to a 1.
However if you select 'fast_io', and then perform the same instruction, the extra TRIS control is not added (it is assumed that _you_ have already setup the TRIS register as you want), and the instruction just becomes the operation to set bit0 of PORTA.

Best Wishes


Ttelmah,

That's the sort of info. I was looking for! That certainly made the code size go down. I'll have to do some additional testing to see how much faster it actually made it.

Thanks.
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