Can I have interupts on any pin ?


Closed Thread
Results 1 to 22 of 22

Hybrid View

  1. #1
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    This is an example of what I mentioned earlier.

    I'll call it FAKE INTERRUPT

    It does have a latency of a little over a millisecond, but often it is plenty good enough to do what you need done. You can make the interrupt faster if you wish - but remember each time you enter/leave an interrupt, you are stealing quite a few processor cycles.


    This code will check the status of any pin once per millisecond. It was written for an 18Fxxxx at 40Mhz. This example is checking the status of PORTC.0.


    Code:
        Changed VAR BYTE
         OldPort VAR BYTE
          
         T0CON = %10001000 ; turn it on, 16 bits, no prescaler (osc/4)
            
         CLEAR 
    
    
    '-----------------  DT_INTS section ----------------------------        
           
            INCLUDE "DT_INTS-18.bas"        
            INCLUDE "ReEnterPBP-18.bas"     
    ASM
         INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
                  INT_Handler    TMR0_INT,   _FakeInt,   PBP,  yes 
              endm
        INT_CREATE           
    ENDASM
    
    
    Goto OverInt
    
    '------------------ Timer 0 interrupt handler-----------------------------------
    
    
    FakeInt:
            
             TMR0H = $D8  ; Preload depends on clk speed
             TMR0L = $F7  ; One millesecond timeout at 40Mhz. 
                          ; Always load HIGHBYTE FIRST
                                  
             Changed = PortC ^ OldPort 
             IF Changed.0 = 1 THEN     ; Pick your pin
                 OldPort = PortC
                 ;;;;  Whatever you want to do when Port bit changes
             ENDIF     
             
    @ INT_RETURN         
    
    
    Overint:
      
      OldPort = PortC    ; Init the var
    
    @ INT_ENABLE TMR0_INT
    
    
    NormalProgramLoop:
    
       
    
        Goto NormalProgramLoop
       
      END
    Charles Linquist

  2. #2
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Here's a schematic for 13 pins with interrupts using just two interrupt-on-change pins.
    Attached Images Attached Images
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  3. #3
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Bruce View Post
    Here's a schematic for 13 pins with interrupts using just two interrupt-on-change pins.
    At Post#3, I was trying to explain the same method.

    --------------------------
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  4. #4
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    At Post#3, I was trying to explain the same method.
    That's what reminded me I had the schematic...;o)
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  5. #5
    Join Date
    Dec 2004
    Location
    Scarborough UK
    Posts
    77


    Did you find this post helpful? Yes | No

    Smile

    WoW guys & gals, im overwhelmed with the response to this, thank you all very much.
    Some of your ideas I have considdered, like a diode to the B0 pin, but I dont think that would work for my app, I need to have as many pins as input as possible which i think is about 33 at most on the 18f4550 (and 2 pins could fire at the same time), I will take a closer look at some of your suggestions on my day off work, it looks like some of it involves assembler which I dont get :-(, but Im sure I will pick something out of your ideas :-), Im just wondering if just polling the pins would be fast enough @ 20mhz, I'm gonna give all your ideas a try this w/end and see what works, thx
    Reading the datasheet & understanding it are two different things.

  6. #6
    Join Date
    Dec 2004
    Location
    Scarborough UK
    Posts
    77


    Did you find this post helpful? Yes | No

    Smile

    Just an afterthought,
    do all pic micro ports/pins have internal pull up resistors ?, i've been looking at the 18f4550 datasheet but cant tell ?, maybe i'm just stupid or tired lol :-)'

    Thanks
    Last edited by Bonxy; - 11th March 2010 at 22:25.
    Reading the datasheet & understanding it are two different things.

  7. #7
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default

    No, internal pullups applys only to portB.

    Al.
    All progress began with an idea

  8. #8
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by aratti View Post
    No, internal pullups applys only to portB.

    Al.
    Some other PICs have pull-ups on PORTA, too. I was not aware of this fact until recently.
    Edit: For example, 16F630.

    Quote Originally Posted by Bonxy View Post
    .... (and 2 pins could fire at the same time....
    What does it matter?
    If one or the other interrupts, you will get into interrupt routine anyway whether two interrupts occur at the same time or not (which I think is very close to impossible !)

    While you are in interrupt routine, check the status of all pins, then act based on each of their tasks.

    Something like >
    Code:
    RB0_Int: 'we are now in interrupt routine.
    A = 0
    B = 0
    C = 0
    D = 0
    ..
    ....
    .......
    IF Pin1 = 0 THEN A = 1 ' Pin1 seems to be interrupted.
    IF Pin2 = 0 THEN B = 3  'Ohh, Pin2 also seems to interrupted.
    ....
    .......
    Last edited by sayzer; - 12th March 2010 at 08:56.
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

Similar Threads

  1. Is this a K Type sensor?
    By jessey in forum mel PIC BASIC Pro
    Replies: 20
    Last Post: - 21st November 2009, 13:55
  2. DS1820 with 16f688
    By jessey in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 23rd May 2009, 05:07
  3. Advice-scrutiny for my serial controller
    By kevlar129bp in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 13th December 2008, 17:11
  4. Microcontroller with 2 way paging application problem
    By oneohthree in forum mel PIC BASIC Pro
    Replies: 30
    Last Post: - 20th April 2007, 17:27
  5. Another RTC, DS1287
    By DavidK in forum Code Examples
    Replies: 0
    Last Post: - 12th December 2006, 17:07

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