Shop OBEX P1 Docs P2 Docs Learn Events
on the right track? — Parallax Forums

on the right track?

Hi folks. Here is my·program project. I wanted some input as to whether my program framework made sense enough to pursue coding it(described below):

I want to program my SX-48 as a triple-split 16-bit stopwatch·measuring HI signals arriving at three different pins at three arbitrary times within a 65535 count loop.·My program·will scan three pre-designated PINs for HI signals in·the·loop. As each·HI signal·is successively detected, a status variable·is incremented by one, the 16 bit split·value is stored, and the pin that detected a HI is set to output.·The program will ignore scanning a PIN set to output to avoid duplicate times. The loop will terminate when the status variable is binary 3 or 65535 is exceeded.

It is possible, however improbable, that 2 or 3 of the times will arrive at the same time. But that does not matter too much to me at the moment. I also realize that a HI signal may occur while other program instructions are being executed, which may or may not be a significant source of error.

jumpin.gif
DSRO

Comments

  • BeanBean Posts: 8,129
    edited 2005-11-26 08:10
    What is the purpose of setting the pin to an output ?
    I guess alot depends on how accurate you need the measurement to be and what speed the counter is.
    Overall it sound do-able.
    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "SX-Video·Module" Now available from Parallax for only $28.95

    http://www.parallax.com/detail.asp?product_id=30012

    "SX-Video OSD module" Now available from Parallax for only·$49.95
    http://www.parallax.com/detail.asp?product_id=30015

    Product web site: www.sxvm.com

    Those that would give up freedom for security will have neither.
    ·
  • edited 2005-11-27 04:06
    Thanks Bean. I need a flag to tell my program that says "hey, you counted this HI pin already, don't stop the stopwatch for this one again, scan the remaining PINS for changes." I am hijacking the port pin direction register as a status register for my own uses. The convienence is that the direction port register is physically tied to a particular Pin.

    I'll be running the counter at 14 MHz.

    MR. DSRO
  • PJMontyPJMonty Posts: 983
    edited 2005-11-27 07:46
    If your three pins are all on the same port, just use an "AND" mask to verify if a bit is set or not. Let's say you use bits 0,1 and 2 on port B. Read port B, then do an AND with a mask of 7 (or in binary %00000111). If none of the pins are high, the value of the AND will be zero. If any are high, you will have a value greater than zero. This gives you a quick way to see if any of the pins has changed. If they have, then use individual masks of 1, 2, and 4 to check each bit in isolation to find the specific one that changed.

    Once you know that a specific bit has changed, just remove that bit from the master "AND" mask. For example, if bit 1 is set, then your mask goes from 7 (in binary %00000111) to 5 (in binary %00000101), which will automatically ignore bit 1.

    If you're not familiar with boolean operators like AND and OR and how they are used to check or set bits, then now is the time to do some research and get up to speed. Once you do, you'll find you can easily handle bit operations.
      Thanks, PeterM
  • edited 2005-12-01 04:18
    Thanks PJ. Thats a good idea. Also thanks to Bean for weighing in. I'll look at those boolean ops.

    DSPRO
Sign In or Register to comment.