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

output to port functions

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



Joined: 24 Mar 2011
Posts: 5

View user's profile Send private message

output to port functions
PostPosted: Thu Mar 24, 2011 8:51 am     Reply with quote

Hi, I am using compiler version 4.064 and I tested out these two functions and used LED's to test the following two commands: the CCS compiler built-in function: "output_high(PIN_D7); "

and the outputting it myself using: "output_d(0b10000000);"

I realize that you would also have to specify the address for the port D if you implement it my way so at the top of your code you'd have to say:

#byte port_d = 0x08

So what I wanted to know is, besides the one difference I mentioned above, does the built-in function that CCS provides do or set any other things in the PIC? basically what would be the exact difference between these two statements? I looked at the CCS compiler built-in functions manual and it doesn't seem to give any information on the actual code for how they implemented the built-in function.

Also, my implementation requires writing to the entire port everytime. So, I was wondering when using the built-in function, if you want to set a certain pin high for example, pin 3, does it write to ALL the pins in the port? so for example, would it do: 00000100? or does it put the value 1 in pin3 w/o writing to any of the other pins? Also, when using this in-built function, if you write to the same port sucessively, for example:





Code:
   //case where you are below the middle threshold of tank
      while(ADC_threshold(THRESHOLDMID) == 0 && Rising == 1){
         output_high(PIN_D5); //turn on led 3 at pin RD5
         output_low(PIN_C1); //disable transmitter
         output_high(PIN_C2); //PortCBits2 = 1; disables sensor
      }


In the code above, since I write to PINC1 and C2 which are on the same port C of the PIC, right after each other, sometimes I don't see them implemented correctly when I hook up LED's to the corresopnding pins to debug. Is this because when using the built-in function, does it take some time to write to the port? So should I include a delay between each write? For some reason when i do this:

Code:
   //case where you are below the middle threshold of tank
      while(ADC_threshold(THRESHOLDMID) == 0 && Rising == 1){
         output_high(PIN_D5); //turn on led 3 at pin RD5
         output_low(PIN_C1); //disable transmitter
                        delay_ms(500); //put in delay too allow time to write to pin
         output_high(PIN_C2); //PortCBits2 = 1; disables sensor
      }


the code works fine, but I have some timing issues that cause problems when I put a delay in there. Is there anyway to make this work without having to use a delay?
Ttelmah



Joined: 11 Mar 2010
Posts: 19366

View user's profile Send private message

PostPosted: Thu Mar 24, 2011 9:31 am     Reply with quote

No, you don't need to have #byte port_d = 0x8.
The output_d instruction knows where port_d is.

Now. your problem sounds like RMW. A search here and generally regarding the PIC, for this will find a lot about it. When you set (or clear) one bit in a port on the PIC, the sequence _performed by the hardware_, is:

Read the current value on the port.
Set/reset the one bit requested.
Output this to the port.

Now, the problem appears if you have an output bit that is overloaded. If (for example), you turn on A0, and this is connected to a load that does not allow it to reach the voltage corresponding to a '1', then you set A1. When A0 is read, the chip sees the pin as being 'low' (since it is not at the high logic level), and clears it.....

Solutions:
First one is avoid overloading the pins. Now you talk about attaching LED's, what resistor value are you using to limit the current these draw?. Typically 270 or 330 ohms are needed. Otherwise the pins will be clamped to the LED Vf, and never go 'high'.....
Second, is when dealing with a _capacitive_ load, adding time delays. Here the pin may take a few uSec to actually reach the required level.

The 'RMW', stands for 'Read Modify Write', which is what the chip internally does when you set/reset one bit.

On later chips (18 family), the 'output register' is a separate register from the port itself, which avoids this problem if changing several pins quickly, with capacitive loads. However in the 'overloaded' version of the problem, if the chip is not to overheat, the hardware needs to be modified to avoid it.

Best Wishes
boogajamooga



Joined: 24 Mar 2011
Posts: 5

View user's profile Send private message

PostPosted: Thu Mar 24, 2011 12:34 pm     Reply with quote

wow thanks! the resistors were the problem.
temtronic



Joined: 01 Jul 2010
Posts: 9173
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Mar 24, 2011 2:24 pm     Reply with quote

Also to see what CCS is doing for their functions, just print out the program.lst file. It'll give you all the information you need, probably more !
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