View previous topic :: View next topic |
Author |
Message |
andys
Joined: 23 Oct 2006 Posts: 175
|
switch_pin |
Posted: Wed May 02, 2007 3:56 am |
|
|
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
|
|
Posted: Wed May 02, 2007 4:00 am |
|
|
Pull up resistors on the pins?...
Best Wishes |
|
|
rnielsen
Joined: 23 Sep 2003 Posts: 852 Location: Utah
|
|
Posted: Wed May 02, 2007 2:39 pm |
|
|
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
|
switch |
Posted: Thu May 03, 2007 5:23 am |
|
|
What is ¨Pull up resistors on the pins¨?
i use pic16F777 |
|
|
rnielsen
Joined: 23 Sep 2003 Posts: 852 Location: Utah
|
|
Posted: Thu May 03, 2007 9:10 am |
|
|
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
|
|
Posted: Sat May 05, 2007 12:07 pm |
|
|
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
|
switch |
Posted: Sun May 06, 2007 8:35 am |
|
|
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
|
|
Posted: Sun May 06, 2007 1:37 pm |
|
|
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? |
|
|
|