1ms Elapsed Timer Demo with DT's Instant Interrupts


Closed Thread
Results 1 to 22 of 22

Hybrid View

  1. #1
    Join Date
    Jan 2013
    Location
    Texas USA
    Posts
    229

    Default 1ms Elapsed Timer Demo with DT's Instant Interrupts

    Recently on this forum there was an inquiry on how to setup an Elapsed Timer using Darrel Taylor's
    Instant Interrupts "DT_INT-14.bas" to work at 1ms resolution.

    Some time ago I had created just such a project for my own purposes.
    I thought it might be worth sharing with the larger audience here.

    *** First of all let me start by saying that Darrel gets all of the credit for this project. ***

    His development of DT's Instant Interrupts for PBP and his initial Elapsed Timer demo were the basis for my project.
    I merely made some minor changes to the Elapsed Timer demo to achieve what I needed.

    I have attached a zip file with all of the independent files including DT's Instant Interrupt include files.

    The project zip file includes (5) files:
    1. NewElapsed_Demo.pbp v1.10 (My Elapsed Timer Demo main program)
    2. ElapTimer_Interrupt.pbp v1.0 (My version of DT's Elapsed_INT.bas)
    3. DT_INTS-14.bas v1.10 (This file has NOT been modified)
    4. ReEnterPBP.bas v3.4 (This file has NOT been modified)
    5. README.txt (Some Installation information)

    My code files are commented fairly well, especially within the "ElapTimer_Interrupt.pbp" file,
    which is based on DT's file, "Elapsed_INT.bas", and where I made my modifications.

    The project was created, compiled and tested with PBP v3.0.7.4 and MPASM v8.90.

    Other than making changes to support a 1ms Timer1 Interrupt period in the ElapTimer_Interrupt file,
    I also incorporated modifications to the same file that were inspired by DT's "Elapsed_INT-18.bas" v1.2 file
    which he created an Elapsed Demo project for 18F series PICs.
    There were some excellent improvements he made that simplifies the use of the file.
    Most notably, the removal of hard-coded TimerConst reload values for OSC frequencies.

    The project displays an LCD clock with the following output:
    dd-hh:mm:ss.mmm

    dd = days
    hh = hours
    mm = minutes
    ss = seconds
    mmm = milliseconds

    With the LCDOUT execution time being what it is, the milliseconds display will not increment by a single ms; however, the Timer1 interrupt is
    firing at 1ms intervals and recording the number of elapsed milliseconds.
    Rather, it will increment by a few ms.


    In the spirit of Darrel's generosity to all of us here, I hope some may find this project helpful.

    ElapsedDemo_1ms.zip
    Regards,
    TABSoft

  2. #2
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: 1ms Elapsed Timer Demo with DT's Instant Interrupts

    To do the digit lookups for 7 segment LEDs, you’d need to print and delay for Human vision all digits of the clock for every millisecond.
    It’s a tough call, but the delay can be shorter the faster the multiplex is cycling.
    For LCDs if I recall correctly the delays for writes were in microseconds, but were pretty high numbers.

    I might have to take a look just to see how much instruction time is left between each ISR.

  3. #3
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: 1ms Elapsed Timer Demo with DT's Instant Interrupts

    Ok so the LCD write command must get interrupted, and is fine to continue the rest of the display
    with updated values after the interrupt, or the entire display would never get written.
    In that case you’re checking & clearing MSecsChanged for nothing,
    and might as well go hard at printing the display though that’s not the time consumer.

    I’m sure the LCD command can be used quicker in BASIC, but as you say it’s the LCD delays the main holdup.

  4. #4
    Join Date
    Jan 2013
    Location
    Texas USA
    Posts
    229


    Did you find this post helpful? Yes | No

    Default Re: 1ms Elapsed Timer Demo with DT's Instant Interrupts

    I have made a few updates to the ElapTimer_Interrupt.pbp include file for this demo.
    The new version is 1.1.

    Updates:
    v1.1 04/06/2015:
    1. Added "TcRem" compile-time asm variable.
    Used to test for Interrupt Time Accuracy during compile phase.
    2. Added compiler test/message for Interrupt Timer Accuracy.
    3. Added compiler test/error for TimerConst variable overrun.

    ElapTimer_Interrupt.pbp.txt

    Don't forget to rename the file by removing the ".txt" at the end of the filename.
    Regards,
    TABSoft

  5. #5
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: 1ms Elapsed Timer Demo with DT's Instant Interrupts

    Hi

    I was looking through your version and come across this again, as is also in DT’s original code:
    Code:
    ; -----------------  ADD TimerConst to TMR1H:TMR1L
    ADD2_TIMER   macro
        CHK?RP  T1CON
        BCF     T1CON,TMR1ON           ;  1 InstCycle, Turn off timer
        MOVLW   LOW(TimerConst)        ;  1 InstCycle
        ADDWF   TMR1L,F                ;  1 InstCycle, Reload timer with correct value
        BTFSC   STATUS,C               ;  1 or 2 InstCycles
        INCF    TMR1H,F                ;  1 InstCycle
        MOVLW   HIGH(TimerConst)       ;  1 InstCycle
        ADDWF   TMR1H,F                ;  1 InstCycle
        endm
    I am wondering about a few things like why this is here:
    Code:
        BTFSC   STATUS,C               ;  1 or 2 InstCycles
    Depending on the carry status after the add, we would still have 8 instructions, because if the skip takes
    two instructions, it skipped a line that would have taken another instruction.

    I don’t understand why it’s necessary. If the ISR is called on timer overflow, then even if it is not zero
    by the time it’s reset, it should be a known value, and not have to be checked.

    This somehow looks like it’s setup as if the ISR was called a variable time after the overflow interrupt which should never happen.
    I think there is something I’m not seeing, and the code it so simple, there must be a reason, otherwise it’s easily fixed.

    I’m seeing error when I use a 10MHz crystal to generate a 1Hz LED pulse, and get it roughly synced (visible to Human) with
    the output of a GPS pulse per second signal. After an hour I can see a difference between the two blinking LEDs,
    which for a Human to see, would probably take some ms difference.
    There could be error in my code, but I doubt that as I have only interfaced with DT’s timer,
    or I have a terrible crystal, or board layout (very likely because the crystal is mounted to a two pin header to make it removable,
    or crystals just really are that bad.

  6. #6
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: 1ms Elapsed Timer Demo with DT's Instant Interrupts

    Ok, so if you had other interrupts enabled, some timer ticks may have occurred before this routine?
    I have only used the Elapsed Timer, and done others manually.

    I hope you don’t mind discussion in your thread Tabsoft..
    if another thread is needed, that’s ok, but I’m thinking some discussion is needed.

    Incidentally, and not so related to this because DT does it slightly different... It appears MC don’t run their own samples:

  7. #7
    Join Date
    Jan 2013
    Location
    Texas USA
    Posts
    229


    Did you find this post helpful? Yes | No

    Default Re: 1ms Elapsed Timer Demo with DT's Instant Interrupts

    Art,

    Tying to respond to your PM, but your inbox is full....
    Regards,
    TABSoft

Similar Threads

  1. DT's Instant Interrupts
    By andywpg in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 1st June 2014, 18:01
  2. Elapsed Timer Demo
    By Darrel Taylor in forum Code Examples
    Replies: 111
    Last Post: - 29th October 2012, 17:39
  3. DT's Instant Interrupts trouble
    By Tomexx in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 24th November 2008, 20:48
  4. Elapsed Timer Demo in a PIC12F675
    By Leonardo in forum mel PIC BASIC Pro
    Replies: 16
    Last Post: - 21st November 2008, 00:01

Members who have read this thread : 2

You do not have permission to view the list of names.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts