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

Pin_A4 not working reliably

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



Joined: 03 Apr 2005
Posts: 22
Location: Laguna Philippines

View user's profile Send private message Yahoo Messenger

Pin_A4 not working reliably
PostPosted: Fri Sep 04, 2009 6:04 am     Reply with quote

Hello All,

I observed with one of my design the PIN_A4 is not working reliably...
Sometimes the system hangs-up after several days.

Code:

//MCU config---
#include <16F876A.h>                     //PIC16F76A MCU used
#device icd =true                       //Enable debugger
#device *=16                            //Enable 16bit wide RAM pointer
#fuses HS, NOWDT, NOPROTECT, NOLVP      //MCU configuration
#ocs 10 Mhz                             //Crystal oscillator used @10Mhz
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

...............

//MCU init...
setup_adc_ports(NO_ANALOGS);
.......

//portion of the program
If (!input(PIN_A4))
             do_something():


Portion of the circuit:
[img][/img]

Compiler Version 4.093
Pls help..


Last edited by jelodavid on Fri Sep 04, 2009 10:45 am; edited 1 time in total
mkuang



Joined: 14 Dec 2007
Posts: 257

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

PostPosted: Fri Sep 04, 2009 8:02 am     Reply with quote

I have a slow internet connection so I cannot check for you but you should check the datasheet to see whether RA4 is a Schmitt trigger input, it often is on some devices. That would mean you would not see a high unless the level is greater than 0.8Vcc and a low of 0.2Vcc.

Other members of this forum have pointed this out in many previous posts.
newguy



Joined: 24 Jun 2004
Posts: 1907

View user's profile Send private message

PostPosted: Fri Sep 04, 2009 8:43 am     Reply with quote

Pin A4, on some processors, is open drain. Not sure about the 16F876 - check the data sheet.
edwardelric
Guest







PostPosted: Fri Sep 04, 2009 9:07 am     Reply with quote

yup, the pin is open drain.just put a pull-up resistor tied to positive supply.
John P



Joined: 17 Sep 2003
Posts: 331

View user's profile Send private message

PostPosted: Fri Sep 04, 2009 9:14 am     Reply with quote

Whether the pin is open drain or not only affects its use as an output. It shouldn't affect it as an input.

Are you sure that somehow, some way, it's not getting reset to be an output? That would sure prevent it from reading the input state properly! Or getting set for analog input?

If you used a pin with an internal pullup (usually Port B) you could eliminate R28.
Ttelmah
Guest







PostPosted: Fri Sep 04, 2009 10:06 am     Reply with quote

A4, on this chip, is 'unusual', in that first, it is open drain, and second, it has no high level protection diode on the input. It is actually specified to allow inputs up to 12v!. However if you go over this, it really can cause fatal problems.
Not enough of the circuit is shown to know whether there is anythng likely to cause problems, but one has to ask if there may be first, a software problem with the code involved in looking at this pin. There is nothing in what is shown, but (for example), is it possible that if this pin changed state, after being tested, could the code get into a hung state?.
Then one has to ask how you know that A4, is the pin involved? Presumably by testing with it disconnected?. Have you considered whether this affects anything else?. How is the signal to which R28 attaches, actually connected to the PIC?. What drives X5-1?. Have you actually put a scope on RA4, and checked how high it is going when the opto is off?. The Schmitt nature of this input, does seem to be the most likely problem, though this should not cause a 'hang', unless there are code problems....

Best Wishes
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