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

switch_pin

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



Joined: 23 Oct 2006
Posts: 175

View user's profile Send private message

switch_pin
PostPosted: Wed May 02, 2007 3:56 am     Reply with quote

i use the if stetement
if (input(PIN_A3)==0) {

setup_timer_2(T2_DIV_BY_1, 255,1);}

else if (input(PIN_A4)==0) {
setup_timer_2(T2_DIV_BY_4, 255,1);}
else if (input(PIN_A5)==0) {
setup_timer_2(T2_DIV_BY_16, 255,1);}

else if (input(PIN_E0)==0) {
setup_timer_2(T2_DISABLED , 255,1);}

which is connect to a 4 way switch.
The circuit on the board is working with the same frequency
all the time indipentendly from the switch.
is anyone who know what is the problem????
Ttelmah
Guest







PostPosted: Wed May 02, 2007 4:00 am     Reply with quote

Pull up resistors on the pins?...

Best Wishes
rnielsen



Joined: 23 Sep 2003
Posts: 852
Location: Utah

View user's profile Send private message

PostPosted: Wed May 02, 2007 2:39 pm     Reply with quote

Check out the I/O section of the spec. sheet. Not all pins are the same. If you are looking at inputs, you will want to make sure it can go both high and low, hence the suggestion for pull-up resistors. Most likely, PortA does not have any internal pull-ups.

Ronald
andys



Joined: 23 Oct 2006
Posts: 175

View user's profile Send private message

switch
PostPosted: Thu May 03, 2007 5:23 am     Reply with quote

What is ¨Pull up resistors on the pins¨?
i use pic16F777
rnielsen



Joined: 23 Sep 2003
Posts: 852
Location: Utah

View user's profile Send private message

PostPosted: Thu May 03, 2007 9:10 am     Reply with quote

It sounds as if you might need a little more 'learning' about electronics.

A 'pull-up' resistor is a resistor that has one lead connected to a component pin, i.e. an input pin of a PIC part. The other resistor lead is connected to VCC. This will, in effect, cause the input pin to be pulled 'High' and the PIC's input() routine will see a '1' on it's input. When you connect a switch to that input and have it pull the input to Ground this will cause the input to see a '0' and allow the PIC to see the different states. When the switch is closed, and pulling the input low, current will flow through the resistor. This will keep Ground and VCC from shorting out yet enabling the pin to be 'pulled' to both states.

If you only connect a switch, to Ground, and not have a 'pull-up' resistor, there is nothing to pull the input 'High'. You need to have the input see both states in order to 'trigger' an event.

Ronald
jds-pic



Joined: 17 Sep 2003
Posts: 205

View user's profile Send private message

PostPosted: Sat May 05, 2007 12:07 pm     Reply with quote

let me just buttress the excellent reply above with some additional practical info which will answer your next question: "What value pull-up resistor should i use?"

the answer is, "it depends".

for slowly changing signals or where battery consumption is a concern, 100K will do. for rapidly changing signals or in the presence of noise, 2K is a better bet. for your application, and knowing your relative inexperience in things electronic, i would start with 10K and work from there.

jds-pic
andys



Joined: 23 Oct 2006
Posts: 175

View user's profile Send private message

switch
PostPosted: Sun May 06, 2007 8:35 am     Reply with quote

I check my circuit and is ok.So the broplem is on the code that i used.
Is anyone who know what is the broplem.
My code is :
if ((input(PIN_A3)==0)) {
setup_timer_2(T2_DIV_BY_1, 255,1);
output_high(PIN_D2);
}

if ((input(PIN_A3)==0)&& (input(PIN_A4)==0)) {
setup_timer_2(T2_DIV_BY_4, 255,1);
output_high(PIN_D3);

}

if (((input(PIN_A3)==0)&&(input(PIN_A4)==0)&&(input(PIN_A5)==0))) {
setup_timer_2(T2_DIV_BY_16, 255,1);
output_high(PIN_C4);
}

if (((input(PIN_E0)==0)&&(input(PIN_A3)==0)&&(input(PIN_A4)==0)&&(input(PIN_A5)==0))) {
setup_timer_2(T2_DISABLED , 255,1);
}
ckielstra



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

View user's profile Send private message

PostPosted: Sun May 06, 2007 1:37 pm     Reply with quote

The code as show does compile (I guess), so we need a bit more information:
1) What is the above code supposed to do?
2) What behaviour do you see? And how is this different from what you want it to behave?

Quote:
I check my circuit and is ok.
Are you really sure about this? Can you tell us how the switch is connected to the PIC pins?

I see you activate a PIC output pin when changing switch positions, do the outputs change as expected?
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