Microchip Technology
Welcome to www.microchip.com
Search: Click here to Search Microchip.com
Forums Home Register LoginLog Out Inbox Address Book My Subscription Member List Search My Profile FAQ
I/O port quirks

I/O port quirks

 
View related threads: (in this forum | in all forums)

Logged in as: Guest
Users viewing this topic: none
  Printable Version
All Forums >> [Microcontroller Discussion Group] >> Digital I/O Ports >> I/O port quirks Page: [1]
Login
Message << Older Topic   Newer Topic >>
I/O port quirks - Jul. 13, 2006 4:49:27 PM   
slavka013

 

Posts: 49
Joined: Nov. 7, 2003
Status: offline
I have discovered strange behaviour on PIC18F2455. One of the output I/O ports was connected to a load that dropped voltage on the i/o pin down to around 3V (VCC = 5V). Under these cismumstance the program could not set the pin into high state. Whe the program ran freely the instruction

bsf PORTC, 1

was apparently ignored. Of course, TRIS bit was cleared and all peripherals using RC1 was disabled.

However if I set a breakpoint on this instruction and single stepped through it (I was using ICD2) then the pin was indeed set to high state, and remained high if I continued to run the program after that. Direct manipulation of the bit while the program was halted also worked fine.

I already resolved the issue, however having spent few hours tracing it I would like to hear some comments as to why it works that way.

Thanks!
Post #: 1
RE: I/O port quirks - Jul. 13, 2006 5:24:12 PM   
bob_barr
5+ years with MCHP products

 

Posts: 5416
Joined: Nov. 7, 2003
From: Morgan Hill, CA
Status: offline
Are you doing any other 'bsf' instructions to the PORTC register? If so, you may be seeing a read-modify-write problem, especially with that pin being so heavily loaded.

In 18F chips, you can avoid r-m-w problems completely by performing any 'bsf' and 'bcf' instructions to the LATC register rather than the PORTC register. The LATC contents will always reflect the last value written to the port rather than whatever happens to be read on the pins when the instruction executes.

<added
I should have included this:

An R-M-W problem on a pin doesn't occur when you perform a 'bcf' or 'bsf' on that pin. It occurs when you perform any instruction that reads the port, modifies some other bit, and then writes the whole byte back to the port. If that read happens before the pin you've just set has reached a high enough voltage level, the pin you've just set will be written back to a zero.

R-M-W issues aren't only caused by 'bsf' and 'bcf' instructions. Logical operations such as 'andwf', 'iorwf', and 'xorwf' can trigger this behavior as well.
/added>

< Message edited by bob_barr -- Jul. 13, 2006 6:07:18 PM >


_____________________________

While it's always good to learn from one's mistakes, it's much easier to learn from the mistakes of others.
Please don't PM me with technical questions. I'll be quite happy to help (if I can) on the forums.

(in reply to slavka013)
Post #: 2
RE: I/O port quirks - Jul. 13, 2006 5:37:50 PM   
slavka013

 

Posts: 49
Joined: Nov. 7, 2003
Status: offline
Yes, I'm aware of the read-modify-write isuue, it's not the case here. When program was freely runinng the pin did not switch into high state, I was monitoring it using logic analyzer.

What I can't understand is difference between single stepping and normal execution of the program....

(in reply to bob_barr)
Post #: 3
RE: I/O port quirks - Jul. 13, 2006 5:54:45 PM   
bob_barr
5+ years with MCHP products

 

Posts: 5416
Joined: Nov. 7, 2003
From: Morgan Hill, CA
Status: offline
Probably the most common reason for programs to act differently between single-stepping and normal execution is that, while single-stepping, the I/O pins have sufficient time between instructions to reach their final states. This frequently masks R-M-W problems that only appear when the program is run at full speed.

I'd still suggest performing any 'bsf' and 'bcf' instructions for I/O port pins to the LATx register rather than the PORTx register. Doing that guarantees that you won't have any R-M-W issues.

_____________________________

While it's always good to learn from one's mistakes, it's much easier to learn from the mistakes of others.
Please don't PM me with technical questions. I'll be quite happy to help (if I can) on the forums.

(in reply to slavka013)
Post #: 4
RE: I/O port quirks - Jul. 13, 2006 8:42:40 PM   
Prince
Experienced Hobbyist

 

Posts: 364
Joined: Nov. 21, 2005
Status: offline
So you have set up a lab cercumstance? Such as a test snippet? Of course you have. 

bsf PORTC, 1 ; This is suppost to be 1 and not 0, right?
idle_loop:
goto idle_loop


_____________________________

ETA - Certified Student Electronics Technician
Experience In 12F, 16F, 18F, and 30F
while (alive > 0)
{
  HandleLife();
  Intelligence++;
}

(in reply to bob_barr)
Post #: 5
RE: I/O port quirks - Jul. 13, 2006 9:05:36 PM   
bob_barr
5+ years with MCHP products

 

Posts: 5416
Joined: Nov. 7, 2003
From: Morgan Hill, CA
Status: offline
Here's a scope picture that I took of a PIC 18F4550 output being turned on. The pin has a capacitive load.

Notice that for much of the first 10 uS (that's a LOT of instruction times) after the pin is switched to a high, its voltage has barely risen toward a volt. Any port modification instruction (bcf, bsf, andwf, iorwf, xorwf) that's executed during that time will read the pin back as a zero. When the instruction writes the modified value back, this bit will be written back to a zero.

<added
clarified wording
/added>



Thumbnail Image


Attachment (1)

< Message edited by bob_barr -- Jul. 13, 2006 9:06:50 PM >


_____________________________

While it's always good to learn from one's mistakes, it's much easier to learn from the mistakes of others.
Please don't PM me with technical questions. I'll be quite happy to help (if I can) on the forums.

(in reply to Prince)
Post #: 6
RE: I/O port quirks - Jul. 18, 2006 2:44:18 AM   
Guest
hi i am experincing the same problem regarding a lower voltage when it should be giving 5V. I try the method you all have recommended but still i got the same problem the MCU i used is PIC18F8722 and i am using the Development board from MCU. So i assume the board should be working fine (I did some testing on it).



(in reply to bob_barr)
  Post #: 7
RE: I/O port quirks - Jul. 26, 2006 4:58:00 PM   
davidcary

 

Posts: 36
Joined: Sep. 12, 2005
Status: offline
Nice photo, bob_barr.

The RMW problem is unfortunately extrememly common.

I've started to point people towards the PICList FAQ at
http://massmind.org/techref/readmodwrite.htm
.
Does that cover it, or is there anything else I should add / anything confusing I need to take out?

(in reply to bob_barr)
Post #: 8
Page:   [1]
All Forums >> [Microcontroller Discussion Group] >> Digital I/O Ports >> I/O port quirks Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts


  Site Index  |  Legal Information  |  microchipDIRECT  |  Samples  |  Technical Support  |  Investor Information  |  Careers at Microchip  |  Contact Us  |  RSS Feeds ©2009 Microchip Technology Inc.  
  Shanghai ICP Recordal No.09049794  
Forum Software © ASPPlayground.NET Advanced Edition 2.5.5 Unicode

0.172