Rodo55

RS08KA2 two hour delay timer

Discussion created by Rodo55 on Sep 8, 2009
Latest reply on Sep 9, 2009 by Rodo55

I'm a novice and I'm looking for help on a two hour delay timer for a project I'm working on.

I'm using a RS08KA2 MC and it doesn't have a RTC so I've nested loops to create a long delay but it isn't very accurate. Does anyone know how to implement a long delay in the KA2 that may be easier to implement and more accurate? I've looked at AN3413 Low Cost digital timer but it ties in a ADC and I can't seem to understand the code.

 

Below is what I've done to get a long delay and it works but seems like a very bad way to do it.

I included all the code since it's such a small program.

 

Any advice would be appreciated,

 

Thanks,

Rod

 


  ORG RAMStart
counter:        DS.B  1
counter2:      DS.B  1          
counter3:      DS.B  1
time2:          DS.B  1

; Const Section
ConstSection:  SECTION
time:           DC.B  $FF
 
; Code Section

            ORG ROMStart
   
;*******************************************************************************************
; Peripheral Initialization
;*******************************************************************************************
init:

;CONFIGURES SYSTEM CONTROL
    mov #HIGH_6_13(SOPT), PAGESEL 
    mov #$03, MAP_ADDR_6(SOPT)      ; Disables COP, enables BKGD (PTA3) and RESET (PTA2)                                 

;CONFIGURES CLOCK (FEI Operation Mode)        
    mov #HIGH_6_13(NV_ICSTRM),PAGESEL 
    lda MAP_ADDR_6(NV_ICSTRM)        
   sta ICSTRM                      ; Sets trimming value  
   clr ICSC1                         ; Selects FLL as clock source and disables it in stop mode
   clr ICSC2                         ; ICSOUT = DCO output frequency  
wait_clock:
    brset CLKST,ICSSC,wait_clock      ; Waits until FLL is engaged
   
;CONFIGURES TIMER
    mov #$70, MTIMSC                    ; Enables interrupt, stops and resets timer counter
    mov #$FF, MTIMMOD                 ; MTIM modulo = 256 counts before interrupt
    mov #$08, MTIMCLK                  ; Selects fBUS as reference clock (8 MHz)


;CONFIGURES I/O CONTROL PORT    
    mov #$31, PTADD                   ; Configures PTA0, PTA4 and PTA5 as output,PTA1 as an Input
    mov #HIGH_6_13(PTAPE), PAGESEL 
    mov #$04, MAP_ADDR_6(PTAPE)       ; Enables Pull UP on PTA2  

;CONFIGURES KEYBOARD INTERRUPTS (KBI)
    mov #$00, KBIES                   ; Selects Falling Edge/Low on Pin
    mov #$02, KBIPE                   ; PTA1 as KBI input
    mov #$06, KBISC                   ; Clears any false interrupts
   
   
    clr PTAD                          ; Clears PTA port
    rts

 

 

;*******************************************************************************************
; Entry Point
;*******************************************************************************************
_Startup:
main:
    bsr init
    clr counter
    clr counter2
    clr counter3

main_loop:

loopRelay:
   
    mov #HIGH_6_13(SIP1),PAGESEL        
    brset 4,MAP_ADDR_6(SIP1),RelayOn      ;If button pushed goto Relay on
   
    bra loopRelay
                                                ;No push button continue to wait
RelayOn:
    bset 2, KBISC                         ;Clear KBI Interrupt
    bset 5, PTAD                          ;Turn on Relay LED
    bset 4,PTAD                           ;Turn on Relay

 

;BELOW IS THE NESTED DELAY LOOPS I USED  

 

StartDelay:
    mov #$60,MTIMSC

    bclr 4,MTIMSC                         ; Start MTIM counter

    wait
    lda counter
    cbeqa #255,Delay2
    inc counter
    bra StartDelay

Delay2:
    clr counter
    lda counter2
    cbeqa #55,Delay3
    inc counter2
    bra StartDelay
   
Delay3:
    clr counter
    clr counter2
    lda counter3
    cbeqa #57, RelayOff
    inc counter3
    bra StartDelay

 

RelayOff
    clr counter
    clr counter2
    clr counter3
    bclr 5,PTAD
    bclr 4,PTAD
    bra loopRelay

Outcomes