PORTB + PORTC Interrupt-On-Change


Closed Thread
Results 1 to 28 of 28

Hybrid View

  1. #1
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,624


    Did you find this post helpful? Yes | No

    Default Re: PORTB + PORTC Interrupt-On-Change

    Hi Barry,
    So how often do you expect the inputs to change state? Thosands of times per second, once every week or perhaps somewhere in between?
    Do you need to detect BOTH edges of the signal or is either the rising or falling edge?
    Are the inputs asynchronous in nature or do they change "in sync" with each other?

    I'm asking because perhaps it can be done without interrupts, if a suitable chip isn't available.

    Another option to look into is one of the "port expander chips". I've never used them but I think some of them have IOC capabillity but then again it depends on the timing requirements etc.

    /Henrik.

  2. #2
    Join Date
    Apr 2011
    Location
    Welches, Oregon
    Posts
    198


    Did you find this post helpful? Yes | No

    Default Re: PORTB + PORTC Interrupt-On-Change

    There may also be the possibility that one might "snapshot" all the lines on an interrupt and then compare to the previous "snapshot" to determine which is the different state?

  3. #3
    Join Date
    Jan 2011
    Location
    Sydney, Australia
    Posts
    172


    Did you find this post helpful? Yes | No

    Default Re: PORTB + PORTC Interrupt-On-Change

    Hi Guys,

    Henrik:
    I am checking for break in continuity due to physical movement. My idea is to use weak pull-ups on one side of the data line and ground the other side. Any break in the line would cause a leading edge interrupt.
    Due to the mechanical nature of the test, any line could fail irrespective of the other lines. The test period is around 1 minute.
    The failure mode could be intermittent (ie momentary break in continuity) or permanent.
    The tests are more indicative than quantitative in that I want to know if one (or more) data lines are broken more often than others - the actual count does not need to be specifically accurate.
    Ideally there would be no failures during the test but hey, who lives in an ideal world? I has assigned WORD variables to all nine counters - just in case!

    Amoque:
    I am not sure how a snapshot would work considering any one of the nine data lines can generate the interrupt. What are you proposing?

    Cheers
    Barry
    VK2XBP

  4. #4
    Join Date
    Dec 2010
    Posts
    409


    Did you find this post helpful? Yes | No

    Default Re: PORTB + PORTC Interrupt-On-Change

    Use an external "OR" gate to generate the interrupt, then read the state of all the pins and increment the counter for the pin that has changed.
    Or you could use PIC16(L)F1526/7 but that's a lot of pins and a difficult package to deal with.

    FYI I found it using the part chooser on the Microchip site - I've never actually used the device.

  5. #5
    Join Date
    Jan 2011
    Location
    Sydney, Australia
    Posts
    172


    Did you find this post helpful? Yes | No

    Default Re: PORTB + PORTC Interrupt-On-Change

    Hi Charlie,

    I had thought about the "OR" gate option but I am not sure if the intermittent fault would last long enough to read the state of all the pins after the interrupt was triggered.
    The PIC16(L)F1526/7 still only has PORTB IOC as an option so all those other pins don't really help my cause.

    Thanks for taking the time to research other option though - greatly appreciated.

    Cheers
    Barry
    VK2XBP

  6. #6
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,624


    Did you find this post helpful? Yes | No

    Default Re: PORTB + PORTC Interrupt-On-Change

    Hi Barry,
    The question really is how short of an event you MUST be able to capture. If we're talking microseconds then you really NEED hardware interrupts. If we're getting up into millisconds or possibly the hundreds of microseconds range then a software aproach, in line with what I, and I think Amoque was saying, might work - YMMV.

    Here's something in the line of what I'm thinking
    Code:
    SignalLines VAR WORD                                    ' Current state of inputs
    oldSignalLines VAR WORD                                 ' Previous state of inputs
    Result VAR WORD                                         ' Result of XORing
    
    Counter VAR WORD[9]                                     ' 9 counters, one for each line
    idx VAR BYTE                                            ' Index variable
    
    ' Subroutine to poll and evalute the signal lines, GOSUB this periodically.
    Test:
        SignalLines.LowByte = PortB                         ' 8 lines on PortB and...
        SignalLines.Bit9 = PortC.0                          ' ...and one on PortC.0 for a total of 9.
    
        ' Any bit that is set in Result indicates a state change, 1->0 and 0->1.    
        Result = SignalLines XOR oldSignalLines
    
        ' Iterate thru the bits in result and increment the counter for each
        ' respective counter if the bit is set.
        For idx = 0 to 8                                    ' 9 bits, 9 counters
            Counter[idx] = Counter[idx] + Result.Bit0[idx]  ' Increment counter if bit is set
        NEXT
        
        oldSignalLines = SignalLines                        ' Clear any mismatch.
    
    RETURN
    Compiles but is not tested, meant as food for thought.

    /Henrik.

  7. #7


    Did you find this post helpful? Yes | No

    Default Re: PORTB + PORTC Interrupt-On-Change

    Henrik

    I though this would take ten pages of code and Darrels instant interrupts etc etc
    Then you condense it into about 10 lines.

    You are a master!!!

  8. #8
    Join Date
    Jan 2011
    Location
    Sydney, Australia
    Posts
    172


    Did you find this post helpful? Yes | No

    Default Re: PORTB + PORTC Interrupt-On-Change

    Hi Henrik,

    Thanks for the program suggestion and detailed explanation of how it works.
    Very nice and succinct code!

    I would like to be able to capture events in the single digit millisecond region as a worst case scenario.
    The XOR approach opens up more PIC options and I could use one with the fastest clock on offer.
    Would you have any idea how long this subroutine would take to complete with a clock speed of say 32MHz or the shortest time achievable between captured events?

    I have a bit of thinking to do before making a decision.

    Thank you all for your valuable input to this project.

    Cheers
    Barry
    VK2XBP

Similar Threads

  1. PortB Change Interrupts
    By backstabber in forum mel PIC BASIC Pro
    Replies: 17
    Last Post: - 8th October 2011, 04:52
  2. Replies: 10
    Last Post: - 24th September 2011, 19:09
  3. Replies: 6
    Last Post: - 12th March 2011, 14:11
  4. Returning from Int on PortB change
    By sheryl in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 11th December 2008, 19:09
  5. Interrupt portb
    By tazntex in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 18th August 2008, 22:05

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