Instant Interrupts - Revisited


Closed Thread
Results 1 to 40 of 773

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default ReEnterPBP.bas - An adaptation of INT_CTRL.pbp

    October 05, 2002 was a good day.   Because that's the day that Tim Box released his "INT_CTRL.pbp" program.   The original "Instant Interrupts"

    Tim had discovered that the only reason you couldn't use Basic statements in a normal interrupt, was because the PBP system variables currently being used by the statement that got interrupted, would be overwritten by the Basic statements in the interrupt routine.   And that, all you have to do is save the state of the system vars at the start of the interrupt, and restore them back to the way they were before exiting the interrupt and you can use any Basic statements you want.

    I've probably said it too many times already but ... Thanks again Tim!
    <hr>
    ReEnterPBP.bas is an adaptation of the same concept, but it allows the Interrupt system to determine if it needs to save the variables or not.

    For instance, if you have a program with both ASM and PBP interrupt handlers, and an interrupt triggers an ASM handler, there's no need to save the variables first, it would just be waisting valuable time. And if more than 1 Basic handler is triggered at the same time, it only saves the variables once, and processes all the Interrupts on the same pass, before restoring the system vars, again saving time.

    However, it does still take a lot of time to save all those variables. Usually it takes around 70 instruction cycles to save the vars. Then another 70 cycles to restore them again. At 4mhz it's 140us total save and restore time, which limits the maximum interrupt frequency to just over 7khz. At 20mhz OSC, you can go up to almost 36khz. That's fast enough to receive RS232 at over 250Kbaud with the USART. &nbsp; But is still considerably slower than you can get with ASM interrupts.

    <br>

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


    Did you find this post helpful? Yes | No

    Default Bug Fix

    <table><tr><td></td><td>While working on the 18F version, I discovered a bug in the ReEnterPBP file.
    It was not restoring the RS1 and RS2 system variables properly.</td></tr></table>The file has been updated to version 3.2, and anyone using Instant Interrupts for the 14-bit PIC's should update the file as soon as possible.


    <br>
    DT

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


    Did you find this post helpful? Yes | No

    Cool DT_INTS-18 Interrupts for 18F's Now Available

    <table><tr><td></td><td>
    At long last.

    The Instant Interrupt system for 18F PIC's is now available.

    It's become increasingly harder to keep things up to date here on the forum, so I've moved everything over to my website.
    I'm still working on some of the pages, but everything you need is already there. It seems to take longer to make the web pages, than it does to write the program.

    http://darreltaylor.com/DT_INTS-18/home.html</td></tr></table>

    <br>
    DT

  4. #4
    Join Date
    Oct 2005
    Location
    New Jersey
    Posts
    425


    Did you find this post helpful? Yes | No

    Default

    Darrel,

    Awesome program for a 18F4550. I never realized it takes so many lines of code just to blink an LED. Where can I adjust the duty cycle of the LED?

    Thanks,

    Chris

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


    Did you find this post helpful? Yes | No

    Default

    Many thanks to Darrel Taylor ! I'll have to try this immediately.


    His techniques probably make most of what I'm about to write obsolete - but last night I promised that I would post what I learned about assembly-language interrupts and PBP from Tim Box, Charles Leo (of MELABS) and my own testing. The information presented is believed to be accurate, but I cannot guarantee this without complete testing - something I will do within the next few days. If I find any mistakes, I'll post an update.

    1)
    Some of the newer 18F parts have a new instruction -

    RETFIE FAST

    This instruction AUTOMATICALLY saves and restores the W,STATUS and BSR registers. Unless you mess around with pointers (such as FSR0x), this is all you need to do use. No extra instructions for saving and restoring context are needed. Just put it in place of the ordinary 'retfie' instruction. Check your datasheet to make sure if your part offers this. The 18F8720 and '8722 have this instruction.

    2)
    If your part does NOT have the "fast interrupt" enhancement, you should *normally* only need to save and restore W,STATUS and BSR.

    3)
    ALL of the variables declared by PBP but used in the assembly routine should be declared as 'bankA'.

    4)
    Variables declared by PBP are given an underscore "_" before the name when used in assembly. For example: 'MyVar var BYTE bankA' in PBP becomes '_MyVar' in assembly. To allow the same name in both PBP AND assembly, you need to define the variable as 'system' . For example 'MyVar BYTE bankA
    system' has the name 'MyVar' in assembly (The assembler variable doesn't require an underscore as long as the variable is declared as 'system'.)

    5)
    Don't declare BIT variables in PBP to later be used in an assembly routine.
    Use BYTE or WORD variables only. If you just need a bit to act as a flag, declare a PBP variable such as 'FLAGVAR' and set/reset one of the bits.

    6)
    Since your are only using the Access Bank (bankA) in your assembly-language routine, you don't need to use GOTOs. Use the BRA (branch) instruction instead.

    7)
    If you have two interrupt levels (high and low priority), you can use the PBP defines -
    DEFINE INTHAND (label of high-priority interrupt handler) and
    DEFINE INTLHAND (label of low-priority interrupt handler)

    Save and restore context the same way as described above. RETFIE FAST works on the low-priority interrupt, too.
    Charles Linquist

  6. #6
    Join Date
    May 2006
    Location
    Del Rio, TX, USA
    Posts
    343


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Charles Linquis
    RETFIE FAST works on the low-priority interrupt, too.
    Just to clarify one important item. Here is snippet from the PIC18F8722 Datasheet under Memory Organization:

    5.1.4 FAST REGISTER STACK
    ...
    If both low and high priority interrupts are enabled, the
    stack registers cannot be used reliably to return from
    low priority interrupts
    . If a high priority interrupt occurs
    while servicing a low priority interrupt, the stack register
    values stored by the low priority interrupt will be
    overwritten. In these cases, users must save the key
    registers in software during a low priority interrupt.
    So, more accurately, RETFIE FAST works when low-priority interrupts are enabled, as long as software saves & restores key registers during the low priority interrupts, and RETFIE FAST is only used to return from high-priority interrupts.

    Steve

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


    Did you find this post helpful? Yes | No

    Default

    Charles,

    Well, you got 1 of them right. The other six get the game Buzzer. ennnhhh.

    1) and 2)
    All 18F's have shadow registers which store the key registers on any interrupt. As Steve already pointed out, if using High Priority Ints, you can't use the Shadow RAM for Low Priority Ints because they will be overwritten by a High Pri. Int. But since Low Pri. Ints can't interrupt High Pr. Ints, Shadow RAM is always valid for High Pri.

    3) You can acces any variable in any bank of ram in an Int Handler. You just have to switch to that bank before using the variable. If you couldn't switch Banks in an interrupt handler, there wouldn't be a reason to save BSR at the beginning.

    CHK?RP is the easiest way. There are some complicated issues with goto's and pbp's PREV_BANK variable. but once you figure out how it works. It's a piece of cake.

    4) Correct.

    5) They probably said to do BIT vars that way because PBP automatically puts BIT variables in alphabeticaly sorted order towards the end of used RAM. And since that's not BANKA, it didn't fit in with number 3). Switch the BANK, and you can access them too.

    6) Again, BANKA is not a limitation.

    7) Seven would have been ok except for the "RETFIE FAST works on the low-priority interrupt, too" which was covered in 1) and 2).

    So, just use DT_INTS-18 with Basic Language Interrupts, and you don't have to worry about Any of that stuff. It's already handled for you.
    <br>
    DT

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


    Did you find this post helpful? Yes | No

    Default

    Chris,

    For the examples, I simply used the timers overflow to TOGGLE a pin, so the duty cycle is always 50%. But then, it's just an example. If you increase the frequency of the timer Overflows, either by reducing the prescaler, or by re-loading the timer on each interrupt, or both, you can control the duty cycle within the interrupt handler. By incrementing a variable you can have it turn on for 10 interrupts and off for 246, or whatever resolution you want.
    <br>
    DT

  9. #9
    Join Date
    Sep 2006
    Location
    Australia
    Posts
    5


    Did you find this post helpful? Yes | No

    Thumbs up Instant Interrupt

    Quote Originally Posted by Darrel Taylor View Post
    <table><tr><td></td><td>
    At long last.

    The Instant Interrupt system for 18F PIC's is now available.

    It's become increasingly harder to keep things up to date here on the forum, so I've moved everything over to my website.
    I'm still working on some of the pages, but everything you need is already there. It seems to take longer to make the web pages, than it does to write the program.

    http://darreltaylor.com/DT_INTS-18/home.html</td></tr></table>

    <br>
    Thank you very much Darrel. Your excellent works have saved me lots of headache.

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 : 8

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