Help in connecting a SN74190N to an 877 PIC

Thread Starter

HindA

Joined Mar 6, 2011
13
I have a project which requires me to turn on the light in a room when there are people present in it. I am using an Infra red emitter and a photodiode as the sensor. I intend to put 2 sensors with a difference in distance inorder to be able to differentiate between people entering and exiting.

I have not worked with counters before and I have no Idea on how I can connect it to the 877 PIC. I need some help in that, please!

I also have a problem on how to use the up mode and the down mode of the counter.

Thank you!
 

spinnaker

Joined Oct 29, 2009
7,830
What is an 877 PIC? PICs start with 10F, 12F, 16F, 18F etc in the 8bit family. PIC24F, dsPIC in the 16bit family and PIC32 in 32 bit family.
 

Thread Starter

HindA

Joined Mar 6, 2011
13
Lightingman, I was told that using a seperate counter is better than using the one embedded in the PIC. I do not know if that is true!

Right now, I'm reading the datasheet of the PIC and I am understanding nothing about the timer mode. Do you have any advice if I want to use it? Besides, how can differentiate between A occuring then B or B occuring then A. i.e. if someone enters or if someone exits the door.

Thank you
 

spinnaker

Joined Oct 29, 2009
7,830
Lightingman, I was told that using a seperate counter is better than using the one embedded in the PIC. I do not know if that is true!

Right now, I'm reading the datasheet of the PIC and I am understanding nothing about the timer mode. Do you have any advice if I want to use it? Besides, how can differentiate between A occuring then B or B occuring then A. i.e. if someone enters or if someone exits the door.

Thank you
Do you need to count how many people enter the room? Or just know they entered?

If you just need to know they entered then this could be done more simple with no PIC.
 

spinnaker

Joined Oct 29, 2009
7,830
Lightingman, I was told that using a seperate counter is better than using the one embedded in the PIC. I do not know if that is true!

Right now, I'm reading the datasheet of the PIC and I am understanding nothing about the timer mode. Do you have any advice if I want to use it? Besides, how can differentiate between A occuring then B or B occuring then A. i.e. if someone enters or if someone exits the door.

Thank you

You should not need a timer unless you want something to happen for a delayed period after someone enters the room.
 

Thread Starter

HindA

Joined Mar 6, 2011
13
I need to count how many people are in the room and turn the light on if someone is inside, this is why i need the PIC :)
 

spinnaker

Joined Oct 29, 2009
7,830
I need to count how many people are in the room and turn the light on if someone is inside, this is why i need the PIC :)

They you will want to use an interrupt. You can use your timer (RA4/T0CKI pin for Timer 0) as a counter but I would suggest just using interrupt on change feature for one of your pins on Port B. You could use the intterput for when someone enters the room (to turn light on) and to do the count.

Do you have to use a 16F877A? The 18F series is optimized for C. It will be a lot easier using C. You can sill use the 16F877A and C but from what I have read the 18F family makes it easier to work with C.
 

Thread Starter

HindA

Joined Mar 6, 2011
13
No, I do not have the 18F.

If I use the interrupt, how can I differentiate between someone entering the room and another exiting it?

This is what I have as an idea but I do not know how to apply it on the PIC:
1) I put one infrared LED on one side and another photodiode on another side A of the door
2) I put another similar sensor on side B of the door
3) If A occures then B, this means someone entered. So, I add one to the counter. If B occured then A, I subtract one from the counter. As long as the counter is greater than zero, the light in the room must still be on.

Do you have an idea for applying that?
 

spinnaker

Joined Oct 29, 2009
7,830
No, I do not have the 18F.

If I use the interrupt, how can I differentiate between someone entering the room and another exiting it?

This is what I have as an idea but I do not know how to apply it on the PIC:
1) I put one infrared LED on one side and another photodiode on another side A of the door
2) I put another similar sensor on side B of the door
3) If A occures then B, this means someone entered. So, I add one to the counter. If B occured then A, I subtract one from the counter. As long as the counter is greater than zero, the light in the room must still be on.

Do you have an idea for applying that?
You could use 2 different pins and 2 different interrupt routines. One for the one near the door and the other for further away. If the door one goes off, it sets a flag. When the one away from the door goes off that flag is cleared and the enter count is updated. Just the reverse for exiting.
 

Thread Starter

HindA

Joined Mar 6, 2011
13
Since I am still a beginner, can you just help me out with the code? if it is in C it's ok, I can manage doing it in mikcroC.

I really am grateful for your help!! Thank you!
 

lightingman

Joined Apr 19, 2007
374
Hi again

You would need to add up all the people who entered and subtract all the people who leave. This is very simple using a PIC. You will not need interupts, just two I/O's configured as inputs and one I/O configured as an output. You could do this with a small device, such as a PIC12FXXX device and a few extra components. The PIC will not be working very hard at all.

Daniel.
 

Thread Starter

HindA

Joined Mar 6, 2011
13
I know that I have to add up all the people that entered and subtract all those who went out. The problem is how do I get the PIC to differentiate if A occured before B or B occured before A (meaning if the 1st sensor was crossed before the second one=> person in, and if the 2nd sensor was crossed then the 1st one was crossed after=> a person out)?

Thank you again :) I'm looking forward to your reply.
 

spinnaker

Joined Oct 29, 2009
7,830
I know that I have to add up all the people that entered and subtract all those who went out. The problem is how do I get the PIC to differentiate if A occured before B or B occured before A (meaning if the 1st sensor was crossed before the second one=> person in, and if the 2nd sensor was crossed then the 1st one was crossed after=> a person out)?

Thank you again :) I'm looking forward to your reply.
Like I said. A sets a flag. When B is tripped it sees if A flag is set. That means someone came in.

If B is tripped it checks to see if A flag is set. If not then it sets a B flag. When A is tripped, it checks the B flag. If set then that means someone is exiting.

Your problem is going to be if people try to enter and exit at exactly the same time. Then I don't know what to do.

You could get really fancy when A is tripped, it starts a timer. If B is not tripped then the enter count is canceled. It means they changed thier mind. :)
 

be80be

Joined Jul 5, 2008
2,072
A infrared LED and a photo-diode do not by themselves make a great switch. room lite can have a false trigger.

To count if some one come's in you would need a sensor on the inside of the door to see if they exited you'll need one on the outside. Like you said.

That would make coding easy

Like this sensor_out as variable and sensor_in as variable. and a counter

Your code would be like this this is in basic But it easy to write it in C to

Rich (BB code):
dim sensor_out as byte
dim sensor_in as byte
dim counter_in as byte
dim counter_out as byte

If sensor_in = 1 and sensor_out =0 then 
      counter_in = counter_in +1
      counter_out = counter_in
      //you can add action code here
elseif sensor_out = 1 and sensor_in = 0 then
      counter_out = counter_out - 1
endif
Just a idea I would blink my Infra red diode at 38 to 40 khz that would keep room light from interfering. And test to see if your receiving light from your Infra red diode
 
Top