PORTB + PORTC Interrupt-On-Change


Closed Thread
Results 1 to 28 of 28

Hybrid View

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

    Default PORTB + PORTC Interrupt-On-Change

    Hi All,

    I am working on a new project which requires monitoring 9 data lines for an interrupt on change (IOC).
    All the program really needs to do is count the number of interrupts on each line, increment individual counters for each occurrence and display the results to a 4x20 LCD display.
    PIC16F1829 has ten IOC lines but doesn't have enough I/O ports for the rest of the project.
    I could find no search criteria on the Microchip web site for IOC and PIC16F1829 is the best option I have been able to find thus far.

    Can anyone suggest an alternate PIC that would handle at least 9 IOC channels PLUS an additional 6 I/O's for 4x20 LCD and 3 I/O's for switches?

    I understand a serial LCD display would free up a number of I/O's on the PIC16F1829 for switch functions but I am trying to avoid going down that path unless absolutely necessary.

    All suggestions, or alternate recommendations on how to perform the same task, would be greatly appreciated.

    Cheers
    Barry
    VK2XBP

    P.S. I also need two ADC lines - just to make it interesting...
    Last edited by Aussie Barry; - 17th March 2014 at 09:58. Reason: Additional requirement

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


    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.

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

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

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

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

  7. #7
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,604


    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.

Similar Threads

  1. PortB Change Interrupts
    By backstabber in forum mel PIC BASIC Pro
    Replies: 17
    Last Post: - 8th October 2011, 03:52
  2. Replies: 10
    Last Post: - 24th September 2011, 18:09
  3. Replies: 6
    Last Post: - 12th March 2011, 13:11
  4. Returning from Int on PortB change
    By sheryl in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 11th December 2008, 18:09
  5. Interrupt portb
    By tazntex in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 18th August 2008, 21: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