Shop OBEX P1 Docs P2 Docs Learn Events
Basic counting code — Parallax Forums

Basic counting code

Still LearningStill Learning Posts: 3
edited 2007-02-27 00:35 in BASIC Stamp
Please, need help or at least a kick in the right direction. I have two books Robotics Experiments and Time'N and Count'N. I want to build a code in BS2 to count and total a input. I have 4 logic circuits built. Two for counting and two for time, as in total time the input is high. Eventually I want to add the time of day the input changed.

Thanks

George

Comments

  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2007-02-22 19:40
    Hi George, a description or·a schematic of your logic circuits would help decide which way to kick.

    Jeff T.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-02-22 23:00
    George,

    I believe that book is written around the PIC micro. Based on your phone call I would say you basically need a state machine code to detect when the door is open and increment a counter and reset once the door closes. It sounds like you already have debounce circuitry to prevent glitches/noise on the I/O pin for switch bounce?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • Still LearningStill Learning Posts: 3
    edited 2007-02-22 23:56
    Hi Jeff and thanks, I have a 24vac control signal that controls a door. The 24vac signal is high to close the door low to open. I am using that same signal and connected it to terminals 1 and 2 of a digital I/O module. I have BS2 on a PCB w/breadboard. From the Vdd of the PCB(5vdc) I connected it to terminal 3 (for Logic supply to the module), Input pin, P0 to output terminal 4, (5vdc) and VSS (common) to terminal 5. The I/O module has a Schmitt Trigger for debounce. I have this same circuit connected on 4 modules using P0, P1, P2 and P3 on the PCB as inputs.

    Input P0 is for total count (low) door opening in a 24 hours. (one day)

    Input P1 is for (differant door), how long the input is high. (hours and minutes, total time) in a day. and maybe time of day the input is low and for how long.

    Input P2 is the same as P0, Differant door.

    Input P3 is the same as P1, Diffrent door.

    Please excuse the terminology, I want to take this slow so I can understand the code.

    I hope this makes sense.

    Thanks

    George

    " border="0">
    328 x 291 - 27K
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2007-02-23 17:38
    Hi George, your program is going to be relatively simple but what you really need to sort out is the hardware. The opto modules look fine for interfacing the open/close state of the doors. When it comes to keeping track of the date and the time you are going to need a real time clock module such as the DS1302 that Parallax sell.
    The information you need to provide your program will be 1 input for each door indicating whether it is open or closed and 1 input from the rtcc to allow you to time the open/closed state and or time stamp the collected data. I suggest you start by splitting the project in two (door states and time functions) and get familiar with the Pbasic routines for each piece. When you feel comfortable with the two parts it should be a snap to combine them into one program.

    Jeff T.
  • Still LearningStill Learning Posts: 3
    edited 2007-02-27 00:35
    Hi Jeff T. Thanks for the help and guidance. I down loaded "What is a Microprocessor" and "BS2 Manaul" holpfuly that will put some light on the subject for me. I think I'll start with the counting part of this. That sounds like it will keep me confused for a long time.

    George
Sign In or Register to comment.