Instant Interrupts - Revisited


Closed Thread
Results 1 to 40 of 773

Hybrid View

  1. #1
    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 13:24.

  2. #2
    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 14:00.

  3. #3
    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 15:50.

  4. #4
    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 01:18.

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

  6. #6
    Join Date
    Nov 2008
    Posts
    9


    Did you find this post helpful? Yes | No

    Default

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

  7. #7
    Join Date
    Nov 2008
    Posts
    9


    Did you find this post helpful? Yes | No

    Default

    ok so i solved the problem. thanks Darrel. I just had to set the BAUDCTL.1 (WUE) bit.

Similar Threads

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

Members who have read this thread : 6

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