Elapsed Timer Demo


Closed Thread
Page 1 of 3 123 LastLast
Results 1 to 40 of 112
  1. #1
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959

    Default Elapsed Timer Demo

    Elapsed Timer Demo

    Attached to this post is a Zip file that contains a "Drop-In" elapsed timer that uses Timer1 and interrupts. It's waaay down there at the bottom of all this dribble. This may get rather long winded, so my first suggestion is to scroll down to the bottom of this post and check out the file then come back and read this post later.

    --------------------- ----------------------- -----------------------------
    The files contained in the Zip are:

    Test_Elapsed_SER.pbp ' Demo of Elapsed Timer using serout2 command and HyperTerminal
    Test_Elapsed_LCD.pbp ' Demo of Elapsed Timer using an LCD
    Elapsed.bas ' Elapsed Timer include file
    ASM_INTS.bas ' Assembly language Interrupt Stubs

    Note: These files are intended to be used on 14-bit core PICS (12F, 16C and 16F) that have a TIMER1 module.
    Note2: They are written for use as the only interrupt in the program. If you need to use other interrupts as well, the program will have to be modified before it will work.
    Note3: It will NEVER work in conjunction with PBP's ON INTERRUPT statement.

    In it's simplest form, this is all it takes to use the Elapsed Timer:
    Code:
        Include "Elapsed.pbp"
        Gosub ResetTime    ' Reset Time to  0d-00:00:00.00
        Gosub StartTimer   ' Start the Elapsed Timer
    This will create a Clock counting at 1/100 seconds. It runs in the background of PBP without any other program intervention required.

    The time is kept in the variables:
    Code:
        Ticks    var byte   ' 1/100th of a second
        Seconds  var byte   ' 0-59
        Minutes  var byte   ' 0-59
        Hours    var byte   ' 0-23
        Days     var word   ' 0-65535
    The time can be easily displayed with a single line:
    Code:
        LCDout $FE,2, dec Days,"d-",dec2 Hours,":",dec2 Minutes,":",dec2 Seconds
    For each of the variables (Seconds, Minutes, Hours and Days) there is a flag that indicates when the value of that variable has changed.
    The Flags are:
    Code:
        SecondsChanged   var bit
        MinutesChanged   var bit
        HoursChanged     var bit
        DaysChanged      var bit
    So, if you wanted to display the time like a clock, you could wait until SecondsChanged = 1, display the time, then reset the flag.
    Code:
        Loop1:
            if SecondsChanged = 1 then
               LCDout $FE,2, dec Days,"d-",dec2 Hours,":",dec2 Minutes,":",dec2 Seconds
               SecondsChanged = 0
            endif
        Goto Loop1
    If you only wanted to display the time each minute instead of every second just do the same thing using the MinutesChanged flag.
    Code:
        Loop1:
            if MinutesChanged = 1 then
               LCDout $FE,2, dec Days,"d-",dec2 Hours,":",dec2 Minutes<br>           MinutesChanged = 0
            endif
        Goto Loop1
    The timer can be Stopped and Started, like a stopwatch.
    Code:
        Gosub StopTimer
        Gosub StartTimer
    --------------------- ----------------------- -----------------------------
    The Elapsed.bas include file also Includes another file, ASM_INTS.bas This file can also be used in your other programs as well. It handles the "Context Saving" that is required for any Assembly language interrupt.

    It contains 2 macros:
    INT_START
    Saves the W, STATUS, PCLATH and FSR registers. This can be used at the beginning of your Interrupt routine.

    INT_RETURN
    Restores the W, STATUS, PCLATH and FSR registers after the Interrupt routine is finished and then returns from the Interrupt (RETFIE).

    Using it in a normal Assembly language interrupt might look something like this:

    Code:
        Define  INTHAND  INT_CODE    ' Tell PBP Where the code starts on an interrupt
    ASM
    INT_CODE
        INT_START                ' Save Context
            ... Your Interrupt routine goes here ...
        INT_RETURN               ' Restore Context
    EndAsm
    Well, I guess that covers most of it. if I've missed anything, or you still have questions, please don't hesitate to ask.

    Happy holidays,
    Attached Files Attached Files
    Last edited by Darrel Taylor; - 10th June 2013 at 21:12.

  2. #2
    Bob_W's Avatar
    Bob_W Guest


    Did you find this post helpful? Yes | No

    Default

    Cool piece of code. I noticed something trying to use it..... I'm using a 12F675 at 4 mhz. I noticed that the ticks were incrementing at 1/4 the rate they were supposed to. Upon fishing around I thought about the fact that there's a 1:1, 1:2, 1:4, and 1:8 prescaler on this part, as well as many others. Forcing the prescaler off makes it count correctly. Just curious.... what part did you use when you wrote this?


    Update... Nevermind.... I had left piece of my code in place that messed with the prescaler.
    Last edited by Bob_W; - 3rd September 2005 at 23:42.

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


    Did you find this post helpful? Yes | No

    Default

    That's the closest thing to "Hey it works" that I've gotten after it being here almost 2 years.

    Thanks Bob!
    DT

  4. #4
    Bob_W's Avatar
    Bob_W Guest


    Did you find this post helpful? Yes | No

    Default

    Ok.... "Hey it works" Really well, I might add! A couple questions..
    In elapsed.bas you've got:
    if Ticks = 100 then
    Ticks = Ticks-100
    Is there a reason you subtract 100 instead of zeroing Ticks?

    The question arises from a little excursion I had because of of the results I got doing subtraction to detect and handle rollovers. I found out that the first section evaluates true because of the unsigned nature of the math. I wound up reversing the sections and verifying the result for the rollover test wasn't > 255. Is there a better way. Also, what's the instruction count offset between 0x10000 - ((clock_freq / 4) /100) It looks like it's 7.

    tmr is 80 Ticks sample at beginning of 500 ms interval
    Ticks is 20 Ticks value now....

    (The forum removed all my indentation, so it looks wierd)


    ms100 = ticks
    IF ms100 - tmr >= 50 THEN
    GOSUB lptoggle
    ELSE
    IF ms100 < tmr THEN
    IF (ms100 + 100) - tmr >= 50 THEN
    GOSUB lptoggle
    END IF
    END IF
    END IF
    RETURN

    lptoggle:
    Toggle 0
    RETURN

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


    Did you find this post helpful? Yes | No

    Default

    Is there a reason you subtract 100 instead of zeroing Ticks?
    Not really. The original program used ON INTERRUPT, and there was a possibility that Ticks might be higher than 100 by the time it got around to calculating the time. But when I switched it over to ASM interrupts, it wasn't needed anymore. Just never changed it.

    And for the ms100 routine, I can't figure out what you're trying to do there.

    If tmr = 80 then (ms100 - tmr >= 50) will be True when ms100 is between 0-79. So the output will be toggled on every loop. Then for 80-99 the (ms100 < tmr) will never evaluate True since it's always >= 80.

    Maybe if you explained what you're trying to do, we can come up with something that'll work.
    <br>
    DT

  6. #6
    Bob_W's Avatar
    Bob_W Guest


    Did you find this post helpful? Yes | No

    Default

    Basically, I want to turn something on - like an LED (later it will actually be a 7 HP siren with a longer on and off time) for 500 ms. I go through all the decision process to decide it should be turned on. Then....

    I save the current ticks value - tmr - # of ticks at start, which is 16 for this grab.

    I turn on the port - for the test program, I'm just toggling an LED at 500 ms intervals.

    I come out of the main program loop every pass to see if I have expired my timer. Get current ticks - ms100 - we'll say I get 65 for this grab.

    Sooo... IF ms100 - tmr >= 50 THEN 65 - 16 = 49.... almost there..

    Where you run into the problem is if you grab, say 80 for tmr.

    For 500 ms to elapse, you'd have to roll over the 100 mark. So, if you try to do the test IF ms100 - tmr >= 50 THEN with tmr = 80, and ms100 = 10 it evaluates true because, under pic math 10 - 80 = 250, or 65391 if you look at all 16 bits. So I figured out that you have to test to see if ms100 (the current tick value) is less than tmr (the tick value when you started timing) and if so, add 100 to the ms100 before subtracting tmr to see if it's 50 or better elapsed.

    Sure you do timing with pause, but you can't look at change of state while you wait for pause to expire. Your timing routine makes it possible watch inputs, and manipulate and time multiple outputs at the same time.

    I used to run into this when doing timing in vbdos. Seconds was easy - if you wound up with a negative, just add 86400.

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


    Did you find this post helpful? Yes | No

    Default

    Well, I was hoping for more of what the program needs to do, instead of why it doesn't work the way you have it. But if I make a few assumptions I guess we can go from there.

    Assumption 1 - The only thing the elapsed timer will be used for, is timing the 500ms periods.

    Assumption 2 - The on/off cycle times are the same. 500ms ON, 500ms OFF. And repeats continuously untill it's determined that it needs to stop.

    I believe the key here is in Starting the Elapsed Timer at the beginning of the alarm cycle so that it always starts at 0. That way you don't have to subtract the starting Ticks count from the current Ticks count. Al you'll need to do is test if it's less than 50.

    Something like this...
    Code:
    Clear
    
    Include "Elapsed.pbp"
    
    AlarmOUT VAR PORTB.0
    AlarmON  VAR BIT
    
    ;----------------------------
    MainLoop:
    ; Somewhere in here determine when to turn on/off alarm
    ; and Gosub to either StartAlarm or StopAlarm
    
        if AlarmON and (Ticks < 50) then
           HIGH AlarmOUT       ' Alarm ON  
        else
           LOW  ALARMOUT       ' Alarm OFF
        endif
    Goto Mainloop
    
    ;----------------------------
    StartAlarm:
        Gosub ResetTime    ' Reset Time to  0d-00:00:00.00    
        Gosub StartTimer   ' Start the Elapsed Timer
        AlarmON = 1
    Return
    
    ;----------------------------
    StopAlarm:
        Gosub StopTimer
        AlarmON = 0
    Return
    HTH
    <br>
    DT

  8. #8
    Bob_W's Avatar
    Bob_W Guest


    Did you find this post helpful? Yes | No

    Default

    The 500 ms on, 500 ms off is just an LED for testing your code. The beauty of your timer routine is that you can time multiple things at the same time......

    Example...
    Siren is running in first of four blasts - timing the on and off interval... WHILE...

    Timing to see it someone is holding down the stop button more than 2 seconds.... WHILE timing to see how long it's been since activation, so we refuse to activate again if it's been less than, say , 5 minutes, so if the tones are sent over the air again, we don't drive the neighbors nuts.... ETC..


    And, that's just this project.


    Thanks.....

  9. #9
    jessey's Avatar
    jessey Guest


    Did you find this post helpful? Yes | No

    Default

    Hi Darrel

    I am trying to use your Elapsed Timer in a thermostat program using a DS1820 chip. My thermostat code compares a user set value to the temperature reading which turns a relay on/off accordingly. I'd like to be able to use your timer as a stop watch to record the total time that the heater is on for. I was really surprised and also delighted to see that your elapsed timer code only uses 139 words! My code by itself seems to work flawlessly but when I include your elapsed code then the temperature isn't consistent, as in, every so often it toggles the heater relay off then back on again ever so briefly.

    I'm thinking that the interrupt is giving me a false temperature reading by corrupting the read. Could you suggest anything I could try to alleviate this? Also, I noticed that you use DEC2 in your LCDOUT command for your timer code, what does the DEC2 command relate to? I've seen that being used in some code before but I don't understand what it's used for. Could you or someone else here explain why and when you'd use the DEC2 or 3 or 4 commands? I've included my thermostat code so you can see how I have your timer set up.

    Thanks
    jessey
    Attached Files Attached Files
    Last edited by jessey; - 4th November 2005 at 11:25.

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


    Did you find this post helpful? Yes | No

    Default

    Hiya Jessey,

    That's the only bad part about interrupts. They Interrupt things.

    And when you have something with very strict timing requirement such as 1-Wire devices, they just don't go together very good.

    Probably the easiest way to remedy the situation is to just turn-off the interrupts when reading the sensor. This may cause a small amount of error to accumulate in the Timer routine, but if you keep the Temp readings to a minimum, it shouldn't even be noticible, maybe add a second a month or so.

    Other than that, using a syncronous device like I2C or SPI will eliminate the problem all together.

    HTH,
    &nbsp;&nbsp;Darrel
    Last edited by Darrel Taylor; - 4th November 2005 at 21:11.

  11. #11
    jessey's Avatar
    jessey Guest


    Did you find this post helpful? Yes | No

    Default Having trouble turning the asm interrupt off/on

    Hi Darrel,

    Well I figured out what the DEC2 command is for, it adds an extra 0 to the display which disappears when the variable is > 9, so I'm guessing it's just added to give the Lcd that digital clock look, which is cool. Now if I could just figure out how to turn off/on your interrupts? I thought it would be as simple as adding PIE1.0 = 0:INTCON.6 = 0:INTCON.7 = 0, for overflow, peripheral and global interrupts just before reading the DS1820 then after the read setting them back to 1 but with no success. When I do that it takes about 10 seconds for the clock to increment?

    Then I implemented a counter in the mainloop and added an IF...THEN to only read the temperature about once every second or so as you suggested and that just wrecks havoc with the temperature reading, making it fluctuate wildly. I tried to make sense of the asm interrupts by reading the manual and searching the archives but to no avail. This experience really has me scratching my head. One thing that's for sure, is that using interrupts can be a scary thing and are not for the faint of heart! How would I go about turning the interrupts off and then back on again? Any further help would be greatly appreciated.

    Thanks
    jessey

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


    Did you find this post helpful? Yes | No

    Default

    Oops, sorry, forgot to answer that part. (DEC2)

    You should only have to reset GIE before reading the sensor.

    INTCON.7 = 0
    OWIN ....
    INTCON.7 = 1

    Not sure what you did with the counter so I can't imagine what happened there.
    <br>
    DT

  13. #13
    jessey's Avatar
    jessey Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor
    Oops, sorry, forgot to answer that part. (DEC2)

    You should only have to reset GIE before reading the sensor.

    INTCON.7 = 0
    OWIN ....
    INTCON.7 = 1

    Not sure what you did with the counter so I can't imagine what happened there.
    <br>

    Hi Darrel,

    That's great, I sure appreciate it, I'll give it a try tomorrow for sure.

    Thanks Again
    jessey

  14. #14
    jessey's Avatar
    jessey Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor
    Oops, sorry, forgot to answer that part. (DEC2)

    You should only have to reset GIE before reading the sensor.

    INTCON.7 = 0
    OWIN ....
    INTCON.7 = 1

    Not sure what you did with the counter so I can't imagine what happened there.
    <br>

    Hi Darrel,

    I tried as you suggested and it's still giving me major problems. The counter does increment but it takes about 50 seconds to increment each second. The temperature seems to function ok, as when I touch the DS1820 it does increase the temp reading without any delays and all the buttons are working ok to enter the other subroutines and I can reset your clock ok as well.

    The only function that doesn't work, is that the heater doesn't shut off when the temperature is equal to or greater that the set reference that's suppose to shut it off.

    I have a Tocks counter that Gosubs the counter in the mainloop that's keeping time as well and it's functioning ok and keeping the proper time so it's a real puzzler. I tried "INTCON.7 = 0" before checking the temp and then instead of "INTCON.7 = 1" to turn it back on I used "Gosub StartTimer" figuring that something wasn't set proper, but still no go.

    It has to be something in the mainloop that's causing the havoc. I noticed that when I enter another subroutine from the mainloop that your clock counts the time ok because if I time the seconds that I'm out of the mainloop and when I return, then your counter has counted the time correctly and I can see the time has advanced on the Lcd.

    I've spent a couple of late nights going through my code thinking that I've got something in it that might be interfering with your counter but came up empty.

    I went through the data sheet again for the 16f877 and still can't figure it out. Would you have any ideas on what's happening to cause this? I've included my code this time and if you get a chance to look at it sometime I'd surely appreciate it.

    Thanks
    jessey
    Attached Files Attached Files
    Last edited by jessey; - 9th November 2005 at 12:51.

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


    Did you find this post helpful? Yes | No

    Default

    The DS1820 takes 750 ms to do a conversion.

    In this section here, you have the interrupts turned off the whole time while waiting 3/4 of a second for it to finish. Missing a few (75) interrupts.
    Code:
    Update_The_Temperature:
    
             INTCON.7 = 0 ' Disables all interrupts
             OWOut DQ, 1, [$CC, $44]              ' Start temperature conversion
             waitloop:OWIn DQ, 4, [count_remain]  ' Check for still busy converting
             IF count_remain = 0 THEN waitloop
             OWOut DQ, 1, [$CC, $BE]              ' Read the temperature
             OWIn DQ, 0, [temperature.LOWBYTE, temperature.HIGHBYTE, Skip 4, _ 
                                                       count_remain,count_per_c]
             'Gosub StartTimer
             INTCON.7 = 1 ' Enables all unmasked interrupts
       RETURN
    Since you have the Elapsed timer going, maybe you could send the convert command, then go back 1 second later and read the results. "Quickly"
    <br>
    Last edited by Darrel Taylor; - 10th November 2005 at 08:05.
    DT

  16. #16


    Did you find this post helpful? Yes | No

    Default

    Darrel,

    I'm trying this code on an 877 and it work great, nice job. I would however like to run it on a 452 or a 4620. What would I have to change for this? I was looking thought the files and came across the lines:

    Code:
      IF OSC == 4                       ; Constants for 100hz interrupt from Timer1
    TimerConst = 0D8F7h                 ; Executed at compile time only
      EndIF
      If OSC == 8
    TimerConst = 0B1E7h
      EndIF
      If OSC == 10
    TimerConst = 09E5Fh
      EndIF
      If OSC == 20
    TimerConst = 03CB7h
      EndIF
    What would these be if I wanted to say run a PLL at 4 MHz or a PLL at 10 MHz?

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


    Did you find this post helpful? Yes | No

    Default

    The easiest way to figure out the constant at any OSC is to use the Timer Calc form at ...
    http://www.picbasic.co.uk/forum/showthread.php?t=2031

    For instance, in the form, enter 4 in the OSC field, then put 100 in the bottom Freq field. Press Calculate, and it shows that it takes 10,000 "Ticks" of the timer. And the number to reload into the Timer on each interrupt is 55543, or 0D8F7h This is the same number shown in the ASM section you listed, for 4Mhz.

    That's 65536 - 10000 + 7

    7 is the number of instructions used to reload the timer. (Elapsed.bas : ADD2_TIMER)

    So, just plug in the new OSC value (Any crystal or PLL Freq) and enter 100 in the FREQ field. The new constant can be added to the ASM section of Elapsed.bas.

    Also, I have a version of "Elapsed" for the 18F's. I'll send it, later tonight, when I get off work.

    L8R,
    Darrel
    Last edited by Darrel Taylor; - 7th December 2005 at 05:44.

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


    Did you find this post helpful? Yes | No

    Default Elapsed-18.bas

    Here's the version for 18F's.

    It should be a drop-in replacement for the old version. Everything works the same, except for the registers saved on entry to the INT routine.

    So, you can still use the Test_Elapsed_LCD/SER.bas demo's from the original version for testing. Just add the "-18" to the INCLUDE line.
    <br>
    Attached Files Attached Files
    Last edited by Darrel Taylor; - 7th December 2005 at 07:39.
    DT

  19. #19


    Did you find this post helpful? Yes | No

    Default

    It works like a charm, thank you vary much. Now I can finish making my waterbed temperature controller.

  20. #20
    Join Date
    Jul 2005
    Posts
    65


    Did you find this post helpful? Yes | No

    Smile To Darrel

    Hi Darrel

    I was wondering if elapsed timer code is accurate enough to make a digital clock and calender, showing time and date.

    Thanks

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


    Did you find this post helpful? Yes | No

    Default

    Hi crematory,

    That depends on the accuracy of the crystal being used, and the ambient temperature.
    And, you'd probably need to have some kind of backup battery, to keep it going during any power outages.

    I think I calculated it at around +/- 4 minutes per year with a standard 20mhz crystal. It was around 20 seconds/year with one of those temperature compensated TTL Oscillators.
    <br>
    DT

  22. #22
    Join Date
    Jul 2005
    Posts
    65


    Did you find this post helpful? Yes | No

    Smile

    Quote Originally Posted by Darrel Taylor
    Hi crematory,

    That depends on the accuracy of the crystal being used, and the ambient temperature.
    And, you'd probably need to have some kind of backup battery, to keep it going during any power outages.

    I think I calculated it at around +/- 4 minutes per year with a standard 20mhz crystal. It was around 20 seconds/year with one of those temperature compensated TTL Oscillators.
    <br>

    4 Minutes a year, that is more than acceptable for me, I will be happy with that in deed.

    I was wondering if you can through a hint for using the rest of interrupts in the PIC when using the elapsed timer code, shall I use your way to handle other interrupts, or what should I exactly do.

    Thanks Darrel

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


    Did you find this post helpful? Yes | No

    Default

    I've been working on something that'll answer that question, but it's still in bits and pieces right now. I guess it's time to finish it.

    Give me a couple days to put it together. Hopefully it'll be worth the wait.
    <br>
    DT

  24. #24
    Join Date
    Jul 2005
    Posts
    65


    Did you find this post helpful? Yes | No

    Thumbs up That amazing Darrel

    Darrel,

    I will be waiting for the answer.



    Good luck

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


    Did you find this post helpful? Yes | No

    Default

    Almost there. &nbsp; I keep getting sidetracked.

    I hope you're using MPASM. I've been unable to make it work with PM.
    <br>

  26. #26
    Join Date
    Jul 2005
    Posts
    65


    Did you find this post helpful? Yes | No

    Smile

    Hi Darrel

    MPASM would never be a problem, I always keep tracking the new versions of microchip compiler (MPASM), as being almost there, I hope you finish it as soon as possible

    Thanks alot

  27. #27
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    In fact, i don't know why PM still exist since it doesn't work anyway with any 18Fs. I always use MPASM.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  28. #28
    Join Date
    Jul 2004
    Posts
    8


    Did you find this post helpful? Yes | No

    Default Elapsed-18

    Hi Darrel,

    I got this message after compiling my program. I'm using Pic18F452 & PicBasic Pro Ver 2.46a

    Error[113] C:\MPLAB\PICBASIC\PBPPIC18.LIB 1154 : Symbol not previously defined (_ClockCount)


    Thank You.
    Last edited by mazlan; - 20th March 2006 at 09:47.

  29. #29
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,795


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mister_e
    In fact, i don't know why PM still exist since it doesn't work anyway with any 18Fs. I always use MPASM.
    Hmm, what are the changes one have to make so the program be compatible with MPASM (other than the DEFINES) ?

    Thanks
    Ioannis

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


    Did you find this post helpful? Yes | No

    Default

    mazlan,

    Since the ClockCount subroutine is in the same file as the Define that assigns it to the interrupt handler, it's unlikely that it can't find the label.

    Unless, you've edited the files or tried to paste the stuff into you're main program instead of using the Include files. In which case I have no way to know what you've done.

    DT

  31. #31
    Join Date
    Jul 2004
    Posts
    8


    Did you find this post helpful? Yes | No

    Smile Elapsed-18

    I'm using the original include files and didn't change anything. Now it's ok. After deleting the space between INTHAND and _ClockCount, everything's OK. Actually, i'm new in microchip assembly.

    Thank You. :-)

  32. #32
    Eng4444's Avatar
    Eng4444 Guest


    Did you find this post helpful? Yes | No

    Unhappy With PIC16F876A...

    How to make the first version of the program works for PIC16F876A with a 4 line LCD?

    Could anyone help me??

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


    Did you find this post helpful? Yes | No

    Default

    1. Set the DEFINEs to match your hardware.

    2. Add CMCON = 7 if using PORTA

    3. compile and run.
    <br>
    DT

  34. #34
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    And ===> Adcon1=7
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

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


    Did you find this post helpful? Yes | No

    Default

    Hi Steve,

    ADCON1 = 7 was already in the "Test_Elapsed_LCD.pbp" program.

    Just need to add the CMCON for the 87x"A" varieties.

    DT
    <br>

  36. #36
    Eng4444's Avatar
    Eng4444 Guest


    Did you find this post helpful? Yes | No

    Exclamation One question..

    This might sound strange for some of you and stupid for others... but i'll say it again, i do not have any previous knowledge in all this...

    i already asked how to make it work for PIC16876A with a 4 lines LCD.

    i got : 1. Set the DEFINEs to match your hardware.

    2. Add CMCON = 7 if using PORTA

    3. compile and run.

    i'm thankful for this.. but at that time, i didn't pay attention to what was written in the first post! :

    " Note2: They are written for use as the only interrupt in the program. If you need to use other interrupts as well, the program will have to be modified before it will work. "

    then, i opened the .zip file and found...4 files!

    ASM_INTS.BAS
    ELAPSED.BAS
    TEST_ELAPSED_LCD.pbp
    Tets_elapsed_ser.pbp

    So what to do with all these......? where to download each of them?....

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


    Did you find this post helpful? Yes | No

    Default

    Naaa. Don't bother.

    Try Melanie's Olympic timer instead (cheers Darrel, you keally know how to make friends - Melanie). It doesn't have the ASM stuff to worry about.

    Or Paul's clock that doesn't even need interrupts.

    DT
    <br>

  38. #38
    Join Date
    Jun 2006
    Posts
    3


    Did you find this post helpful? Yes | No

    Default

    Just wanted to say thanks, works great on a 16F690.

    I was going to modify your program a bit, I have an application which uses count down timers, but I thought I should check with you, I noticed a copyright on the code.

    Thanks,
    Mike

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


    Did you find this post helpful? Yes | No

    Default

    Hi Mike,

    Glad it's working.

    No problem with the copyright.
    You're free to use it any way you want. Well, except posting it somewhere saying you wrote it
    DT

  40. #40
    Join Date
    Jun 2006
    Location
    Bangalore, India
    Posts
    136


    Did you find this post helpful? Yes | No

    Question Having trouble getting accuracy

    Hi Darrel,
    I tried making a LCD clock with calender with the elapsed timer code, but the clock runs nearly 2 seconds slow per day.
    I've made some modifications to the Elapsed_INT.bas.txt file so attached that also with my code ...
    I dont know how to fix this error...
    What should i do?... try tweeking the TimerConst or something???
    Attached Files Attached Files

Similar Threads

  1. Instant Interrupts - Revisited
    By Darrel Taylor in forum Code Examples
    Replies: 772
    Last Post: - 17th February 2016, 23:14
  2. Get elapsed time while TIMER samples pulses
    By RodSTAR in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 27th March 2009, 17:27
  3. Elapsed Timer Demo in a PIC12F675
    By Leonardo in forum mel PIC BASIC Pro
    Replies: 16
    Last Post: - 21st November 2008, 01:01
  4. Totally Baffled with Elapsed Timer
    By CocaColaKid in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 11th June 2008, 22:01
  5. Darrel Taylor Elapsed Timer
    By rwskinner in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 13th March 2008, 02:22

Members who have read this thread : 4

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