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

PIC18F2550 pin C5 input state "latching" [SOLVED]

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



Joined: 15 May 2013
Posts: 7
Location: México

View user's profile Send private message Visit poster's website

PIC18F2550 pin C5 input state "latching" [SOLVED]
PostPosted: Wed Oct 09, 2013 11:00 pm     Reply with quote

Hello everyone!

I'm working with the 18F2550, trying to read pin C4 and C5. (Already disabled USB functions from those pins)
I made a small code to show the problem. It is supposed to turn on LED1 while S1 is pressed.



Code:
output_bit(PIN_RB2, input(PIN_C5));

Full code and schematic below.

The weird part: Each time I press S1, LED1 turns ON as expected, but when I release S1, LED1 stays on. PORTC register reads 0010 0000 even after releasing S1.

The weirder part: LED1 will stay ON until I press S2.
I have other push buttons on pins C6 and C7, but they have no effect on the state of LED1. Under simulation (proteus) it runs as expected.

The weirdest part: When I supply the circuit directly from pickit3, the problem seems to disappear (i.e. LED1 turns OFF when I release S1). This problem only appears when I supply my circuit from a battery or external power supply.
I double-checked my power supply design (LM7805), and it seems to be ok. I got all my decoupling and bypass capacitors as usual, no voltage ripple or glitches.


I am debugging using pickit3 on mplab 8.91, and my compiler version is 4.114.
R1 = R2 = 1.5K
4MHz xtal. (I think my fuses are correct, but after 10hrs working on the same thing, I'm not sure Sad )

I couldn't find any info on the datasheet regarding this behavior.
Has anyone had this problem before?

Thanks in advance!!!
Reno

PS sorry for the crappy hand drawn schematic, hope it is clear.

Code:
#include <18F2550.h>

//#FUSES DEBUG
#FUSES NOWDT                    //No Watch Dog Timer
#FUSES PLL1                     //Divide By 1 (4MHz oscillator input)
#FUSES CPUDIV1                  //No System Clock Postscaler
#FUSES HSPLL                    //Crystal/Resonator with PLL enabled
#FUSES PUT                      //Power Up Timer
#FUSES NOBROWNOUT               //No brownout reset
#FUSES VREGEN                   //USB voltage regulator enabled
#FUSES NOPBADEN                 //PORTB pins are configured as I/O on RESET
#FUSES NOMCLR                   //Master Clear pin used for I/O
#FUSES NOSTVREN                 //Stack full/underflow will not cause reset
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOPROTECT                //Code not protected from reading

#use delay(clock=48000000)
#use rs232(baud=9600,parity=N,xmit=PIN_A1,rcv=PIN_A2,bits=8)

#byte UCFG = getenv("SFR:UCFG")
#byte UCON = getenv("SFR:UCON")
#bit UTRDIS = UCFG.3
#bit USBEN = UCON.3


void main()
{
   UTRDIS = 1;
   USBEN = 0;
   while(1)
   {
      output_bit(PIN_RB2, input(PIN_C5));
   }
}

_________________
Reno Baron


Last edited by renobaron on Thu Oct 10, 2013 11:39 am; edited 1 time in total
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Oct 10, 2013 10:01 am     Reply with quote

I don't have a 18F2550, so I tested your program with an 18F4550 which
is in the same PIC family. It worked OK for me. I used a PicDem2-Plus
board (non-Rohs vs.). That board doesn't have a push-button on Pin C5
so I jumpered it over the button on pin A4. I used your compiler version
4.114.

There are differences in the external circuits. The switch on my board
is wired as shown below. This is much more standard, than the way
you're doing it. The standard way is with the switch going to ground
and a pull-up resistor. The 470 ohm series resistor protects the PIC pin
from students who might make the pin into an high level output and then
press the switch (which could burn up the pin driver in the PIC). The cap
is there to provide some external debouncing.
Code:


                 +5v
                  |
                  <
                  > 4.7K       
                  <         ___ Push button switch 
To     470        |        _|_|_
PIC --/\/\/\---------------o   o------
pin           |                       |             
             ___                     --- GND
             --- 0.1uf (100 nF)       -   
              |
              |     
             ---  GND
              -




The LED circuit looks like this:
Code:

pin      470 ohms      LED       
B2    ---/\/\/\/------->|----
                            |
                            |
                          -----  Ground 
                           ---
                            -
 

My suggestion is to re-wire your circuits so they look like this, as closely
as possible (including component values). See if it then works.

Also, one more comment. Your code as posted, can't possibly compile.
You have "PIN_RB2" in there and that's not a legal CCS constant. Is this
your true actual test program ? If not, post the real program.
renobaron



Joined: 15 May 2013
Posts: 7
Location: México

View user's profile Send private message Visit poster's website

PostPosted: Thu Oct 10, 2013 11:16 am     Reply with quote

Thanks for your reply!

I will change the pulldown resistors for pullups and post my results.
I made a mistake with the RB2 thing. The actual code is as follows (fragment):

Code:

#define LED1 PIN_B2

//in main:

output_bit(LED1, input(PIN_C5));



Thanks again
Reno
_________________
Reno Baron
renobaron



Joined: 15 May 2013
Posts: 7
Location: México

View user's profile Send private message Visit poster's website

Solved
PostPosted: Thu Oct 10, 2013 11:39 am     Reply with quote

Wiring the resistors as pullups solves the problem. Seemed like a complex problem, but sticking to the standard practices can save you lots of problems! Thank you again PCM Programmer
_________________
Reno Baron
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