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 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 "DT_INTS-18.bas"     ' Base Interrupt System
    INCLUDE "ReEnterPBP-18.bas"     ' 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 > 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 09:35. Reason: HTML
    DT

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

  3. #3
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    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!

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

  5. #5
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    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!

  6. #6
    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 01:57. Reason: ADDED

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

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

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