Counting time via external pulses


Closed Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2007
    Posts
    26

    Default Counting time via external pulses

    Hello!

    I've have one thing to do, but my experiance is low in this area.....this is the deal, I have two pulses comming from electronic that is allready excist, when pulse A is comming I should count in one direction, and when pulse B comming I should count opposite.

    This is the deal, say on input A when I got pulse, controller should count, so every 12 counte's is one secound, after secound it goes minutes, houres normal, in case signal comes to input it should come same, but only in opposite direction. Probably is simple thing to do, but I don't have clue where to start, specially this part when time is included.

    thanks.

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default Re: Counting time via external pulses

    Pseudo code.

    IF PULSE THEN
    SEC = SEC + 1

    IF SEC = 60 THEN
    SEC = 0
    MIN = 1
    ...
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Aug 2007
    Posts
    26


    Did you find this post helpful? Yes | No

    Default Re: Counting time via external pulses

    I did that, now my main problem is counting backwards......problem is if I count backward evrytime secounds passes 59 to 00 minute raises for 1, same happend if I go backward, but if should decrese

    this is my code:

    loop1:
    if porta.1=0 then
    counter=counter+1
    if counter == 12 then
    sekunda = sekunda +1
    counter = 0
    endif
    if sekunda == 60 then
    minuta = minuta +1
    sekunda = 0
    endif
    IF minuta == 60 then
    sat = sat +1
    minuta =0
    endif

    goto lcd
    endif

    if porta.0=0 then
    if counter == 0 then
    counter = 12
    if sekunda == 0 then
    sekunda = 60
    endif
    sekunda = sekunda -1
    endif
    counter=counter-1
    goto lcd
    endif

    goto loop1

    lcd:

    lcdout $fe,$c0,dec2 counter,"TCR:",DEC2 sat,":", dec2 minuta,":",dec2 sekunda
    while (porta.0=0 or porta.1=0)ause 10:wend
    goto loop1

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts