Timer Interrupt to exit a closed loop


Closed Thread
Results 1 to 8 of 8

Hybrid View

  1. #1
    Join Date
    Oct 2004
    Location
    North Norfolk UK
    Posts
    146


    Did you find this post helpful? Yes | No

    Default

    Hi Darrel,

    Thanks just got your reply, although I using the comparators to feed the CCp modules. As you say the cmp interrupt is on *any change on either comparator*

    so i am using the cmp as a sort of interrupt on change on both analog pins. It is then inportant to disable the cmp interrupt as soon as possible. I did have one comaparator output (the one i felt most probable to set) linked to portb internal interrupt but it oscillated like crazy, I get little or no bounce using this setup. I had been disabling the cmp_int "inside" it own handler routine but felt that this was bad practice (any thought?)which I why I try to keep the sub routines as simple as posible ie Z=1 or Z=2.

    I have tried introducing delays without using pause (small count loops) to allow the interrupt disable to settle.

    but I guesss that whilst I have been concentrating on timer0 as the culprit I should be back looking at CMP_INT to see if there is any way this could be responsible. But this loopback is happening 206ms after I have disabled CMP.

    I also check that Z variable that I use as a progress gate is not corrupted, that is to say that even though Z = 1 the program is passing through a conditional IF's that should prevent it, confused........ I am totally.

  2. #2
    Join Date
    Oct 2004
    Location
    North Norfolk UK
    Posts
    146


    Did you find this post helpful? Yes | No

    Default

    well it looks as if I have found a workaround, it seems as if the first line after the
    @ INT_ENABLE CMP_INT is being ignored furthermore placing Z = 0 at any position from start to the @ INT_ENABLE CMP_INT will also cause a problem so I have to place a dummy line after the enable and everything works as it should do....... or so it appears on the surface to.
    Code:
    @ INT_ENABLE  CMP_INT 
    Z = 0                             'dummy line ignored
    Z = 0
    Waiting:
    if Z = 0 then Waiting
    I have only one variable in the example. I do not think I can face it but I have a feeling that I may have to check the stability of all my variables before and after an interrupt implementation .

    I have just pulled the whole house down to find a needle ......... but for the want of that needle.... I am cold wet and have nothing to cook on!!!

    think I will go down the road and post a christmas card to myself

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


    Did you find this post helpful? Yes | No

    Default

    I had been disabling the cmp_int "inside" it own handler routine but felt that this was bad practice (any thought?)
    That's the correct way.
    Comparators can give many interrupts right at the point where it switches (hundreds even, if the analog signal is slow). If it's allowed to return from the interrupt without disabling, it'll end up right back in the handler again until it's past the switching point of the comparator. External hysterisis can be added to the comparator to eliminate that, but it's not needed in this case.

    Also, much like the PORTB change interrupt, you should read the CMCON register inside the handler to end the mismatch condition. Typically, the handler would do that anyways to determine which comparator fired.

    And,
    before enabling the comparator the first time. Read CMCON, then Reset the interrupt flag.
    Then be sure to clear it again before re-enabling later. The flag may have been set during the time it was Disabled.

    that I may have to check the stability of all my variables before and after an interrupt implementation
    No need,
    Nothing happens to your other variables during an interrupt, unless you specifically change them in the handler.
    <br>
    DT

  4. #4
    Join Date
    Oct 2004
    Location
    North Norfolk UK
    Posts
    146


    Did you find this post helpful? Yes | No

    Default

    Hi Darrel

    Thankyou for your help..., again. I was experiencing occasional hysterisis whilst using the internal comparators but by slightly increasing the speed of the analog signal along with placing two bypass caps on each VDD pin of the MCU the internal bounce was brought easily under control.


    By executing strict good housekeeping with respect to the flags and reading the cmcon register as you advised (it is in the Datasheet) together with re-setting all the registers prior to re-enabling I now have all six interrupts functioning perfectly within the same sub-routine and all being disabled upon exit. I am delighted and relieved, i almost feel a poem coming on but I note you recently penned something apt.

    I can fly effortlesly ..... so until I have to learn how to land I am enjoying the moment.

Similar Threads

  1. Elapsed Timer Demo
    By Darrel Taylor in forum Code Examples
    Replies: 111
    Last Post: - 29th October 2012, 18:39
  2. Controlsystem for compact sporting (clay shooting)
    By Fredrick in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 30th July 2009, 17:48
  3. Can't ID interrupt source with this IntHandler??
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 3rd June 2009, 03:35
  4. Using input from Switch to control a loop
    By MrRoboto in forum mel PIC BASIC
    Replies: 9
    Last Post: - 2nd February 2009, 06:02
  5. Serial Relays
    By tazntex in forum General
    Replies: 3
    Last Post: - 17th May 2007, 18:42

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