Need little help with maths - Timer based application


Closed Thread
Results 1 to 3 of 3

Hybrid View

  1. #1

    Default Need little help with maths - Timer based application

    Hi, I am trying to create a timer application which tracks 30minutes, 1Hr, 1h30min, 2H, 2H30min. It does not need to be very precise, variation of upto a 2 seconds is fine.
    I am using 16f676 & using 16bit timer1 for this.
    PIC-timer calculator says interrupts are generated 524.295mSec @4Mhz & 1:8 prescaler.
    I have a word variable which works as a counter for interrupts & tells me that certain time has elapsed.
    My problem is that I am not sure if I have calculated the delayset values right as calculator disagrees with me.
    Code looks like this:

    Code:
    delay var word
    delaystop var word
    redled var porta.0
    ;---------INTERRUPTS DECLARED HERE------------------------------
    ASM
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
            INT_Handler    TMR1_INT,  _delaystop,   PBP,  yes
        endm
        INT_CREATE               ; Creates the interrupt processor
    ENDASM
    
    T1CON=$31
    
    ;-------------INTERRUPTS ENABLED HERE-----------------------------
    @   INT_ENABLE   TMR1_INT     ; Enable external (INT) interrupts
    while 1
    if button1 then
    delay=0 : delayset=2060 ; 30 minutes
    endif
    
    if button2 then
    delay=0 : delayset=4120 ; 1Hour
    endif
    
    if button3 then
    delay=0 : delayset=6180 ; 1Hr 30 minutes
    endif
    
    if button4 then
    delay=0 : delayset=8240 ; 2 Hours
    endif
    
    if button5 then
    delay=0 : delayset=10300 ; 2Hrs 30 minutes
    endif
    wend
    
    delaystop:
    delay=delay+1
    if delay=delaystop then
          redled=1
    endif
    @ INT_RETURN
    ___________________
    WHY things get boring when they work just fine?

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    30 minutes = 1,800 seconds:
    1800 / 0.524295 = 3433

    1 hour = 3,600 seconds:
    3600 / 0.524295 = 6866

    1.5 hours = 10299
    2 hours = 13732

    And maybe it's somewhere else in the program that wasn't posted, but ..
    It looks like you are adjusting the value in delayset according to the buttons.
    Then comparing the delay time against delaystop in the handler.

    Oh, and delaystop is both a variable and the Label to the Interrupt handler.
    <br>

    hth,
    Last edited by Darrel Taylor; - 19th June 2010 at 18:12. Reason: delaystop label
    DT

  3. #3


    Did you find this post helpful? Yes | No

    Default

    Got that!
    It is my typing mistake to put delay=delaystop in ISR, though it actually is delay=delayset
    Thanks
    ___________________
    WHY things get boring when they work just fine?

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