View previous topic :: View next topic |
Author |
Message |
Sterngleiter
Joined: 07 Jan 2013 Posts: 90
|
IO Ports as Input |
Posted: Thu Jul 31, 2014 2:11 pm |
|
|
I have the following problem:
I would like to count for something.
The port is controlled by a pushbutton.
The pushbutton is 10cm away from port. When I turn off the voltage, not actuated pushbutton is counted. that should not be.
When I touch the cable between button and pic its counted without push button but not ever.
the Code is :
Code: |
#include <main.h>
int test;
void main()
{
while(true)
{
if(input(pin_a1)==1)
{
while(input(pin_a1)==1);
++test;
}
}
}
|
I can find nothing on the internet is no solution. I can not check with oscilloscope.
Thanks for HELP |
|
|
alan
Joined: 12 Nov 2012 Posts: 357 Location: South Africa
|
|
Posted: Thu Jul 31, 2014 2:15 pm |
|
|
How is your PB connected? Is it pulled low or high? (Show ASCII diagram if possible).
Also do a search for debouncing of your PB.
Regards |
|
|
Sterngleiter
Joined: 07 Jan 2013 Posts: 90
|
|
Posted: Thu Jul 31, 2014 2:40 pm |
|
|
It's pulled low.
Debounced over
While(input(pin_a1)==1); |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Thu Jul 31, 2014 2:49 pm |
|
|
Two questions:-
1) How do you know what the value of your variable 'test' is?
2) How fast do you think it might count?
Mike |
|
|
Sterngleiter
Joined: 07 Jan 2013 Posts: 90
|
|
Posted: Thu Jul 31, 2014 2:54 pm |
|
|
I forgot to mention that I still have lcd display.
When i turn off the Power only then counted alone without pushing Button |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Thu Jul 31, 2014 3:08 pm |
|
|
So please give us short, complete and compilable code which shows the problem you are having.
Mike |
|
|
Sterngleiter
Joined: 07 Jan 2013 Posts: 90
|
|
Posted: Thu Jul 31, 2014 3:23 pm |
|
|
Is Not difficult Code. It is Running. You Must only insert printf (lcd...)
My Problem is why counted when i turn off the power.
I also use a output instead of the variable.
I can see it. Is a Short Time High.
Code: |
#include <main.h>
int test;
void main()
{
while(true)
{
if(input(pin_a1)==1)
{
while(input(pin_a1)==1);
Output_high(pin_b0);
}
}
} |
|
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Thu Jul 31, 2014 3:30 pm |
|
|
You're the one wanting help.
There must be something you're not telling us.
If you refuse to provide a complete picture, I'm out.
Bye.
Mike |
|
|
Sterngleiter
Joined: 07 Jan 2013 Posts: 90
|
|
Posted: Thu Jul 31, 2014 3:44 pm |
|
|
It is really original Code that i have. I'm writing from telephone therefore I can not copy from compiler "pcwhd 5.0 ". When i touch the cable from switch during turn off the power without pushing then is the Output High for a Short Time but Not ever. why should not say everything I. I have this Problem with more pic controller. oddly always the same error. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9246 Location: Greensville,Ontario
|
|
Posted: Thu Jul 31, 2014 5:25 pm |
|
|
It sounds like the input is acting as an antenna and picking up strong EMI or local AC ( 50 or 60 Hz). That's one of the problems using an active high as opposed to active low input signal.
You should have some low value capacitor on the input to 'filter' the 'noise'.
Without seeing a schematic or picture of your project it is difficult to tell what the real problem is.
Perhaps you can change the 'logic' to active low( grounding the input = 'true') and see what happens ?
hth
jay |
|
|
Sterngleiter
Joined: 07 Jan 2013 Posts: 90
|
|
Posted: Fri Aug 01, 2014 1:24 am |
|
|
I have also tried the other way around.
always the same result.
as I said it only occurs when off.
I would like to also add the wiring diagram but I do not know how |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19552
|
|
Posted: Fri Aug 01, 2014 2:08 am |
|
|
You put the image on a website (either your own, or a 'free picture hosting' site), and post the link to it here. |
|
|
alan
Joined: 12 Nov 2012 Posts: 357 Location: South Africa
|
|
Posted: Fri Aug 01, 2014 2:48 am |
|
|
Edit OOPS
Or just use ASCII
Code: |
VCC
|
| |
|_| _|_
PIN ------|---- ----------|
__|__
___
_
|
Regards
Last edited by alan on Fri Aug 01, 2014 4:22 am; edited 1 time in total |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19552
|
|
Posted: Fri Aug 01, 2014 3:02 am |
|
|
But if using ASCII, remember to use the 'code' buttons round it, so the formatting is preserved. Otherwise it is not legible.... |
|
|
Sterngleiter
Joined: 07 Jan 2013 Posts: 90
|
|
Posted: Fri Aug 01, 2014 5:30 am |
|
|
it's just like having drawn alan.
I do not understand what you mean Ttelmah.
why is the line of push buttons like a antenna.
I am looking for solution set several months.
please help me.
I can not even imagine that I'm the only one with this problem- |
|
|
|