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 support@ccsinfo.com

IO Ports as Input
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Sterngleiter



Joined: 07 Jan 2013
Posts: 90

View user's profile Send private message

IO Ports as Input
PostPosted: Thu Jul 31, 2014 2:11 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Jul 31, 2014 2:15 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Jul 31, 2014 2:40 pm     Reply with quote

It's pulled low.
Debounced over
While(input(pin_a1)==1);
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Thu Jul 31, 2014 2:49 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Jul 31, 2014 2:54 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Jul 31, 2014 3:08 pm     Reply with quote

So please give us short, complete and compilable code which shows the problem you are having.

Mike
Sterngleiter



Joined: 07 Jan 2013
Posts: 90

View user's profile Send private message

PostPosted: Thu Jul 31, 2014 3:23 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Jul 31, 2014 3:30 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Jul 31, 2014 3:44 pm     Reply with quote

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: 9162
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Jul 31, 2014 5:25 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Aug 01, 2014 1:24 am     Reply with quote

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: 19329

View user's profile Send private message

PostPosted: Fri Aug 01, 2014 2:08 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Aug 01, 2014 2:48 am     Reply with quote

Edit OOPS Embarassed
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: 19329

View user's profile Send private message

PostPosted: Fri Aug 01, 2014 3:02 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Aug 01, 2014 5:30 am     Reply with quote

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-
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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