Elapsed Timer Demo


Closed Thread
Results 1 to 40 of 112

Hybrid View

  1. #1
    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,
      Darrel
    Last edited by Darrel Taylor; - 4th November 2005 at 20:11.

  2. #2
    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

  3. #3
    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

  4. #4
    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

  5. #5
    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 11:51.

  6. #6
    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 07:05.
    DT

  7. #7


    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?

  8. #8
    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 04:44.

Similar Threads

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

Members who have read this thread : 2

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