Timer program at Atom28

noob question.

but i dont find it at atom28 manual.

i have a digital input. this set me a bit.
i want start a timer. when the digital input doesnt come for 2 minutes.
then delet variable.
when pir is 2 minutes low then the LedC = 0

how to do that?

;--------------------------------------------------------------------
;[CONSTANDS]
TRUE con 1
FALSE con 0

piru con 1
pird con 0
;--------------------------------------------------------------------
;[INPUTS]

pir var bit
prev_pir var bit

;--------------------------------------------------------------------
;[OUTPUTS]

LedC var bit ;Orange

;--------------------------------------------------------------------
;[MAIN]
main:
;Button A
if (pir = pird) AND (prev_pir = piru) then
LedC = 1
endif

endif
gosub Readinput
gosub WriteLeds
goto main

;--------------------------------------------------------------------
;[ReadButtons] Reading input buttons from the ABB
ReadInput:
input P7

prev_pir = pir

pir = in7
return
;--------------------------------------------------------------------
;[WriteLEDs] Updates the state of the leds
WriteLEDs:

if ledC = 1 then
low p14
endif
return

Sorry, I don’t fully understand your question.

First do you have an Atom 28 or an Atom Pro 28?

I think you are asking to have the code look something like:

main:
    if (pir = pird) and (prev_pir = piru) then
        LedC = 1
    else if (I exceeded my timeout)
        LedC = 0
    endif
    ...
   Goto Main

Depending on how complex and accurate you wish to make the code you have several ways. One possible way is by a simple loop counter. When you get your start condition you set a counter to zero. Then each time you go through the loop you increment this counter. If this counter exceeds some number you go into your error condition. The loop counter value you error out on is something you may need to set by trial in error. i.e. you set it to some value, use a stop watch to time it and then adjust it until it is close to what you want.
Again Something like:

Timercount     var    unsigned long
fTimerActive    var    bit
...

fTimerActive = 0
Main:
    if pir <> prev_pir then
        ; The input changed
        if pir = pird then
            ; The input went high
            LedC = 1
            TimerCount = 0
            fTimerActive = 1
        else
           ; The input went low again
           fTimerActive = 0 
        endif
    else if fTimerActive = 1
        TimerCount = TimerCount + 1
        ; See if we exceeded our time out
        if TimerCount > 1000000L then
            LedC = 0
            fTimerActive = 0
        endif
        ... (read inputs and write leds...)
    goto main

I hope the above is reasonably clear. Note: I did not try to compile this nor did I verify that I had everything correct, but I think the basics are there.

A more complex way to do this is to setup a timer, such as WTIMER. There are some threads that cover this, such as the TV Brat under the Biped forum has a timer. Also there are threads in this forum that talk about Timer Ticks and processing interrupts on the Basic Atom Pro, which has sections on timers. You might try looking at a few of these posts and see if you wish to go this direction or not. If so some of us can help to show you a basic outline on how to do this.

Good Luck
Kurt

i have a atom 28 pro

i want make i timer…
when the sensor idle for 2 minutes then delet the led c.
when it comes a new input in this 2 minutes he timer starts again.

i need it for activate and disable the hexapod.

for when is somebody in room he stands up is ther nobody after 2 minutes he shutdown.

this code doesnt work… there is a problem on a else command.

thank you

just guessing but he is making a motion detector out of the hexapod, with a 2-minute inactivity timeout.

I will try to setup some of the basics for you and leave it to you to fill in the pieces. the CPU is running with a clock at 16,000,000 instructions per second (more or less) and you wish for a timeout at 120 seconds or 1,920,000,000 cpu cycles. So lets set up a wtimer at the Atom Pro. Look at the H8/3694 document that you can access from the tools menu of the IDE.

[code]
timer var unsigned long

timer = 0
ONINTERRUPT TIMERWINT,TimerWIntHandler
TCRW = (TCRW & 0x70) | 0x4 ;Sets TimerW to increment once
;every 8 clock cycles.
ENABLE TIMERWINT

fTimerActive = 0
Main:
if pir <> prev_pir then
; reset our time out.
TCNT = 0 ; reset the internal timer
timer = 0 ; reset the interrupt overflow count.

    ; The input changed 
    if pir = pird then 
        ; The input went high 
        LedC = 1 
    else 
       ; The input went low again 
       ;???
    endif 

else if timer >= 3662 then 
        LedC = 0 
        ; we have our two minute timeout.
endif 
   ... (read inputs and write leds...) 
goto main 

TimerWIntHandler :
timer = timer + 1
resume[/code]

I hope this works ok. Where did 3662 come from. If you multiply this by 8, which is the number of instructions per increment of the timer and you multiple this by 65536 which is the number of times TCNT can be incremented before you get a wtimer overflow you get:1919942656 clock cycles which gets you pretty close to 120 seconds (119.996)

Good Luck
Kurt