Semi-random INT count???


Closed Thread
Results 1 to 7 of 7

Hybrid View

  1. #1
    Join Date
    May 2013
    Location
    australia
    Posts
    2,641


    Did you find this post helpful? Yes | No

    Default Re: Semi-random INT count???

    lets have a word var count and a word var pos
    count is the one used in your isr , pos will be the " current " position outside the isr

    we have a sub to get pos
    getpos:

    @ INT_DISABLE INT_INT
    POS= COUNT
    @ INT_ENABLE INT_INT
    RETURN

    now whenever you wish to use pos just call getpos first to "refresh" its value


    some more thoughts
    1 are your encoders mechanically switched ( ie contact bounce could be an issue)
    2 isr's should be kept as short a possible , lcd routines in isr may cause unexpected issues
    3 have you tesed with only one encoder is connected ?
    4 have you a schematic of your setup and a link to the positioner encoder data sheet

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default Re: Semi-random INT count???

    Hi,
    A schematic would be nice but I think we've covered this before. Two encoder signals on the same pin, fighting each other, is most likely not a good solution. You mention a relay, switching between the two, and that should be fine. Just make sure the signal at the PIC input is well defined (pulled up/down) and not floating at any point.

    And Richard is spot on. If the frequeuncy of the encoder signal is anything above "a couple of Hz" you definitely do not want the LCDOUT statements within the ISR. Those two statments takes at least 5ms to exectute, then there's the rest of the ISR itself (which isn't much but still...) and the system variable save/restore. But let's say 5ms (and that's probably on the LOW side) then your input frequency can't be higher than 200Hz.

    If you have a two channel scope you can test this.
    1) Scope the input signal to the PIC with channel 1 on the scope.
    2) Set a pin high at the beginning of the ISR. Set it LOW at the end of the ISR.
    3) Scope this output of this pin with channel 2 on the scope.

    The time between the rising edge on Ch1 and the rising edge on Ch2 is the interrupt latency, the time it takes to save the system vars and "get to" the actual ISR code.
    The pulse width on Ch2 is the execution time of the ISR itself.
    Then there's the time it takes to restore the system vars and "get out" of the ISR. This is pretty much equal to the measured latency.

    Add the numbers together, ie 2*latency + ISR execution time and see what you get. Make sure you do this with a LOW(ish) input frequency to ENSURE you're not "overrunning" yourself. Then remove the LCDOUT statements from the ISR and measure again.

    /Henrik.
    Last edited by HenrikOlsson; - 24th June 2014 at 06:35.

  3. #3


    Did you find this post helpful? Yes | No

    Default Re: Semi-random INT count???

    OK, bummer! My debugging was buggy.... Those are only there for the moment to see where I am. My fastest encoder, according to the scope is running about 50-60 hz. So that may be the problem. I'm headed out the door, but I'll try to deal with it when I get back this afternoon and see how it goes. I am still skeptical though, since it was the slow encoder that first showed the problem, and I still cant see how it would go from 3500 counts in say 120 seconds, all the way up to multiple WORD stackoverflows in the same time from this issue, but maybe I just still dont see the big picture....

Similar Threads

  1. is random really not so random?
    By mrpackethead in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 4th November 2011, 01:57
  2. Random
    By ruijc in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 16th March 2011, 12:49
  3. Using both hardware int and Timer Int together?
    By ozarkshermit in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 6th January 2010, 01:09
  4. Random
    By SELTZER in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 13th April 2006, 16:48
  5. Poor mans "semi" logic analyzer
    By anj in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 21st September 2004, 13:26

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