element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
NXP Semiconductors
  • Products
  • Manufacturers
  • NXP Semiconductors
  • More
  • Cancel
NXP Semiconductors
Forum any advice about RS08KA2 two hour delay timer?
  • Blog
  • Forum
  • Documents
  • Events
  • Quiz
  • Polls
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join NXP Semiconductors to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Verified Answer
  • Replies 1 reply
  • Subscribers 39 subscribers
  • Views 361 views
  • Users 0 members are here
Related

any advice about RS08KA2 two hour delay timer?

Former Member
Former Member over 16 years ago

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,

 

=====================================================================================
  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

  • Sign in to reply
  • Cancel
Parents
  • Former Member
    0 Former Member over 16 years ago

    Hello Smile,

     

    Using the MTIM for such a long time delay, I might suggest -

    1. Use XCLK (16kHz) as the MTIM source, rather than the bus clock.
    2. Set the prescale value to maximum (256), to increase the overflow period as much as possible.

    With these settings, the MTIM clock frequency should be 62.5 Hz, assuming the reference clock is properly trimmed. Now for a free-running MTIM, the overflow period should be 4.096 seconds. However, if the MTIMMOD value were to be set to decimal 249, the overflow period should be exactly 4.0 seconds, which may be more convenient to work with.

     

    A two-hour timeout period now requires that decimal 1800 overflows should occur, and this requires a 16-bit counter. Consider the following untested code snippet:

     

    DELAY EQU   1800

    count DS.W  1

     

    ...


    StartDelay:

         mov   #(DELAY/256),count   ; High byte

         mov   #(DELAY%256),count+1 ; Low byte

         mov   #$60,MTIMSC          ; Start MTIM counter

         mov   #HIGH_6_13(SIP1),PAGESEL

    loop1:

         wait

         brclr 2,MAP_ADDR_6(SIP1),loop1 ; Wait for MTIM overflow

     

         mov   #HIGH_6_13(MTIMSC),PAGESEL

         bclr  7,MAP_ADDR_6(MTIMSC)     ; Clear flag 

     

         lda count+1 ; Decrement word value

         bne next1

         dec count

    next1:

         dec count+1

         lda count   ; Test for timeout

         ora count+1

         bne loop1   ; Loop if not timeout

     

         ; Do timeout action here

     

     

    Regards,

     

    Simon

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Reject Answer
    • Cancel
Reply
  • Former Member
    0 Former Member over 16 years ago

    Hello Smile,

     

    Using the MTIM for such a long time delay, I might suggest -

    1. Use XCLK (16kHz) as the MTIM source, rather than the bus clock.
    2. Set the prescale value to maximum (256), to increase the overflow period as much as possible.

    With these settings, the MTIM clock frequency should be 62.5 Hz, assuming the reference clock is properly trimmed. Now for a free-running MTIM, the overflow period should be 4.096 seconds. However, if the MTIMMOD value were to be set to decimal 249, the overflow period should be exactly 4.0 seconds, which may be more convenient to work with.

     

    A two-hour timeout period now requires that decimal 1800 overflows should occur, and this requires a 16-bit counter. Consider the following untested code snippet:

     

    DELAY EQU   1800

    count DS.W  1

     

    ...


    StartDelay:

         mov   #(DELAY/256),count   ; High byte

         mov   #(DELAY%256),count+1 ; Low byte

         mov   #$60,MTIMSC          ; Start MTIM counter

         mov   #HIGH_6_13(SIP1),PAGESEL

    loop1:

         wait

         brclr 2,MAP_ADDR_6(SIP1),loop1 ; Wait for MTIM overflow

     

         mov   #HIGH_6_13(MTIMSC),PAGESEL

         bclr  7,MAP_ADDR_6(MTIMSC)     ; Clear flag 

     

         lda count+1 ; Decrement word value

         bne next1

         dec count

    next1:

         dec count+1

         lda count   ; Test for timeout

         ora count+1

         bne loop1   ; Loop if not timeout

     

         ; Do timeout action here

     

     

    Regards,

     

    Simon

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Reject Answer
    • Cancel
Children
No Data
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube