PDA

View Full Version : Counting time via external pulses



Marin
- 28th February 2011, 14:00
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.

mackrackit
- 28th February 2011, 20:55
Pseudo code.

IF PULSE THEN
SEC = SEC + 1

IF SEC = 60 THEN
SEC = 0
MIN = 1
...

Marin
- 28th February 2011, 22:37
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):pause 10:wend
goto loop1