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

I/O trouble

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



Joined: 14 Mar 2008
Posts: 10

View user's profile Send private message

I/O trouble
PostPosted: Tue Jun 10, 2008 11:32 pm     Reply with quote

Hello

I am using a pic 18f4580. I have a input that is always reading low. I am using a 10K pull up resistor to 5V. The digital input was working fine for about 1 hour of run time. Nothing abnormal electrically has taken place. Is it possible I am reading a internal buffer and not the output. I have tried reprogramming the chip and the pin still reads low when it is high. Pin d6 is the pin in question. Are there any settings I am missing? Can you reset the internal buffer by setting the pin to a digital output and setting it low/high and then resetting it back to a input?

Any help would be much appreciated.

PS. This is the second board that this has happened too.

Thanks Geo
Code:
#zero_ram
#use fast_io(A)
#use fast_io(B)
#use fast_io(C)
#use fast_io(D)
#use fast_io(E)
#use delay(clock=10000000)
# fuses HS,NOPROTECT,BROWNOUT,NOWDT,PUT, NOLVP,MCLR

set_tris_d(0b01000000);//D6 set to input for SWitch
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Wed Jun 11, 2008 7:50 am     Reply with quote

Way back when I used to work with PIC16C54s it was common knowledge that PIC TRIS direction bits sometimes got garbled. So I developed a programming style that reconfigures the TRIS registers each time through the main loop. I don't know if that problem persists, but I still use that style and I have no problems.

The datasheet should show you the structure of the pin buffers and let you know just where your input data is coming from.
_________________
The search for better is endless. Instead simply find very good and get the job done.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Wed Jun 11, 2008 8:36 am     Reply with quote

The shown code fragment looks fine but is incomplete, the port reading part is missing. Post a small but complete program demonstrating your problem.

What is your compiler version number?

You are reading data from a switch. Whenever I read 'switch' I think 'debounce code'. What kind of switch is connected and what measures have you taken to solve the switch bouncing effects?
Ttelmah
Guest







PostPosted: Wed Jun 11, 2008 8:38 am     Reply with quote

If you are using standard_io (the default in CCS), and are using their I/O instructions (output_high etc.), then CCS will automatically set/clear the TRIS bits for every input/output instruction. With 'fast_io' selected this is removed.
Realistically, if the pin was reading OK, then either something has gone wrong in the code, or something 'abnormal electrical' _has_ taken place.
There is a separate _output_ latch, but the input latch, is directly wired to the pin, and is enabled, by the read operation. It'll latch whatever is there, when you start the read operation.
The 'fast_io' line is configuration change, so doesn't have to be inside the code, but the _tris_ line, is a program instruction, and needs to be inside the running code. As shown, it won't change the TRIS. I'd suspect this is the problem, though the default TRIS setting, would be for all pins to be inputs.

Best Wishes
george



Joined: 14 Mar 2008
Posts: 10

View user's profile Send private message

PostPosted: Thu Jun 12, 2008 8:57 am     Reply with quote

Thanks for the responses

Compiler version is
PCWHD 4.074
De bounce is done with hysteresis using a timer interrupt. Every 50 milliseconds the switch is read with this statement.
if(!input(PR_SW))
Port is initialized with startup routine called once before main loop.

set_tris_d(0b01000000);//D6 set to input for PR_SW
void main(void)
{
startup(); //initialize

while (true){
.
.
.

}// while(TRUE)
}//end of main
I had a closer look at the data sheet and noticed this portd uses Schmidt triggers for digital inputs
from data sheet
RD6/PSP6/
P1C
RD6 OUT 0 DIG LATD<6> data output.
IN 1 ST PORTD<6> data input.
Legend: OUT = Output, IN = Input, ANA = Analog Signal, DIG = Digital Output, ST = Schmitt Buffer Input, TTL = TTL Buffer Input
There is diode protection to VDD or VSS on this PIN.
However, I suspect the Pin was damaged electrically with an inductive load.
The chip was reprogrammed with and older version of software and the pin still did not read correctly.

Anyway thanks for all your help. If the second one has I/O problems then
I need to look very closely at the code. However if it was the code, would not the I/o pin be reset when it is reprogrammed?


Thanks Geo
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