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

Timing issue

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



Joined: 11 Nov 2008
Posts: 24

View user's profile Send private message Send e-mail Yahoo Messenger MSN Messenger

Timing issue
PostPosted: Thu Mar 05, 2009 2:54 am     Reply with quote

i wanted to read a pin's state.

1.
Code:
current_bit = PORTB

read all the bits and evaluate PIN_B0 (believe this is do faster reading)

or

2.
Code:
current_bit = input(PIN_B0)


i worry about the time may taken by input(PIN_XX) statement. So which is the registry hold the value for each pin?

Thanks in advance
Ttelmah
Guest







PostPosted: Thu Mar 05, 2009 3:26 am     Reply with quote

Three different things here:

First, the internal input and output functions, whether for a bit, or a whole port byte, have two basically different modes of operation, according to whether FAST_IO is selected. If this is selected, then these functions operate _exactly the same_ as doing direct bit/byte I/O on the port. If not, extra instructions are added to automatically update the TRIS register. This latter is convenient, since it avoids TRIS errors (probably the commonest thing to get set wrong on a PIC), _but_ at a cost in speed.

Second, if FAST_IO is enabled, and you do a direct bit read or set, using:
Code:

current_bit = input(PIN_B0);

//or

output_high(PIN_B0);

Then the output evaluates to just a single machine instruction - no faster possible, while the input will take just one two instructions (but three instruction cycles) to read the bit, and set the bit/byte in the result. Again as efficient as possible.

Third option, manually doing this. A shown here, if you actually want a 'bit', then this is by far the least efficient, since it'll take as many instructions to read the byte as reading and testing the bit, and then you still have to test the bit as more instructions....

If you want to leave the port with automatic I/O selection (and not set FAST_IO), but override this to do a single bit access, then the fastest route, is:
Code:

//Assuming you have PORTB already defined

#bit MyB0=PORTB.0

current_bit=MyB0;

This will do the same as the input(PIN_B0) instruction, but will not affect the TRIS, whether or not FAST_IO is selected.

Best Wishes
viknes1985



Joined: 11 Nov 2008
Posts: 24

View user's profile Send private message Send e-mail Yahoo Messenger MSN Messenger

thanks
PostPosted: Thu Mar 05, 2009 4:01 am     Reply with quote

thanks for the quick reply Ttelmah.
viknes1985



Joined: 11 Nov 2008
Posts: 24

View user's profile Send private message Send e-mail Yahoo Messenger MSN Messenger

i'm using int_rb
PostPosted: Mon Mar 09, 2009 9:58 am     Reply with quote

Hi Ttelmah,

I tried as you said, but the bit is always high.

Clarification :

I'm using int_rb to detect the changes in B4 (PIN_B4), so I used set_tris(0x10);

Basically I want to get the bit, which cause the interrupt.

If I never set tris, how do the PIC knows that I'm using B4 as input. Any suggestion?


Thanks in advance
viknes1985



Joined: 11 Nov 2008
Posts: 24

View user's profile Send private message Send e-mail Yahoo Messenger MSN Messenger

read the pulse status
PostPosted: Mon Mar 09, 2009 10:49 am     Reply with quote

Using interrupt coz alot of problem, using fast i/o solved the problem....

Last edited by viknes1985 on Fri Mar 20, 2009 12:31 pm; edited 1 time in total
Ttelmah
Guest







PostPosted: Mon Mar 09, 2009 11:19 am     Reply with quote

A couple of comments.
First, you enable the global interrupt, but never enable INT_RB....

Then, you are clearing RBIF in the interrupt. This is a waste of time. The compiler already does this for you, unless you add the 'NOCLEAR' directive to the interrupt declaration.

Then, you don't declare FAST_IO, and you perform an output_low instruction, TRIS will be being updated for you. Do you want this?.

You are also using the flex LCD driver. What does this say about TRIS?. Would it support using fast_io?. Does it update TRIS?.

Best Wishes
viknes1985



Joined: 11 Nov 2008
Posts: 24

View user's profile Send private message Send e-mail Yahoo Messenger MSN Messenger

enabling is seems to ok
PostPosted: Mon Mar 09, 2009 12:37 pm     Reply with quote

Hi Ttelmah,

i'm using RBIE
Code:
#byte INTCON = 0x00B
#bit  RBIE = INTCON.3   //int_rb enable/disable

do i still need to enable INT_RB in main? as you may see, i enabling the interrupt only at certain times.

output_low()... is just connected to LED to get to know when it's passed the programming code...

i got flex_lcd.c from code library in this forum, uploaded by PCM programmer(thanks to him). I just go through it, no function interfere with other ports. I'm using only port D as output to LCD.
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