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

    To: Demon and mister_e,

    Hey, did you guys ever figure out the USB with DT_INTs approach.

    I was thinking about trying a USB project, and wondered if you 2 ever got it working?
    <br>
    Last edited by Demon; - 4th October 2016 at 18:44.
    DT

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


    Did you find this post helpful? Yes | No

    Unhappy

    Quote Originally Posted by Darrel Taylor View Post
    To: Demon and mister_e,

    Hey, did you guys ever figure out the USB with DT_INTs approach.

    I was thinking about trying a USB project, and wondered if you 2 ever got it working?
    <br>
    Well, i hate to say that Darrel but something goes bad when using instant interrupt and USB. Maybe some PBP variable need to be saved or something like that.

    Bellow is a short and sweet working example using ON INTERRUPT to do the USBSERVICE each 100uSec.

    OK it doesn't do anything else than sitting there and spin but, it keeps the connection alive without any Windows Warning. Once this solve, it should fix USBOUT and USBIN... or help to

    It use a PIC18F4550 and a 4MHZ crystal OSC.
    Code:
    asm
        __CONFIG    _CONFIG1L, _PLLDIV_1_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L  
                                ;              ;                      ; USB clock source comes from the 96 MHz PLL divided by 2
                                ;              ; [OSC1/OSC2 Src: /1][96 MHz PLL Src: /2]
                                ; No prescale (4 MHz oscillator input drives PLL directly)
    
    
        __CONFIG    _CONFIG1H, _FOSC_XTPLL_XT_1H & _FCMEN_OFF_1H & _IESO_OFF_1H 
                                ;                  ;               ; Oscillator Switchover mode disabled
                                ;                  ; Fail-Safe Clock Monitor disabled
                                ; XT oscillator, PLL enabled, XT used by USB
        __CONFIG    _CONFIG2L, _PWRT_ON_2L & _BOR_ON_2L  & _BORV_2_2L  & _VREGEN_ON_2L   
        __CONFIG    _CONFIG2H, _WDT_OFF_2H 
        __CONFIG    _CONFIG3H, _MCLRE_ON_3H & _LPT1OSC_OFF_3H & _PBADEN_OFF_3H & _CCP2MX_ON_3H 
        __CONFIG    _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L & _ICPRT_OFF_4L  & _XINST_OFF_4L & _DEBUG_OFF_4L 
    endasm
    DEFINE OSC 48          
    
    PORTB   =   0
    TRISB.0 =   0
    
    LED0    VAR PORTB.0
    TMR0IF  VAR INTCON.2
    TMR0ON  VAR T0CON.7
    
    INTCON  =   %10100000       ' Enable global and TMR0 interrupts
    T0CON   =   %10000000       ' TMR0, CLK internal, prescaler 1:2, T0ON
    
    UCFG    var byte EXT        ' include UCFG register... Yeah Melabs didn't :o(
    
    Reload      con 65000       ' ~100 uSec
    ucfg    =   %00010100       ' enable internal USB pull-up, Full speed USB
    
    goto SkipMacro
        asm 
    Reload_TMR0 macro
        BCF     _TMR0ON         ; stop timer
        MOVE?CW _Reload,TMR0L   ; reload
        BCF     _TMR0IF         ; clear overflow flag
        BSF     _TMR0ON         ; start timer
        ENDM
        endasm
    
    SkipMacro:
        pause 500               ' Settle delay
        usbinit                 ' initialise USB...
    @   Reload_TMR0             ; Reload timer0
        ON INTERRUPT GOTO DoUSBService
    
    Start: 
        goto start              ' Spin 'till you die!
    
    DISABLE
    DoUSBService:
        toggle LED0             ' toggle LED each time 
        usbservice              ' keep connection alive
    @   Reload_TMR0             ; reload timer
        RESUME                  ' getout of here
    ENABLE
    So nothing complicated... just spinning and keep USB connection alive.

    NOW, if i use the DT interrupt, IT SHOULD looks like this
    Code:
    asm
        __CONFIG    _CONFIG1L, _PLLDIV_1_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L  
                                ;              ;                      ; USB clock source comes from the 96 MHz PLL divided by 2
                                ;              ; [OSC1/OSC2 Src: /1][96 MHz PLL Src: /2]
                                ; No prescale (4 MHz oscillator input drives PLL directly)
    
    
        __CONFIG    _CONFIG1H, _FOSC_XTPLL_XT_1H & _FCMEN_OFF_1H & _IESO_OFF_1H 
                                ;                  ;               ; Oscillator Switchover mode disabled
                                ;                  ; Fail-Safe Clock Monitor disabled
                                ; XT oscillator, PLL enabled, XT used by USB
        __CONFIG    _CONFIG2L, _PWRT_ON_2L & _BOR_ON_2L  & _BORV_2_2L  & _VREGEN_ON_2L   
        __CONFIG    _CONFIG2H, _WDT_OFF_2H 
        __CONFIG    _CONFIG3H, _MCLRE_ON_3H & _LPT1OSC_OFF_3H & _PBADEN_OFF_3H & _CCP2MX_ON_3H 
        __CONFIG    _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L & _ICPRT_OFF_4L  & _XINST_OFF_4L & _DEBUG_OFF_4L 
    endasm
    DEFINE OSC 48          
    PORTB   =   0
    TRISB.0 =   0
    
    LED0    VAR PORTB.0
    TMR0IF  VAR INTCON.2
    TMR0ON  VAR T0CON.7
    
    INTCON  =   %10100000       ' Enable global and TMR0 interrupts
    T0CON   =   %10000000       ' TMR0, CLK internal, prescaler 1:2, T0ON
    
    UCFG    var byte EXT        ' include UCFG register... Yeah Melabs didn't :o(
    
    Reload      con 65000       ' ~100 uSec
    ucfg    =   %00010100       ' enable internal USB pull-up, Full speed USB
    
    INCLUDE "DT_INTS-18.bas"    ' Base Interrupt System
    INCLUDE "ReEnterPBP-18.bas" ' Include if using PBP interrupts
    
    goto skipmacro
    
        ASM
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
            INT_Handler    TMR0_INT,  _DoUSBService,   PBP,  no
        endm
        INT_CREATE               ; Creates the interrupt processor
    
    Reload_TMR0 macro
        BCF     _TMR0ON         ; stop timer
        MOVE?CW _Reload,TMR0L   ; reload
        BCF     _TMR0IF         ; clear overflow flag
        BSF     _TMR0ON         ; start timer
        ENDM
        endasm
    
    SkipMacro:
        pause 500
        usbinit ' initialise USB...
    @   Reload_TMR0
    @   INT_ENABLE  TMR0_INT
    
    Start: 
        goto start        
    
    DoUSBService:
        toggle led0
        usbservice
    @   Reload_TMR0
    @   INT_RETURN
    Right or i screw something? Anyways ON both, the LED work as expected (so i shouldn't be too wrong) but, the second lost the USB connection really soon... and yeah you have to reboot or it will reboot for you if you disconnect
    the USB plug. It's getting boring

    i attach everything i have in my C:\PBP_PROG\USBDemo folder, including a compiled VB utility to monitor if the device is Connected or Not when using EasyHID default VendorID and ProductID

    <img SRC="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=1300&stc=1&d=116748409 1">


    So for now, i still use the On Interrupt... Before i read and understand the whole Jan Axelson book, and build my own USB macros, i may need much spare time... oh yeah it's more than a RS-232 and there's a lot of improvements and adds to do with PBP.

    Now the weird stuff... Melabs didn't include the 'interesting' registers like UCFG, UIR,UIE,UEIR,UEIE and probably others... bah xxx VAR BYTE EXT fix it for now and if needed.

    To be honest, i didn't search really hard to find the problem source... getting lazy i guess :-)
    Attached Images Attached Images  
    Attached Files Attached Files
    Last edited by Demon; - 4th October 2016 at 18:44.
    Steve

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

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


    Did you find this post helpful? Yes | No

    Default That should do it.

    Wow, it seems like that should work?

    That sure gives me a starting point, (good one)

    And since you're also in such a good "moon"

    I'll take a look at ...
    http://www.picbasic.co.uk/forum/showthread.php?t=5418
    Too
    <br>
    DT

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


    Did you find this post helpful? Yes | No

    Default Moon or mood.... that's the question



    Well maybe i should say MOOD?
    Your Canadian to English dictionnary is still good

    Enjoy!
    Steve

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

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


    Did you find this post helpful? Yes | No

    Default

    Well, if I look at my girlfriend ... Moon's and Mood's have the same period, 27.3 days.

    Don't know how that fit's in with you though
    <br>
    DT

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


    Did you find this post helpful? Yes | No

    Default

    Yeah, it remind me something... sometimes i'm glad to be 'single'
    Last edited by mister_e; - 31st December 2006 at 12:49.
    Steve

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

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


    Did you find this post helpful? Yes | No

    Default

    Steve,

    I got my parts in for USB (gotta love ebay), and I've built up a breadboard with a 4550 and LED's, switches etc.
    I've looked at the example from post #143, the second one, with DT_INTS, and found two problems. The ...

    INTCON = %10100000 ' Enable global and TMR0 interrupts

    was causing the TMR0 interrupts to start servicing the USB before it was initialized. DT_INTS handles all the interrupt enable bits, so you don't need it anyway.

    The other problem was ...

    goto skipmacro

    was skipping over the interrupt defintion. That section of code needs to execute so that it can handle the enable bits and setup a couple other variables.

    Once I made those changes, the program works as expected, and never looses connection.
    <hr>
    But here's the good part,

    After going through the USB18.ASM file and seeing how things worked, it soon became apparent that those routines are setup to use the USB interrupts(even though PBP doesn't use them that way). It just needs a "kick-start" to get it going. The "kick-start" is simply a tight loop servicing the USB until the driver gets to the "CONFIGURED_STATE". After that it takes off and handles itself.

    But the best part is that it doesn't use ANY PBP system variables to service the USB. So the whole thing can be treated like ASM interrupts, and tied directly into the USB_INT interrupt.

    This also seems to improve the response time since it can react immediately to each step of the USB protocol, instead of after each interval of the timer, or whenever ON INTERRUPT get's around to it, but I don't have any hard data to back that up yet.

    Here's your PIC program from the [USBDemo, something to learn USB a little bit ]thread /.zip file.
    Modified to use DT_INTS-18 and the USB interrupt.
    All the other files are the same.

    http://www.darreltaylor.com/files/USBDemo2_DT.txt

    Works great with the "Mister E USBDemo" program.
    <br>
    DT

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