Help in connecting a SN74190N to an 877 PIC

Discussion in 'Embedded Systems and Microcontrollers' started by HindA, Mar 6, 2011.

  1. HindA

    Thread Starter New Member

    Mar 6, 2011
    13
    0
    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!
     
  2. lightingman

    Senior Member

    Apr 19, 2007
    374
    22
    Hi,

    Why do you need to use a counter with a PIC. All the counting / timing can be done within the 877.

    Daniel.
     
    HindA likes this.
  3. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,866
    988
    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.
     
    HindA likes this.
  4. HindA

    Thread Starter New Member

    Mar 6, 2011
    13
    0
    spinnaker, the PIC's name is 16F877A
     
  5. HindA

    Thread Starter New Member

    Mar 6, 2011
    13
    0
    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
     
  6. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,866
    988
    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.
     
  7. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,866
    988

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

    Thread Starter New Member

    Mar 6, 2011
    13
    0
    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 :)
     
  9. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,866
    988

    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.
     
    HindA likes this.
  10. HindA

    Thread Starter New Member

    Mar 6, 2011
    13
    0
    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?
     
  11. HindA

    Thread Starter New Member

    Mar 6, 2011
    13
    0
    By the way, I am using mikroC as a language. It is similar to the C.
     
  12. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,866
    988
    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.
     
  13. HindA

    Thread Starter New Member

    Mar 6, 2011
    13
    0
    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!
     
  14. lightingman

    Senior Member

    Apr 19, 2007
    374
    22
    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.
     
  15. lightingman

    Senior Member

    Apr 19, 2007
    374
    22
    Look. Give me a couple of days, and I will work it out for you.

    Daniel
     
    HindA likes this.
  16. HindA

    Thread Starter New Member

    Mar 6, 2011
    13
    0
    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.
     
  17. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,866
    988
    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. :)
     
    HindA likes this.
  18. be80be

    Senior Member

    Jul 5, 2008
    431
    57
    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

    Code ( (Unknown Language)):
    1.  
    2. dim sensor_out as byte
    3. dim sensor_in as byte
    4. dim counter_in as byte
    5. dim counter_out as byte
    6.  
    7. If sensor_in = 1 and sensor_out =0 then
    8.       counter_in = counter_in +1
    9.       counter_out = counter_in
    10.       //you can add action code here
    11. elseif sensor_out = 1 and sensor_in = 0 then
    12.       counter_out = counter_out - 1
    13. endif
    14.  
    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
     
  19. be80be

    Senior Member

    Jul 5, 2008
    431
    57
    That is a hard one
     
  20. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,866
    988
    They would need to exit an enter at exactly the same time fo rit to be a problem.
     
Loading...