Sonsivri
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
December 07, 2016, 07:12:24 19:12


Login with username, password and session length


Pages: [1]
Print
Author Topic: Help: Simple PIC pullup not working  (Read 4142 times)
0 Members and 1 Guest are viewing this topic.
picaboo
V.I.P
Newbie
*****
Offline Offline

Posts: 12

Thank You
-Given: 11
-Receive: 0


« on: April 16, 2010, 01:11:17 13:11 »


Hello Everybody,

This seem to be awfully simple, but I am not able to get it working.

I am working with a PIC16F877A, sitting on a ICD2 target board. I am using Hi-Tech suit (picc). In the project, I am using ICD2 as a debugger.

I am using only 1 pin of this huge PIC. A 4K7 resistor is connected between RB0 and +5V as a pullup. I am not using PORTB's internal pullups.

I have a multimeter probe touching RB0. Please see the code below. What I am expecting is that after reset, the multimeter should show +5V (high). After executing the line "TRISB &= ~(1<<HT9200_CE);" in HT9200_enable routine, the multimeter should show 0V (low).

What I am seeing is, the RB0 value stays high. After the program execution finishes, if I disconnect the 4K7 resistor from RB0, it still stays high. I don't understand this. At that point TRISB[0] is 0 (output) and I had loaded RB0 latch with 0 before. So, the RB0 should be driven low.

I also observed the following.

1. If I disconnect the 4K7 resistor and then reset the PIC, the RB0 shows 0V. This is also mystery to me. After reset all IO pins become input and floating. So, the voltage should be near to 2.5V, isn't it? Why is it showing logic low?

Appreciate if you can help me figuring out why this simple pull up experiment is not working.


--Picaboo



Code
====

#include  <htc.h>

#define HT9200_CE 1
#define HT9200_CLK 0
#define HT9200_DATA 2

__CONFIG(XT  &  WDTDIS  &  PWRTDIS  &  BORDIS  &  LVPDIS  &  WRTEN  &
DEBUGEN  &  DUNPROT  &  UNPROTECT);

void HT9200_Init(void) {
   //Pull CE, CLK and DATA high
   
   //The CE, CLK and DATA does not have pullups. These are driven by master.
   //At power-up, all ports come up as I/P. These pins are inputs to the
   //HT9200 also. So, at power-up these pins does not have any driver.they
   //float. The floating pin may cause HT9200 interpret the input as valid something
   //and play the frequencies.
   
   //To make the CE pin high (which makes HT9200 inactive) at power up, and since
   //all pins come up as input which floats, there is a pull up on this pin. So, at
   //power up this pin is seen as high and HT9200 does not play any tone.
   
   //To control the CE pin, only low state need to be driven by PIC. The port latch
   //is always loaded with zero. Whenever low is needed TRISB is programmed to make
   //this pin output, and the pin goes low. Whenever high is needed, TRISB is
   //programmed to make the pin input, and the pullup causes the pin to go high.

   //Clock and data pin is completely driven by PIC since there is no pullup.
   //These pins are always configured as output.
     
   //The Pin latches must be loaded with 'high' before making the pin direction
   //as output (by programming TRIS register). This will cause the the bus to go
   //to high from float.
   
   //Though at power up or at reset the pin autotomatically becomes input, just
   //as a precautionary measure, make CE input. The pin goes high because of pullup.
   TRISB |= (1<<HT9200_CE);
     
   //load 0 to CE latch
   PORTB &= ~(1<<HT9200_CE);
   
   //load 1 to CLK latch
   PORTB |= (1<<HT9200_CLK);
   //configure CLK pin as output
   TRISB &= ~(1<<HT9200_CLK);
   
   //load 1 to DATA latch
   PORTB |= (1<<HT9200_DATA);
   //configure DATA pin as output
   TRISB &= ~(1<<HT9200_DATA);
}

//HT9200 is enabled by pulling CE low. After that wait 10ms for the osc to stabilize
void HT9200_Enable(void){
unsigned short i;

   //activate the bus by pulling CE low.
   TRISB &= ~(1<<HT9200_CE);
   //wait for 10ms
   //DelayMs(10);
   //DelayBigUs(10000);
}

void  chip_init(void)
{
//Timer1 overflow bit interrupt disable
PIE1      =  0b00000000;

//Disable peripheral interrupt bit (Timer1 is part of periperals))
INTCON    =  0b00000000;

//Disable PORTB pull_ups
OPTION    =  0b10000000;

// port  directions:  1=input,  0=output
TRISA     =  0b00000000; //PortA bit 3:0 are outputs for LED cathods. bit 5 is for colon
TRISC     =  0b00000000; //PortC

PORTC = 0b00000000;

//Disable timer1, internal clock source, do not sync to ext clock,
//shutoff osc, 1:1 prescale
//T1CON     =  0b00000101;
T1CON     =  0b00000100;

//To make RA4 digital output
CMCON     = 0b00000000;

PORTA = 0b00000000;
}

void  main(void){
   
   chip_init();
   HT9200_Init();
   ei();
   
   HT9200_Enable();
}


Logged
hate
Hero Member
*****
Offline Offline

Posts: 556

Thank You
-Given: 156
-Receive: 354


« Reply #1 on: April 16, 2010, 03:59:59 15:59 »


Floating doesn't mean the input will oscillate all the time. It may oscillate, stay low or stay high if it has no pullups etc... so when u remove the resistor after program execution, it's a high probability that the pin resides at high if it's current state is input. And 1 important thing, ur CE pin is not RB0 it's RB1. RB0 is the CLK pin and it always resides at high through ur code as I can see.

Regards...
Logged

Regards...
picaboo
V.I.P
Newbie
*****
Offline Offline

Posts: 12

Thank You
-Given: 11
-Receive: 0


« Reply #2 on: April 16, 2010, 04:32:18 16:32 »

Thanks Hate.

Actually, it is RB1. I first experimented with RB0 and then wanted to see if same is happening with RB1. Same is happening.

If you see, in HT9200_Enable routine, I am driving RB1 low.

1. I had set RB1 as input at the first line of this routine.
TRISB |= (1<<HT9200_CE);

2. In HT9200_Init routine I loaded PORTB_1 with 0.
PORTB &= ~(1<<HT9200_CE);


Since RB1 is input and there is a pullup resistor, I was expecting RB1 to read as 1. This is happening.

3. In HT9200_Enable routine, I am setting RB1 as output.
TRISB &= ~(1<<HT9200_CE);

Since RB1 latch is loaded with 0, this should now drive the pin. This is not happening. The pin stays high.

Now, the only connection to this pin to 5V is through the pullup resistor. So, I thought I will disconnect the resistor. But after that also the RB1 pin is staying high. Why is that? RB1 latch is loaded with 0, and the pin is now output. Very simple. Where from the pin be driven as 1?


Another observation. With 1K pullup the behavior is same. But with 10K pullup the pin gets driven to low. But now the problem is the high condition is not 5V. Becaus ethere is too much drop in 10K resistor, RB1 pin shows 3.5V. This is not recognized as high in my logic analyzer as well as the next chip (HT9200) which I am trying to drive with this 1->0 transition.

Logged
hate
Hero Member
*****
Offline Offline

Posts: 556

Thank You
-Given: 156
-Receive: 354


« Reply #3 on: April 16, 2010, 05:18:57 17:18 »


This may be the compiler accessing the i/o's by its own for some purpose, reset maybe. Have u tried setting and resetting the bits directly, like

TRISB.1=0;
PORTB.1=0;

to be sure there's nothing wrong with the pic hardware or compiler. I'm not sure of the syntax though as I don't use HI-TECH. If that also doesn't work, post ur .lst or .asm file so we can debug deeper. Some peripheral on the PIC may need to be shut down, consider that also.

Regards...
Logged

Regards...
ALLPIC
V.I.P
Active Member
*****
Offline Offline

Posts: 113

Thank You
-Given: 64
-Receive: 72


« Reply #4 on: April 25, 2010, 05:56:07 05:56 »

I think to see logic low input you need to some thing that refer to ground. What you can do is. Just put 1K resistor as pull-up and 10K as pull down. and then check in software. I think that will solve your problem. If that has been solved then let me know I will tell you reason.
Logged
Pages: [1]
Print
Jump to:  


DISCLAIMER
WE DONT HOST ANY ILLEGAL FILES ON THE SERVER
USE CONTACT US TO REPORT ILLEGAL FILES
ADMINISTRATORS CANNOT BE HELD RESPONSIBLE FOR USERS POSTS AND LINKS

... Copyright 2003-2999 Sonsivri.to ...
Powered by SMF 1.1.18 | SMF © 2006-2009, Simple Machines LLC | HarzeM Dilber MC