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 does not know its high, pun intended

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








pin does not know its high, pun intended
PostPosted: Tue Jan 29, 2008 9:40 am     Reply with quote

Im sure there is a simple answer that im not seeing.....

I'm working with a univeral proto board that has pull down resistors connected with a push button to pin_b1 and pin_b2 of PIC18F4520 Micro. I am using the input function to detect a high level on either of the pins and nothing is happening. Ive checked the portb register and the micro is not detecting that the pins have gone high.

here is a test piece of code that i have tried to cimply to problem to. Thanks for the input.

Compiler 3.203





Code:
#include <18F4520.h>
#fuses INTRC//HS//INTRC
#fuses NOPROTECT,MCLR,NOBROWNOUT,BORV45,NOWDT,WDT128,NOPUT,NOSTVREN,NODEBUG
#fuses NOLVP,NOWRT,NOCPB,NOWRTB,NOWRTC,NOCPD,NOWRTD,NOEBTR,NOEBTRB
#fuses NOXINST   //extended cpu
#use delay(clock=8000000)

void main(){
setup_oscillator(OSC_8MHZ|OSC_NORMAL);

set_tris_b(0xff);

//start indicator
output_high(pin_d7);
delay_ms(500);
output_low(pin_d7);
delay_ms(500);



while(1){

if(input(pin_b1)==0){
   //pin_b1 button was pushed
   output_high(pin_d7);
   delay_ms(500);
   output_low(pin_d7);
   delay_ms(500);
}
else if(input(pin_b2)==1){
   //pin_b2 button was pushed
   output_high(pin_d7);
   delay_ms(500);
   output_low(pin_d7);
   delay_ms(500);
}

delay_ms(50);
}//while
}//main
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Tue Jan 29, 2008 9:50 am     Reply with quote

Shouldn't you be checking if pin_b2 == 0 (not 1 as in your code).

Also I would remove the else and just have the 2 seperate if's unless you don't want to check b2 IF b1 is pressed!

I also assume the push buttons are push to break and are connected from VCC to each pin.
Guest








PostPosted: Tue Jan 29, 2008 9:56 am     Reply with quote

The pushbuttons are tied Low through the pull down resistor and the input pins are connected to VDD when the pushbutton is pressed. So the pins are low until buttons are pushed.

Yeah, the code is rough, but just a simple example of checking both pins.
Guest








PostPosted: Tue Jan 29, 2008 9:58 am     Reply with quote

Woops to the code here is the updated corrected test statements.....

Code:
#include <18F4520.h>
#fuses INTRC//HS//INTRC
#fuses NOPROTECT,MCLR,NOBROWNOUT,BORV45,NOWDT,WDT128,NOPUT,NOSTVREN,NODEBUG
#fuses NOLVP,NOWRT,NOCPB,NOWRTB,NOWRTC,NOCPD,NOWRTD,NOEBTR,NOEBTRB
#fuses NOXINST   //extended cpu
#use delay(clock=8000000)

void main(){
setup_oscillator(OSC_8MHZ|OSC_NORMAL);

set_tris_b(0xff);

//start indicator
output_high(pin_d7);
delay_ms(500);
output_low(pin_d7);
delay_ms(500);



while(1){

if(input(pin_b1)==1){
   //pin_b1 button was pushed
   output_high(pin_d7);
   delay_ms(500);
   output_low(pin_d7);
   delay_ms(500);
}
else if(input(pin_b2)==1){
   //pin_b2 button was pushed
   output_high(pin_d7);
   delay_ms(500);
   output_low(pin_d7);
   delay_ms(500);
}

delay_ms(50);
}//while
}//main
Guest








PostPosted: Tue Jan 29, 2008 10:32 am     Reply with quote

Anything obviously wrong?

Is it possible that i have bad couple of micros?

Do i need the weak pull ups enabled in this case? Where i am connecting the pin directly to VDD.

Any other ideas?
rnielsen



Joined: 23 Sep 2003
Posts: 852
Location: Utah

View user's profile Send private message

PostPosted: Tue Jan 29, 2008 10:32 am     Reply with quote

Just one quick note. You need to include the fuse NOPBADEN. This makes PORTB pins configured as digital I/O on RESET.

Ronald
Guest








PostPosted: Tue Jan 29, 2008 1:41 pm     Reply with quote

Ok, so after some pin to pin testing and verifying the test on a separate proto board im a little perplexed!

I thought there may be some errors on my proto board so i did all concluding test on the PICDEM 2 plus Demo board.

I first decided to test to 2 pins that i was having problems with on my board. b1 and b2, which by verification on the datasheet state they can be used as digital I/O (page 14). One discrepancy between by board and the dem2 plus board is that they do not have a direct resistor pull-up configuration for the PB(Vinput of ~2.2V), the pins with both microchip's PB configuration and a direct vdd pull up configuration. Both of the pins do no work as digital Inputs in either configurations. I tried a separate micro and same results.

This really blowing me away, i tested all ports to see which i can use as digital Inputs. Here are my findings

PORTA, the only pin that responded as an input was pin_a4.

PORTB, the only pin that responded as an input was pin_b5

PORTC, Port C worked as expected, but would not respond to their input pin configuration where Vinput ~2.2V.

PORTD, PORTC, Port C worked as expected, but would not respond to their input pin configuration where Vinput ~2.2V.

So i did both test on 2 boards with same results. Either both my micros after damaged or Microchips datasheet seems to be wayyyyy offffff as to how you can use the pins.

Here is the code i used to test both configurations.

Code:

#include <18F4520.h>
#fuses INTRC//HS|INTRC
#fuses NOPROTECT,MCLR,NOBROWNOUT,BORV45,NOWDT,WDT128,NOPUT,NOSTVREN,NODEBUG
#fuses NOLVP,NOWRT,NOCPB,NOWRTB,NOWRTC,NOCPD,NOWRTD,NOEBTR,NOEBTRB
#fuses NOXINST   //extended cpu
#fuses NOPBADEN  //PORTB pins configured as digital I/O on RESET
#use delay(clock=8000000)

#define LED pin_b3
#define test_pin pin_b1

void main(){
setup_oscillator(OSC_8MHZ|OSC_NORMAL);

set_tris_b(0xff);

//start indicator
output_high(LED);
delay_ms(500);
output_low(LED);
delay_ms(500);



while(1){

if(input(test_pin)==1){
   //pin_b1 button was pushed
   output_high(LED);
   delay_ms(500);
   output_low(LED);
   delay_ms(500);
}


delay_ms(50);
}//while
}//main


Any ideas, i guess i will order a couple more PIC18F4520's to verify the results...........

very discombobled......as i thought i could trust the datasheets a little more than this!
Ttelmah
Guest







PostPosted: Wed Jan 30, 2008 8:05 am     Reply with quote

So, what happens if you add:

SETUP_ADC_PORTS(NO_ANALOGS);

to your code?.
I'd have expected B6, and B7 to also work, but the big 'pattern', is that no pin that is definable as an analog source, is working. There have been a number of versions of CCS code, with various chips, that 'default' to enabling the analog ports on boot. Explicitly turning them off, may well fix this.

Best Wishes
Guest








PostPosted: Sat Feb 02, 2008 9:04 am     Reply with quote

Well, got some new pic18f4520's in and tested them..... same problems.
ckielstra



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

View user's profile Send private message

PostPosted: Sat Feb 02, 2008 9:29 am     Reply with quote

Quote:
Compiler 3.203
This might not have to do with your current problems but using this version you are going to run into other problems. V3.203 was one of the first releases of the v3.2 compiler and had _many_ problems. The v3.2 compiler became more or less usable with release v3.225.

My advice: revert to either v3.191, the last stable version before the v3.2 release, or update to a newer version.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Feb 02, 2008 4:48 pm     Reply with quote

Quote:
but would not respond to their input pin configuration where Vinput ~2.2V.

Are you using 2.2v as your input high level ?

For many pins, this won't work. It's too low. All PIC pins that have
schmitt trigger inputs require an input level of at least .8 x Vdd.
For a 5v board, the required level is 4.0 volts. However, for Port B
2.2v should work. The required minimum is 2.0v.


I suggest that you use the PicDem2-Plus board, and make these changes:

1. Re-wire your switches so they are used in the conventional way.
This is with a pull-up resistor on the PIC pin, and with one side of the
switch connected to ground.

2. For Port B, you can enable the built-in pull-ups instead of adding
external resistors. Do it by adding this line of code:
Code:
port_b_pullups(TRUE);


3. Change the tests so they check for a logic zero. That's because
pressing the switch will now take the pin to ground, after you re-wire it.
Example:
Code:
if(input(test_pin) == 0){


If this doesn't work then post the new program.
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