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

Help: Connecting OPB705 sensor with P16F877A
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
logicchild



Joined: 16 Nov 2013
Posts: 14

View user's profile Send private message

PostPosted: Sun Nov 17, 2013 2:51 pm     Reply with quote

Hi,

I'm currently using this schema, also I will use its analog value.

In PIC,
I made the port A as analog, and I tested it and it works, I don't want the converted digital value, I just want 0 or +V, so I've connected a LED in PORTB pin0, and reading from AN2, and then checking if the value is zero it will turn off the LED, otherwise turn it on,

That's all I want.

Thanks for everyone Smile Smile
Ttelmah



Joined: 11 Mar 2010
Posts: 19535

View user's profile Send private message

PostPosted: Mon Nov 18, 2013 1:08 am     Reply with quote

Some comments:

1) The value will almost certainly need to be tested for being close to zero, rather than zero itself. A transistor pulling down, is not a perfect short, and the ADC, will see noise both on the signal and on it's Vref. So your test wants to be something like if the count (assuming you use the 8bit mode), is <20.

2) Why waste so much work?. What you want is simply detection of a voltage being above or below a threshold. Using the ADC, is a 'sledgehammer/nut' solution. The chip you are using, has a comparator. This is exactly the sort of job this is designed to do. Giving you a simple 1/0 output, when an input voltage is above/below a programmed threshold. Right tool for the job. The ADC involves a lot of processor time, and quite bulky code comparatively.

3) Key thing that people are trying to point out to you, is the first rule of debugging. Do things in little bits. Get the sensor working, and returning a voltage that changes as it sees a signal _first_. Only once you have this working, and know what voltages to expect, move on to the code. trying to do it any other way, is just wasting your time.

Best Wishes
temtronic



Joined: 01 Jul 2010
Posts: 9240
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Nov 18, 2013 8:14 am     Reply with quote

also...

remember that sensor is a 'flag' NOT 'distance' type sensor. It was designed to give a '1' or '0' for 'something there or not'. It cannot be used to say 'something is x inches away from me'.

hth
jay
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 Previous  1, 2
Page 2 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