Instant Interrupts - Revisited


Closed Thread
Page 1 of 20 1234511 ... LastLast
Results 1 to 40 of 773
  1. #1
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959

    Default Instant Interrupts - Revisited

    This is a series of include files that simplify the process of creating interrupt driven programs for PicBasic Pro. MPASM required.

    Once you try this, you may never use ON INTERRUPT again.

    Features:
    Assembly language Interrupts
    Basic language Interrupts
    Both ASM and Basic interrupts in the same program
    Service Multiple Interrupt sources
    Prioritized execution order
    Very easy to use


    No ON INTERRUPT "Code Bloat"
    No ON INTERRUPT " I'll service your interrupt whenever I feel like it." mentality.
    .
    One of the best things about this system, is that you don't have to remember where all the Enable bits and Interrupt flags are located.

    Each interrupt "source" is given a unique name that is used to reference it.
    The system "Looks Up" the correct bit locations for that name. Reducing those RTFM sessions to a minimum.
    The following table lists the Named Interrupts.
    Note: More interrupts have been added .. please visit http://darreltaylor.com/DT_INTS-14/intro.html

    Available Interrupt Sources 14-bit
    Code:
     INT_INT -- INT External Interrupt
     RBC_INT -- RB Port Change Interrupt
     TMR0_INT -- TMR0 Overflow Interrupt 16F
     TMR1_INT -- TMR1 Overflow Interrupt
     TMR2_INT -- TMR2 to PR2 Match Interrupt
     TX_INT -- USART Transmit Interrupt
     RX_INT -- USART Receive Interrupt
     CMP_INT -- Comparator Interrupt
     EE_INT -- EEPROM/FLASH Write Operation Interrupt
     BUS_INT -- Bus Collision Interrupt
     PSP_INT -- Parallel Slave Port Read/Write Interrupt
     AD_INT -- A/D Converter Interrupt
     SSP_INT -- Master Synchronous Serial Port Interrupt
     CCP1_INT -- CCP1 Interrupt
     CCP2_INT -- CCP2 Interrupt
    Here's a simple example of toggling an LED using the external interrupt (INT). (Hello World)
    Code:
    LED1   VAR  PORTB.1
    
    INCLUDE "DT_INTS-14.bas"     ' Base Interrupt System
    INCLUDE "ReEnterPBP.bas"     ' Include if using PBP interrupts
    
    ASM
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
            INT_Handler    INT_INT,  _ToggleLED1,   PBP,  yes
        endm
        INT_CREATE               ; Creates the interrupt processor
    
        INT_ENABLE   INT_INT     ; enable external (INT) interrupts
    ENDASM
    
    Main:
      PAUSE 1
    GOTO Main
    
    '---[INT - interrupt handler]---------------------------------------------------
    ToggleLED1:
         TOGGLE LED1
    @ INT_RETURN
    Code Size = 234 words

    This project, and it's associated files, have been moved.
    Please download them from my website.
    DT_INTS-14 (12F-16F)
    http://darreltaylor.com/DT_INTS-14/intro.html

    DT_INTS-18 (18F)
    http://darreltaylor.com/DT_INTS-18/home.html

    .
    Last edited by Darrel Taylor; - 21st January 2014 at 19:20.

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


    Did you find this post helpful? Yes | No

    Default Example 2

    The ultimate overkill Blinky Light program ... using Timer 1
    Code:
    LED1   VAR  PORTB.1
    
    INCLUDE "DT_INTS-14.bas"     ' Base Interrupt System
    INCLUDE "ReEnterPBP.bas"     ' Include if using PBP interrupts
    
    ASM
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
            INT_Handler   TMR1_INT,  _ToggleLED1,   PBP,  yes
        endm
        INT_CREATE               ; Creates the interrupt processor
    ENDASM
    
    T1CON = $31                ; Prescaler=8, TMR1ON
    @ INT_ENABLE  TMR1_INT     ; enable Timer 1 interrupts
    
    Main:
      PAUSE 1
    GOTO Main
    
    '---[TMR1 - interrupt handler]--------------------------------------------------
    ToggleLED1:
         TOGGLE LED1
    @ INT_RETURN
    Code Size = 240 words

    OK, Why? ... You might ask.
    Well, for one, this Blinky Light program will continue Blinking at the same rate, no matter what else you add to the Main: program loop. Try doing that with pauses.
    Last edited by Darrel Taylor; - 21st January 2014 at 19:14.

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


    Did you find this post helpful? Yes | No

    Default Elapsed Timer

    The NEW Elapsed Timer does, ... well .. it does exactly the same thing as the old Elapsed Timer. But now it works with the Instant Interrupt system. Which means that you can use many other interrupts in the same program without much trouble at all. Unlike the last version.

    Here's an example of just the Elapsed Timer by itself.
    Code:
    INCLUDE "DT_INTS-14.bas"
    INCLUDE "ReEnterPBP.bas"
    INCLUDE "Elapsed_INT.bas"  ; Elapsed Timer Routines
    
    ASM
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
            INT_Handler   TMR1_INT,  _ClockCount,   PBP,  yes
        endm
        INT_CREATE            ; Creates the interrupt processor
    
        INT_ENABLE  TMR1_INT  ; Enable Timer 1 Interrupts  
    ENDASM
    
    GOSUB ResetTime           ' Reset Time to  0d-00:00:00.00
    GOSUB StartTimer          ' Start the Elapsed Timer
    
    Main:
      IF SecondsChanged = 1 THEN  
         SecondsChanged = 0
         LCDOUT $FE,2, DEC Days,"d-",DEC2 Hours,":",DEC2 Minutes,":",DEC2 Seconds
      ENDIF
    GOTO Main
    Code Size = 537 Words

    This will create a Clock counting at 1/100 seconds. It runs in the background of PBP without any other program intervention required.

    The time is kept in the variables:
    Code:
        Ticks    var byte   ' 1/100th of a second
        Seconds  var byte   ' 0-59
        Minutes  var byte   ' 0-59
        Hours    var byte   ' 0-23
        Days     var word   ' 0-65535
    The time can be easily displayed with a single line:
    Code:
        LCDout $FE,2, dec Days,"d-",dec2 Hours,":",dec2 Minutes,":",dec2 Seconds
    For each of the variables (Seconds, Minutes, Hours and Days) there is a flag
    that indicates when the value of that variable has changed. The Flags are:

    SecondsChanged var bit
    MinutesChanged var bit
    HoursChanged var bit
    DaysChanged var bit

    If you wanted to display the time like a clock, you could wait until
    SecondsChanged = 1, display the time, then reset the flag.

    Code:
        Loop1:
            if SecondsChanged = 1 then
               LCDout $FE,2, dec Days,"d-",dec2 Hours,":",dec2 Minutes,":",dec2 Seconds
               SecondsChanged = 0
            endif
        Goto Loop1
    If you only wanted to display the time each minute instead of every second
    just do the same thing using the MinutesChanged flag.

    Code:
        Loop1:
            if MinutesChanged = 1 then
               LCDout $FE,2, dec Days,"d-",dec2 Hours,":",dec2 Minutes
               MinutesChanged = 0
            endif
        Goto Loop1
    The timer can be Stopped and Started, like a stopwatch.
    Code:
        Gosub StopTimer
        Gosub StartTimer
    Attached Files Attached Files
    Last edited by Darrel Taylor; - 21st January 2014 at 19:12.

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


    Did you find this post helpful? Yes | No

    Default Bringing them together

    So far I've shown one interrupt source being used at a time, but as I said in the first post, you can easily service Multiple Interrupt Sources.   So what if we wanted to join the previous 3 examples into one program.   NOT a problem!

    To add more interrupt "Handlers", simply add them to the INT_LIST, and create a subroutine for them.

    Since both the Blinky Light, and Elapsed Timer used TMR1, lets move the Blinky Light over to TMR0. Elapsed will still use TMR1.
    Code:
    LED1   VAR  PORTD.0
    LED2   VAR  PORTD.1
    
    INCLUDE "DT_INTS-14.bas"     ' Base Interrupt System
    INCLUDE "ReEnterPBP.bas"     ' Include if using PBP interrupts
    INCLUDE "Elapsed_INT.bas"    ' Elapsed Timer Routines
    
    ASM
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
            INT_Handler    INT_INT,  _ToggleLED1,   PBP,  yes
            INT_Handler   TMR0_INT,  _ToggleLED2,   PBP,  yes
            INT_Handler   TMR1_INT,  _ClockCount,   PBP,  yes
        endm
        INT_CREATE               ; Creates the interrupt processor
    
        INT_ENABLE   INT_INT     ; enable external (INT) interrupts
        INT_ENABLE  TMR0_INT     ; enable Timer 0 interrupts
        INT_ENABLE  TMR1_INT     ; Enable Timer 1 Interrupts  
    ENDASM
    
    OPTION_REG = OPTION_REG & $80 | 1  ; Set TMR0 Prescaler to 256, leave RBPU alone
    GOSUB ResetTime              ' Reset Time to  0d-00:00:00.00
    GOSUB StartTimer             ' Start the Elapsed Timer
    
    Main:
        IF SecondsChanged = 1 THEN  
           SecondsChanged = 0
           LCDOUT $FE,$C0, DEC Days,"d-",DEC2 Hours,":",DEC2 Minutes,":",DEC2 Seconds
        ENDIF
    GOTO Main
    
    '---[INT - interrupt handler]---------------------------------------------------
    ToggleLED1:
         TOGGLE LED1
    @ INT_RETURN
    
    '---[TMR0 - interrupt handler]-------------------------------(Blinky Light)------
    T0Count  VAR WORD
    ToggleLED2:
        T0Count = T0Count + 1
        IF T0Count = 512 THEN T0Count = 0 : TOGGLE LED2
    @ INT_RETURN
    
    <font size=-2>Code Size = 711 Words</font>

    Now we have all three interrupt sources working together in the same program.
    LED1 responds to the external INT
    LED2 flashes, timed by TMR0
    and, the elapsed timer is maintained via TMR1
    And, all of this is happening behind the scenes of your normal PBP program.
    Attached Files Attached Files
    Last edited by ScaleRobotics; - 7th January 2012 at 17:38.

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


    Did you find this post helpful? Yes | No

    Default The Base Layer - ASM interrupts

    <table cellpadding=6><tr><td valign=center></td><td>The Instant Interrupt System consists of several "Layers".

    The Bottom Layer is "DT_INTS-14.bas". This file contains everything required to use Interrupts at the ASM level. &nbsp; It handles all of the "Context Saving/Restoring", detects which interrupt has been triggered, and calls the appropriate "User Routine".

    The next layer up is created from the INT_LIST macro you define in the program. &nbsp; It defines the Interrupt sources to use and the corresponding subroutines that will be called. &nbsp; They can be either simple subroutines, or complete "Modules" in a separate Include file, like the Elapse Timer. &nbsp; Up to 14 separate INT_Handler's can be in the LIST.

    And, the Top Layer is the normal PBP program that runs in the foreground.

    If Basic Laguage interrupts are not being used, then DT_INTS-14.bas is the only file you need to include.</td></tr></table>Here's another example of a Blinky Light program using TMR1 with an Assembly Language Interrupt handler
    Code:
    LED1   VAR  PORTD.0
    LOW  LED1                    ; Set to Output Low
    
    INCLUDE "DT_INTS-14.bas"     ; Base Interrupt System
    
    ASM
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
            INT_Handler   TMR1_INT,   ToggleLED1,   ASM,  yes
        endm
        INT_CREATE               ; Creates the interrupt processor
    
        INT_ENABLE  TMR1_INT     ; Enable Timer 1 Interrupts  
    ENDASM
    
    T1CON = $31                  ; Prescaler=8, TMR1ON
    
    Main:
        PAUSE 1
    GOTO Main
    
    '---[TMR1_INT - interrupt handler]------------------------------------------
    ASM
    ToggleLED1
        btfsc  _LED1
        goto   $+3
        bsf    _LED1
        goto   $+2
        bcf    _LED1
        INT_RETURN
    ENDASM
    
    <font size=-3>Code Size = 104 Words</font>

    Notice that the INT_Handler's Type is ASM, and the Label does not have an underscore before it.<hr><table cellpadding=6><tr><td></td><td valign=top>By using this type of Layering scheme. It allows us more flexability, depending on the type of interrupt we want to use. &nbsp; If we want to add Basic Language Handlers, all we need to do is Include "ReEnterPBP.bas", and it will insert another Layer in-between the Base and the Handlers.

    With this layer included, you can have any combination of ASM and PBP interrupts in the same program</td></tr></table>
    <br>
    Last edited by ScaleRobotics; - 7th January 2012 at 17:33.

  6. #6
    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. &nbsp; Because that's the day that Tim Box released his "INT_CTRL.pbp" program. &nbsp; 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. &nbsp; 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>

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

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

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

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

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

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

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

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


    Did you find this post helpful? Yes | No

    Default

    Darrel,

    Thanks for the clarifications.

    I'm not very familiar with bank switching, so at this time I didn't feel comfortable with dealing with that. You mention "CHK?RP" as an easy way to deal with the issue. I have no idea how to use this. I assume this is a macro that comes from somewhere. Could you please elaborate?
    Charles Linquist

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


    1 out of 1 members found this post helpful. Did you find this post helpful? Yes | No

    Default

    CHK?RP is a PBP macro wich send you to the correct bank of a x register

    CHK?RP PORTA

    not much, using this one avoid you to read the x PIC datasheet to see where the x register is placed and do the bank switching yourself. Really handy stuff!
    Steve

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

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


    Did you find this post helpful? Yes | No

    Default

    Nice work Darrel.
    Regards,

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

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


    Did you find this post helpful? Yes | No

    Default

    Bruce,

    Thank You, Thank You, Thank You!

    But I gotta ask.

    Have you tried it yet?
    Or does it just Look Cool?

    Apprehensively,
    &nbsp; Darrel

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


    Did you find this post helpful? Yes | No

    Default

    Hi Darrel,

    I've tested it on a Lab-X1 with 18F452. Timers 0, 1 and 3 hi-pri. USART rx
    low-pri, and it works as advertised...;o}

    P.S. I thought this was pretty slick;
    movff FSR#v(F)L, fsave#v(F)Pr
    movff FSR#v(F)H, fsave#v(F)Pr + 1
    Last edited by Bruce; - 13th July 2006 at 19:30.
    Regards,

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

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


    Did you find this post helpful? Yes | No

    Default

    Excellent!

    Thanks for that.

    And, yeah. The "Text Substitution" comes in pretty handy.
    A bit Cryptic looking, but it is "Slick". Finding more uses for it with each new program.
    <br>
    DT

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


    Did you find this post helpful? Yes | No

    Default

    Darrel,
    i'm developping an USB device to be release within let's say a year if everything work as expect. I have to use few interrupts source(4 as now.. but it grows). Today i decided to implement the instant interrupt in. All i can say is that it really reduce the latency. Worked well before... by far better now. You really save me to spend hours in the asm developpement...

    Anyways i'll probably have no choice to use asm if i really don't want to move to the DsPIC. It's still in developpement so far.

    Thanks!
    Last edited by mister_e; - 14th July 2006 at 05:02.
    Steve

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

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


    Did you find this post helpful? Yes | No

    Default

    Sounds great Steve,

    Were you using ON INTERRUPT before? or ASM?
    <br>
    DT

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


    Did you find this post helpful? Yes | No

    Default

    On interrupt first.. thereafter trying to do a real pure assembler ISR wich was a real improvement but didn't finished to implement/debug all of them 'cause you bum decide to stop me and release the 18Fs version and worst for FREE!

    I may want to waste my time one day to do a pure asm ISR and compare both... but not for now as it's work really fine and i'm still unsure of the real final requirement 'round this device. You know how it is.. sometimes we see it bigger than it have to be

    i'll keep you post anyways!
    Last edited by mister_e; - 14th July 2006 at 22:14.
    Steve

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

  23. #23
    Join Date
    Mar 2006
    Location
    Pennsylvania, USA.
    Posts
    130


    Did you find this post helpful? Yes | No

    Question Instant Interrupts

    I tried it, played with it for over three hours, nothing but compilation errors. I'm using Picbasic Pro 2.46 and MPASM 5.03. Any ideas?

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


    Did you find this post helpful? Yes | No

    Default

    What were the errors?

    And which example were you trying?
    <br>
    DT

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


    Did you find this post helpful? Yes | No

    Default

    Darrel,

    I finally had a chance to try DT_Ints-18, and it works (of course) as advertised. I can't thank you enough for working on this and finishing it just as I had a pressing need.

    Keep up the good work!

    Can I ask for HI2CREAD and HI2CWRITE next? Real FUNCTIONS?
    Charles Linquist

  26. #26
    Join Date
    Mar 2006
    Location
    Pennsylvania, USA.
    Posts
    130


    Did you find this post helpful? Yes | No

    Default Hi Darrel

    That was fast!

    My errors are as follows,
    Warning[230]c:\pbp\18f4550inc 20:_config has been deprecated for PIC18 devices. Use directive CONFIG. (this is listed five times, then,)
    Error[128]c:\progra~1\Mecani~1\example2.asm 1150:missing arguement(s)
    Error[113]c:\ "" 602: Symbol not previously defined (INTFLAGREG)
    603: Symbol not previously defined (INTFLAGBIT)
    218: " (INTFLAGREG)
    218: " (INTFLAGBIT)
    656: ERROR (INTERRUPT SOURCE (INTFLAGREG,INTFLAGBIT) NOT FOUND
    713: ERRORINT_ENABLE - Priority State Not Found)

    Thanks, I'm dying to try this out!

    Jerry Gavin

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


    Did you find this post helpful? Yes | No

    Default

    about the CONFIG warning error look at the FAQ
    http://www.picbasic.co.uk/forum/showthread.php?t=543

    Now be sure all files are in the same directory (source code, include and so on)

    Still having problem? post your whole code here.

    HTH
    Steve

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

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Charles Linquis
    Can I ask for HI2CREAD and HI2CWRITE next? Real FUNCTIONS?
    what you mean by 'real function' ? unless using Macro and INCLUDE files and as far as i'm aware of, we can't add in the existing function list... i would be so much handy.

    Darrel... Yet another Plug-In application
    Steve

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

  29. #29
    Join Date
    Mar 2006
    Location
    Pennsylvania, USA.
    Posts
    130


    Did you find this post helpful? Yes | No

    Smile Problem solved!

    When you have eliminated all possible problems, the only one left, no matter how improbable must be the solution, to paraphrase Sherlock Holmes. I noticed that two of the files that I downloaded were showing up as smaller than the file sizes listed on Darrel's site. I deleted them and downloaded again, and everything compiled perfectly the first time! Works Great! I had just received a few 18F4550s to play with so Darrel's timing was perfect.

    Also, thanks to Steve for the note regarding the Config problem.

    Thanks to all,

    Jerry Gavin

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


    Did you find this post helpful? Yes | No

    Default

    Jerry,

    Great, I'm so glad you found it. Never would have figured that out from here.

    Charles,

    You're welcome,

    I think the HI2C, and HI2CSLAVE should be pretty easy now with DT_INTS. As well as HSPI and HSPISLAVE, PSPSLAVE, SSPWM, Multi-SSPWM, PWPS, Multi-PWPS, etc. etc. etc.

    However, in order to facilitate some of those types of commands, I think the next step is a universal FIFO (First In First Out) buffer structure. Already have it working, but it looks real ugly right now.

    As for Functions, I think Steve's right. Until we can gain control over the compiler, or the IDE, or maybe create a Pre-compiler, Functions will remain on the PBP wish list.

    DT

    P.S. My "Timing" is still not perfect though, since I've been totally sidetracked from the Elapsed Timer/Oscillator accracy problem.
    <br>

  31. #31
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,961


    Did you find this post helpful? Yes | No

    Default

    This is just so cool, this stuff is exactly what I needed to service USB without having to figure out how much to sprinkle within the code.

    Can't wait to try this after dinner.

    Robert
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

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


    Did you find this post helpful? Yes | No

    Default

    Darrel,

    You said "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."

    When I look at your program, I am completely lost. Can you tell me exactly what variable(s) I have to changed to get the LED blink faster or slower?

    Thanks,

    Chris

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


    Did you find this post helpful? Yes | No

    Default Advanced Blinky Light (fader)

    Chris,

    The prescaler can be changed with T1CON.
    $31 = 1:8
    $21 = 1:4
    $11 = 1:2
    $01 = 1:1

    And the Timer is reloaded by putting values in TMR1H:TMR1L.

    So first, decide what frequency you need, I'll go with 100hz.

    Then, go to this thread...
    Testing Forms [TimerCalc] Working I think?
    http://www.picbasic.co.uk/forum/showthread.php?t=2031

    Enter the OSC value you are using, say 20mhz.
    I'll also go with 1:1 prescaler, enter that. (ok, it's already there)
    Then enter 100 in the Freq field at the bottom.

    Now you can see that it will take a total of 50,000 counts (ticks) to achieve 100hz.

    Decide what resolution you want for the Duty-Cycle. ummm, 8-bit (256).

    Now you just calculate the ON count from that with...
    50000*DutyCycle/256 which is the same thing as...
    50000*/DutyCycle in PBP
    and the OFF count is 50000 - ONcount

    Ok, so let's put that into the Blinky Light example


    Code:
    
    ; Initialize your hardware first.
    
    
    INCLUDE &quot;DT_INTS-18.bas&quot;     ' Base Interrupt System
    INCLUDE &quot;ReEnterPBP-18.bas&quot;     ' Include if using PBP interrupts
    
    
    LED1       VAR PORTB.1
    DutyCycle  VAR BYTE
    
    
    TotalCount CON 50000
    ONcount    VAR WORD
    OFFcount   VAR WORD
    
    
    ASM
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
            INT_Handler   TMR1_INT,  _ToggleLED1,   PBP,  yes
        endm
        INT_CREATE               ; Creates the interrupt processor
    ENDASM
    
    
    T1CON = $00                ; Prescaler=1:1, TMR OFF
    @ INT_ENABLE  TMR1_INT     ; enable Timer 1 interrupts
    
    
    Main:
        FOR DutyCycle = 0 TO 255           ; Ramp up
            GOSUB  SetDutyCycle
            PAUSE  5
        NEXT DutyCycle
    
    
        FOR DutyCycle = 254 TO 1 STEP -1   ; Ramp down
            GOSUB  SetDutyCycle
            PAUSE  5
        NEXT DutyCycle
    GOTO Main
    
    
    
    
    SetDutyCycle:
        ONcount = TotalCount*/DutyCycle
        OFFcount = TotalCount - ONcount
        IF DutyCycle = 0 THEN
            T1CON.0 = 0    ; turn off timer
            LOW  LED1      ; idle LOW
        ELSE
            T1CON.0 = 1    ; timer on if DutyCycle &gt; 0
        ENDIF 
    RETURN
    
    
    DISABLE DEBUG
    '---[TMR1 - interrupt handler]------------------------------------------------
    @Timer1=TMR1L             ; map timer registers to a word variable
    Timer1 VAR WORD EXT
    
    
    ToggleLED1:
        IF LED1 THEN
            LOW LED1
            T1CON.0 = 0         ; stop the timer
            Timer1  = OFFcount  ; Load OFF count
            T1CON.0 = 1         ; start timer
        ELSE
            HIGH LED1
            T1CON.0 = 0         ; stop the timer
            Timer1  = ONcount   ; Load ON count
            T1CON.0 = 1         ; start timer
        ENDIF
    @ INT_RETURN
    ENABLE DEBUG
    
    Last edited by mackrackit; - 1st February 2012 at 10:35. Reason: HTML
    DT

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


    Did you find this post helpful? Yes | No

    Default

    OK, So once you try that, you'll realize that the RAMP is not linear.

    It's more a function of the LED output than the PWM routine itself.

    Changing it to 10-bit, and creating a lookup table that matches the LED brightness, seems to work. But I'm sure someone can come up with a better idea.
    <br>
    DT

  35. #35
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,961


    Did you find this post helpful? Yes | No

    Default

    Darrel, if all goes well I hope to be able to commercialize this project within the next 57 years. Can I have your permission to include all this nice stuff within my code?

    Hey, when I first started this project it was supposed to be nothing but a few switches and LEDs. That must have been over 2 years ago. Now I'm using a 320x240 graphic LCD, an 18F4550, two 16F628, 2 MCP23016, surface mount components, USB full speed, VB and eventually an Access database (I'm Tim The Toolman Taylor of home electronics).

    Having to learn electronics kinda put me slightly behind schedule.

    Robert
    :lol:
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

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


    Did you find this post helpful? Yes | No

    Default

    Hi Tim

    If you do it in the next 57 days (or 5.7), you can still use everything to your hearts content.

    Of course, you could add some routines to the pot.

    Help keep the Internet Free!
    <br>
    DT

  37. #37
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,961


    Did you find this post helpful? Yes | No

    Default

    Thank you, thank you, thank you, thank you, thank you!
    Thank you, thank you, thank you, thank you, thank you!

    You can be sure that I will post anything useful that I can contribute; like the stuff for the SED1335 graphic LCD. Last time I Googled, there were no code examples for that one.

    But I'm afraid there's not much I can add; you, Mister E and the other regulars have already covered anything I could conjure (and then some).

    Robert
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

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


    Did you find this post helpful? Yes | No

    Default

    But I'm afraid there's not much I can add;
    Well, I'm no philosophy major, but I figure...

    The Day you decide you Can't, is also the Day you won't.

    Give it a try.
    Added: or should I say more tries (examples). (SED1335 320x240 graphic LCD)

    DT

    Oh, and, You're Welcome, You're Welcome, You're Welcome,
    You're Welcome, You're Welcome, You're Welcome.
    Last edited by Darrel Taylor; - 17th July 2006 at 02:57. Reason: ADDED

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


    Did you find this post helpful? Yes | No

    Default

    Darrel,

    I'm trying to work your Instant Interrupts in to my regular code.

    When compiling, I get the following error messages:

    WARNING:Unable to fit variable RetAddrH in requested bank 16
    WARNING:Unable to fit variable RetAddrL in requested bank 16
    WARNING:Unable to fit variable INT_Flags in requested bank 16
    WARNING:Unable to fit variable HP_Vars in requested bank 0


    Since these are just warnings, do I need to be concerned?
    Is there a solution?
    Charles Linquist

  40. #40
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,961


    Did you find this post helpful? Yes | No

    Default

    I'm the proud owner of an interupt routine in a PIC 16F628, my very first. It handles USART RX from a PIC 18F4550 wonderfully.

    As mentionned on Darrel's information, I had to switch from MP to MPASM and encountered some delays in setting up the _CONFIG switches properly. But once I got that cleaned up I was up and running, this is just awesome!

    (Charles, any chance you are using MP?)

    Robert
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

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

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