Instant Interrupts - Revisited


Closed Thread
Results 1 to 40 of 773

Hybrid View

  1. #1
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default PIC16F616, Interrupt on PORTA change

    Not sure if this have been covered, but however. I'm actually working with a PIC16F616, there's no interrupt on PORTB change on this one, but Interrupt on PORTA change, great Microchip

    From what i see, it is not included in DT_INTS-14, so here's one method to do so...

    Open DT_INTS-14, and add the sections in Red
    Code:
    ASM
      #define INT_INT   INTCON,INTF     ;-- INT External Interrupt
      #define RBC_INT   INTCON,RBIF     ;-- RB Port Change Interrupt
      #define RAC_INT   INTCON,RAIF     ;-- RA Port Change Interrupt
      #define TMR0_INT  INTCON,T0IF     ;-- TMR0 Overflow Interrupt 16F
      #define TMR1_INT  PIR1,TMR1IF     ;-- TMR1 Overflow Interrupt
      #define TMR2_INT  PIR1,TMR2IF     ;-- TMR2 to PR2 Match Interrupt
      #define TX_INT    PIR1,TXIF       ;-- USART Transmit Interrupt
      #define RX_INT    PIR1,RCIF       ;-- USART Receive Interrupt
      #define CMP_INT   PIR2,CMIF       ;-- Comparator Interrupt
      #define EE_INT    PIR2,EEIF       ;-- EEPROM/FLASH Write Operation Interrupt
      #define BUS_INT   PIR2,BCLIF      ;-- Bus Collision Interrupt
      #define PSP_INT   PIR1,PSPIF      ;-- Parallel Slave Port Read/Write Interrupt
      #define AD_INT    PIR1,ADIF       ;-- A/D Converter Interrupt
      #define SSP_INT   PIR1,SSPIF      ;-- Master Synchronous Serial Port Interrupt
      #define CCP1_INT  PIR1,CCP1IF     ;-- CCP1 Interrupt
      #define CCP2_INT  PIR2,CCP2IF     ;-- CCP2 Interrupt
    
    ENDASM
    
    asm
    INT_Source  macro  IFR, IFB, IER, IEB
        if ((IflagReg == IFR) && (IflagBit == IFB))
      list  
    INT_Flag_Reg = IFR
    INT_Flag_Bit = IFB
    INT_Enable_Reg = IER
    INT_Enable_Bit = IEB
    Found = YES
        endif
    ;  nolist  
        endm 
    endasm
    
    
    asm
    ;-------------------------------------------------------------------------------
    GetIntInfo  macro  IflagReg, IflagBit
    
    Found = NO
    ; nolist
      ifdef INTF    ;----{ INT External Interrupt }----------------[INTCON, INTF]---
          INT_Source  INTCON, INTF, INTCON, INTE
      endif
      ifdef RBIF    ;----{ RB Port Change Interrupt }--------------[INTCON, RBIF]---
          INT_Source  INTCON, RBIF, INTCON, RBIE
      endif
      ifdef RAIF    ;----{ RA Port Change Interrupt }--------------[INTCON, RAIF]---
          INT_Source  INTCON, RAIF, INTCON, RAIE
      endif
      ifdef T0IF    ;----{ TMR0 Overflow Interrupt }-------------[INTCON, TMR0IF]---
          INT_Source  INTCON, T0IF, INTCON, T0IE
      endif
      ifdef TMR1IF  ;----{ TMR1 Overflow Interrupt }---------------[PIR1, TMR1IF]---
          INT_Source  PIR1, TMR1IF, PIE1, TMR1IE
      endif
      ifdef TMR2IF  ;----{ TMR2 to PR2 Match Interrupt }-----------[PIR1, TMR2IF]---
          INT_Source  PIR1, TMR2IF, PIE1, TMR2IE
      endif
      ifdef TXIF    ;----{ USART Transmit Interrupt }----------------[PIR1, TXIF]---
          INT_Source  PIR1, TXIF, PIE1, TXIE
      endif
      ifdef RCIF    ;----{ USART Receive Interrupt }------------------[PIR1 RCIF]---
              INT_Source  PIR1, RCIF, PIE1, RCIE
      endif
      ifdef CMIF    ;----{ Comparator Interrupt }--------------------[PIR2, CMIF]---
          ifdef PIR2
              INT_Source  PIR2, CMIF, PIE2, CMIE
          else
              INT_Source  PIR1, CMIF, PIE1, CMIE
          endif
      endif
      ifdef EEIF    ;---{ EEPROM/FLASH Write Operation Interrupt }---[PIR2, EEIF]---
          ifdef PIR2
              INT_Source  PIR2, EEIF, PIE2, EEIE
          else
              INT_Source  PIR1, EEIF, PIE1, EEIE
          endif
      endif
      ifdef BCLIF   ;----{ Bus Collision Interrupt }----------------[PIR2, BCLIF]---
          INT_Source  PIR2, BCLIF, PIE2, BCLIE
      endif
      ifdef PSPIF   ;--{ Parallel Slave Port Read/Write Interrupt }--[PIR1, PSPIF]--
          INT_Source  PIR1, PSPIF, PIE1, PSPIE
      endif
      ifdef ADIF   ;----{ A/D Converter Interrupt }------------------[PIR1, ADIF]---
          INT_Source  PIR1, ADIF, PIE1, ADIE
      endif
      ifdef SSPIF  ;----{ Master Synchronous Serial Port Interrupt }--[PIR1, SSPIF]-
          INT_Source  PIR1, SSPIF, PIE1, SSPIE
      endif
      ifdef CCP1IF ;----{ CCP1 Interrupt }-------------------------[PIR1, CCP1IF]---
          INT_Source  PIR1, CCP1IF, PIE1, CCP1IE
      endif
      ifdef CCP2IF ;----{ CCP2 Interrupt Flag }--------------------[PIR2, CCP2IF]---
          INT_Source  PIR2, CCP2IF, PIE2, CCP2IE
      endif
        
      list
        endm
      list  
    ENDASM
    Sure enough there's some other PIC with interrupt on PORTA change, I just never came across one... or maybe... but never used that feature yet
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  2. #2
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default

    Oops - double post....removed.
    Last edited by HankMcSpank; - 19th May 2009 at 14:25.

  3. #3
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default

    mister_e.... I'd like to get interupts working on my 16F690 ....I visited Darrel's website & on the very first example "Hello World", he shows the code along with a short schematic - the interupt is showing as being presented on port RBO (actually called RBO/INT on the diagram).

    I have some (newbie!) questions...

    Are Darrel's interput routines for a specific PIC?

    I ask because my PIC 16F690 doesn't even have an RB0(!), therefore to my next question....

    Is there a particular PIC pin I should be using for his routines to work.

    My end goal is quite simple...I have an encoder wheel with 48 black stripes that I'm having one helluva job getting the polling right....I'd simply like to be able to use a PIC interupt for when each black stripe passes the photo transistor 'pickup' (to increment a PIC counter)

    That said, for testing puproses I do need one more interupt ...this being for a magnetic switch (I've glued a magnet to the edge of the disc so I know when the wheel has turned once) to interupt once per rev, I can then make sure that the PIC 'saw' all the stripes for the past rev....so to my other question - is there normally just one INT pin that's useable for externally triggered interupts on a PIC (specifically a 16F690)

    i'd dearly love to be able to use Darrel's simple routines...but I'm a little clueless wrt ensuring I'm connecting my incoming 'pulses' to the correct PIC 16F690 pins!

    edit: Darrel has kindly replied to the earlier PM I sent him, telling me that I need to look for the pin marked 'INT'...which on my PIC 16F690 is apparently pin RA2 - tks Darrel!
    Last edited by HankMcSpank; - 19th May 2009 at 14:24.

  4. #4
    Join Date
    Mar 2006
    Location
    China
    Posts
    266


    Did you find this post helpful? Yes | No

    Default Use T?CKI

    Hi,

    If you have a T?CKI pin on your pic you can use that pin to check for black stripes. This is the pin for the external clock signal connected to the internal timer/counter. This way you can get an interupt every black stripe or every 2:nd or once per wheel rotation (or anything else more or less). This is all depending of what you preload the counter with. If you have a 8-bit counter and load FF into it, next clock pulse will overflow the counter and you will get an interupt. If you preload it with FF-(dec 48) it will overflow once every full rotation of the wheel.

    If you just want to count the stripes preload it with 0 and off you go....

    This way your PIC will do most of the counting by itself and giving you more instruction time for something more useful.

    If you use the RA2/INT for the magnetic switch you can use RA5/T1CKI the external clock input for the stripes phototransistor

    /me
    Last edited by Jumper; - 19th May 2009 at 15:00.

  5. #5
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Jumper View Post
    Hi,

    If you have a T?CKI pin on your pic you can use that pin to check for black stripes. This is the pin for the external clock signal connected to the internal timer/counter. This way you can get an interupt every black stripe or every 2:nd or once per wheel rotation (or anything else more or less). This is all depending of what you preload the counter with. If you have a 8-bit counter and load FF into it, next clock pulse will overflow the counter and you will get an interupt. If you preload it with FF-(dec 48) it will overflow once every full rotation of the wheel.

    If you just want to count the stripes preload it with 0 and off you go....

    This way your PIC will do most of the counting by itself and giving you more instruction time for something more useful.

    If you use the RA2/INT for the magnetic switch you can use RA5/T1CKI the external clock input for the stripes phototransistor

    /me
    Thanks...there's some top tips there.

    Just a thought here - is it even possible to get reliable results with mechanical switches & interupts?

    By this I mean, a mechanical switch normally needs a debounce, else you'd get more than one interupt for every time the switch 'settled'? In my situation, it's importnat that there's just one 'trigger' for every revolution of the encoder wheel (so I can establish how many interupts/black stripes the PIC has counted over one rev)...if I used an interupt for the magnetic switch, there'd be a possibility of not just one interupt...but several in quick succession...which will cause a bit of 'fog' whilst trying to confirm that my wheel, circuit & PIC are all in sync & counting 48 stripes per turn!

    By the way...I've now dabbled with Darrel's "Hello World" which will suit my encoder wheel needs perfectly....after wrestling with 'pin' polling for weeks with my encoder wheel & getting very erratic results, I'm one very happy McSpank here today! October 05, 2002 maybe was a good day...but I can say without any shadow of a doubt, for me the 19 May 2009 was a lot better !!

    Just a couple of small suggestions for Darrel's website (to save avoid a lot of newbie-esque puzzlement) - on Darrel's very first hello world code page, it might be worth saying that a user will need to establish their own PIC variant's 'INT' pin, along with perhaps a couple of PIC specific examples. (it might be ovbious to you old hands, but looking at the plethora of pins PICs have, it wasn't obvious to me!)

    Also, for what it's worth...the 16F690 is perhaps the most common chip that newbies come into contact with at the moment (on account it's bundled with Microchip's very popular PikKit2 starter kit)...I had a problem with Darrel's "Hello World" code when I first compiled ...."error: variable wsave3 position request 416 beyond ram_end 367.", ultimately meaning a line in Darrel's DT_INTS-14.bas file needed commenting out - that might also be worth a mention too? (or at least some mention on a FAQ page?)

    Anyway, a hearty thanks to Darrel... without his effort towards making interupts easy with PICBasic , I'm sure I would have left interupts for another day (ie sometime in 2023!)
    Last edited by HankMcSpank; - 19th May 2009 at 16:50.

  6. #6
    Join Date
    Nov 2008
    Posts
    9


    Did you find this post helpful? Yes | No

    Default Help

    I am using a 16f866 with your instant interrupt but I cannot get it to wake up from sleep using a USART RX int.. If i use a Pause 1 in the main loop it works fine but I would really like for it to go to sleep and just wait. Please let me know what I am doing wrong.. here is the code.. Thank you Darrel for the awesome instant interrupt routines.


    Code:
    Define OSC 8
    
    INCLUDE "DT_INTS-14.bas"     ' Base Interrupt System
    INCLUDE "ReEnterPBP.bas"     ' Include if using PBP interrupts
    
    ' Set receive register to receiver enabled
    DEFINE HSER_RCSTA 90h 
    
    ' Set transmit register to transmitter enabled
    DEFINE HSER_TXSTA 20h 
    
    ' Set baud rate
    DEFINE HSER_BAUD 2400
    
    x var byte
    OSCCON=%01111000
    
    ASM
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
            INT_Handler   RX_INT ,  _ToggleLED1,   PBP,  yes
        endm
        INT_CREATE               ; Creates the interrupt processor
    ENDASM
    
    @ INT_ENABLE  RX_INT      
    
    Main:
    @sleep
    @nop
    GOTO Main
    
    '---[RX-Int - interrupt handler]--------------------------------------------------
    ToggleLED1:
    hserin [x]
    hserout ["Hello"]
    @ INT_RETURN
    Last edited by jchandir; - 31st May 2009 at 02:18.

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


    Did you find this post helpful? Yes | No

    Default

    I assume you meant 16F886?

    From the datasheet...
    During Sleep mode, all clocks to the EUSART are
    suspended. Because of this, the Baud Rate Generator
    is inactive and a proper character reception cannot be
    performed.
    You can use the AUTO-WAKE-UP ON BREAK feature of the EUSART, but there are several things to consider.

    Take a look at section 12.3.2 AUTO-WAKE-UP ON BREAK
    <br>
    DT

  8. #8
    Join Date
    Nov 2008
    Posts
    9


    Did you find this post helpful? Yes | No

    Default

    shoot.. i meant 16f688... sorry about my careless mistake.

Similar Threads

  1. Clock using Instant Interrupts
    By PICpocket in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 16th February 2009, 22:43
  2. DT instant interrupts with mister_e keypad
    By Tomexx in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 26th November 2008, 21:02
  3. DT's Instant Interrupts trouble
    By Tomexx in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 24th November 2008, 21:48
  4. Keypad and DT's Instant Interrupts
    By Homerclese in forum General
    Replies: 11
    Last Post: - 27th April 2007, 07:32
  5. Replies: 1
    Last Post: - 1st November 2006, 04:11

Members who have read this thread : 4

You do not have permission to view the list of names.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts