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

Wierd port C behavior

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







Wierd port C behavior
PostPosted: Fri Jan 30, 2004 4:08 am     Reply with quote

Something funny is happening with my portc on a 16f876.

Using output_c(0xff) all the pins go high.
When I use output_high(PIN_C0) C0 goes high as expected.
When I use output_high(PIN_C0) followed by output_high(C1) only c1 goes high.

Any ideas? Nothing else exists in the program, just those lines mentioned above in main. I tried turning off ccp1, ccp2, and timer1 but result is the same.
Guest








PostPosted: Fri Jan 30, 2004 4:35 am     Reply with quote

Hello

I had this problem on a PIC12F675. I disabled the comparator module completely, and everything worked fine. I don't remember if the 876 has comparators. I it hasn't, there is maybe another hardware module at this pin.

mfg
Felix
Guest
Guest







PostPosted: Fri Jan 30, 2004 4:42 am     Reply with quote

Felix,

Good guess but that isn't the problem. The analog stuff on a 876 is on portA. The only thing on c0 and c1 is timer1 and ccp2 respectively, of which I have already tried manually disabling.

I have a feeling port c may need some special sort of initalizing when not using the TRIS command. I did some quick and dirty assembly as suggested by someone..

Code:

processor 16f876
#include <p16f876.inc>
__config _HS_OSC & _WDT_OFF & _PWRTE_ON

movlw B'00000000'
tris PORTA
tris PORTB
tris PORTC

main:

bsf PORTC, 0
bsf PORTC, 1
bsf PORTC, 2
bsf PORTC, 3
bsf PORTC, 4
bsf PORTC, 5
bsf PORTC, 6
bsf PORTC, 7
goto main

END


And I was able to see c0 and c1 on simultaniously.
Ttelmah
Guest







Re: Wierd port C behavior
PostPosted: Fri Jan 30, 2004 5:49 am     Reply with quote

Guest wrote:
Something funny is happening with my portc on a 16f876.

Using output_c(0xff) all the pins go high.
When I use output_high(PIN_C0) C0 goes high as expected.
When I use output_high(PIN_C0) followed by output_high(C1) only c1 goes high.

Any ideas? Nothing else exists in the program, just those lines mentioned above in main. I tried turning off ccp1, ccp2, and timer1 but result is the same.

If your two lines are immediately after one another, this may be the 'read modify write' problem.
Basically, when you do a 'output_high(bit)' function, the chip reads the current pin values, and sets the requested bit. Now if you perform 'output_high(PIN_C1)', if there is a reasonable load, and especially significant capacitance on the pin, it may take a few uSec, to actually go 'high'. So if the very next instruction, is another bit 'output', the port is read, and at this point, pin_c1, is not yet high. So the bit is read as a '0', and gets output as a 0...
Hence:

output_high(PIN_C1);
delay_us(1);
output_high(PIN_C0);

with the delay dependant on the capacitance present on the pin, may be necessary to perform this operation.
There is significant documentation about this behaviour on the MicroChip site.

Best Wishes
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jan 30, 2004 5:41 pm     Reply with quote

I tested the following program with PCM vs. 3.184, and it
works OK. Both pins C0 and C1 are set high, as observed
with an oscilloscope.

#include "16F877.h"
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 4000000)

main()
{

output_high(PIN_C0);

output_high(PIN_C1);

while(1);
}
Guest








PostPosted: Fri Jan 30, 2004 6:58 pm     Reply with quote

Thanks for letting me know about the read-modify-write issue.

Although, I don't think timing was my issue as observed by the following code that didn't work:

output_high(PIN_C1);
delay_ms(1000);
output_high(PIN_C0);

Only C0 remained lit (I had small leds directly connected to each pin). I rememberd the mention of current draw in the microchip website, so I added limiting resistors in series with each led (even though I know the leds weren't drawing more then the rated current per pin), and the above code worked even without the delay (@20mhz).

So I guess drawing too much current (or too fast) from any port pin, even if the others are stable, will lead to issues. Well, you learn something new every day.
Charlie U



Joined: 09 Sep 2003
Posts: 183
Location: Somewhere under water in the Great Lakes

View user's profile Send private message

Predictable Port C Behavior
PostPosted: Fri Jan 30, 2004 9:59 pm     Reply with quote

Now that we know "the rest of the story" it is fairly easy to surmise that, indeed you _are_ seeing a "read-modify-write" problem. The "small" LEDs that you had on the port pins, without current limiting resistors, were limiting the output voltage to somewhere between 2 and 3 volts, because they are diodes. The inputs to port C are Schmitt triggers and require 0.8 x VDD to be high, which is 4 VDC in a 5 volt system. Therefor, even though you have set the outputs to a high state, the output drivers can not pull the outputs above the diode operating voltage of 3 volts max (estimated), which is below the input threshold of 4 volts, the pins will be read as a 0 during the read modify write action of the bit set, and driven back as a 0.
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