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

Testing Output

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



Joined: 03 Dec 2005
Posts: 182
Location: Australia SA

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

Testing Output
PostPosted: Mon Jan 09, 2006 5:31 am     Reply with quote

Hi,
If I set an output high, How can I test the to see if the putput is high with C.

Any assistance will be greatly appriciated. Confused


Andrew
_________________
What has been learnt if you make the same mistake? Wink
Guest








PostPosted: Mon Jan 09, 2006 7:00 am     Reply with quote

Use input() function (see p119of October 05 manual - pdf file available on website)
e.g.
Code:
if( input(PIN_A0) )
printf("A0 is now high\r\n");
Ttelmah
Guest







PostPosted: Mon Jan 09, 2006 7:47 am     Reply with quote

The only problem with this, is that if using standard_IO, the compiler will switch the pin to being an input, when this is executed. You will know it was 'high' when read, but it may well no longer be so. The answer is to directly read the input latch instead, or to use fixed/fast I/O.
So, if using standard_IO, on a 18F PIC:
Code:


#byte INPUT_LATCH = 0xF80
#bit A0 = INPUT_LATCH.0

output_high (PIN_A0);
//This sets the pin as an output, and drives this high
while (A0==0) {
   //waiting here for the pin to go high
   //I'd suggest havin a counter, and a 'error' timeout
   //If is not high in a few counts
}

//Here the pin is high



Best Wishes
Storic



Joined: 03 Dec 2005
Posts: 182
Location: Australia SA

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

PostPosted: Mon Jan 09, 2006 12:40 pm     Reply with quote

Thaks
_________________
What has been learnt if you make the same mistake? Wink
asmallri



Joined: 12 Aug 2004
Posts: 1634
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

Re: Testing Output
PostPosted: Mon Jan 09, 2006 7:42 pm     Reply with quote

Storic wrote:
Hi,
If I set an output high, How can I test the to see if the putput is high with C.

Any assistance will be greatly appriciated. Confused


Andrew


You think your confused now...

This depends on the load on the PIC's output pin. It is possible for you the set the ouput high, the PIC to drive the output high accordinging but if you "read" the (loaded) pin you will see it as low. Also you have to take into account the type of input. You might be driving a load which includes a CMOS level device but the PIC may have a TTL input stage. This means that what the PIC reads as an input does not agree with what the external device sees.
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
kender



Joined: 09 Aug 2004
Posts: 768
Location: Silicon Valley

View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger

Spare $0.02 ?
PostPosted: Mon Jan 09, 2006 8:10 pm     Reply with quote

I'm simply curious, why would you need this feedback? The the time the line of C code output_high(PIN_A0); is executed, the pin is pretty much guaranteed to be high, unless the load connected to the pin is sinking more current then PIC can provide. Are you building, essentially, a 20mA fuse?
rnielsen



Joined: 23 Sep 2003
Posts: 852
Location: Utah

View user's profile Send private message

PostPosted: Wed Jan 11, 2006 9:25 am     Reply with quote

Quote:
I'm simply curious, why would you need this feedback?


I've needed to output a partial word to a port and didn't want to change the status of any of the other pins on the same port. I would read the status of those pins and then include that data in the word when I sent it to the port.

Ronald
asmallri



Joined: 12 Aug 2004
Posts: 1634
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Wed Jan 11, 2006 7:39 pm     Reply with quote

rnielsen wrote:
Quote:
I'm simply curious, why would you need this feedback?


I've needed to output a partial word to a port and didn't want to change the status of any of the other pins on the same port. I would read the status of those pins and then include that data in the word when I sent it to the port.

Ronald


In that case you want to read the output latch (as opposed to the input latch), make your changes and write back out to the output latch. That assumes you are using a PIC (such as the PIC18F family) that has output latches. You can also use bit_set and bit_clear on the output latch.

If you are using a 16F series pic without output latches then you have a problem due to the pin load as previously discussed. To handle this you could implement your own port mirror byte. Whenever you want to write to the port you first write / modify the mirror byte the write the contents of the mirror byte to the port. This solution allows you to use bit_set and bit_clear on the mirror byte.
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
Storic



Joined: 03 Dec 2005
Posts: 182
Location: Australia SA

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

PostPosted: Sat Feb 04, 2006 6:28 am     Reply with quote

I used the code as below
Code:
#byte OP_LATCH = 0xF81 // PORT B; PORT A = 0xF80
#bit OUT1 = OP_LATCH.2
#bit OUT2 = OP_LATCH.3
#bit OUT3 = OP_LATCH.0
#bit OUT4 = OP_LATCH.5


and the test is
Code:
    if (OUT1==0) E_Flag1 = 1; else E_Flag1 = 0;
    if (OUT2==0) E_Flag2 = 1; else E_Flag2 = 0;
    if (OUT3==0) E_Flag3 = 1; else E_Flag3 = 0;
    if (OUT4==0) E_Flag4 = 1; else E_Flag4 = 0;


thanks again (it took a while to understand the op_latch = 0xf80, I found the answer in the debug viewing the IO PORTS, this is where I found Port B = 0xF81.)

Andrew
_________________
What has been learnt if you make the same mistake? Wink
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