USB CDC with DT_INTS


Closed Thread
Results 1 to 8 of 8
  1. #1
    Join Date
    Feb 2011
    Location
    Michigan, USA
    Posts
    33

    Default USB CDC with DT_INTS

    Hello All,
    First of all let me say thanks to the lot of you for all the great info here in this forum. I've
    recently used a few ideas from here and I didn't want to just take the code and run. Also
    for DT_Ints. Code with this much functionality deserves a thanks. I'm sure it will probably
    save my dignity some day.

    I've been using the PIC for about 6 years now for work and home projects and I've managed
    to learn on my own but I think I'm getting into deeper waters now. I need to ask for help.

    I came across this post but I am having trouble making it work.
    http://www.picbasic.co.uk/forum/show...4292#post94292

    The PC does not recognize the device at all. But before you say, uh oh ... not another
    clown who can't figure out USB , I have had success using other techniques.

    I currently have a good connection using a timer interrupt to run USBSERVICE. The timer is set for 2.7ms. Anything slower and I have an intermittent connection. (or not at all)
    I've used this at home with great success. But recently I've tried this on a computer at work
    and it drops the connection after about 10 minutes. Tomorrow I am going to increase the
    timer interrupt to see if that fixes it.

    But I saw the post about CDC and USB interrupts and said that's a hell of lot better than a timer.

    Here's what I'm using:
    WinXP
    PBPro v2.6b
    MPLab v8.33
    PIC18F2458
    Vusb 0.33uF
    PicKit2
    20MHz Ext. Clock

    Any suggestions is much appreciated
    thanks -
    Mike
    Last edited by mackrackit; - 24th March 2011 at 04:07.

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924

    Default Re: USB CDC with DT_INTS

    The link you gave is bad and I could not quite figure out the thread you were looking at. And we do not have your code and configs....
    But maybe this will help
    http://www.picbasic.co.uk/forum/cont...USB-SD-LOGGING
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Feb 2011
    Location
    Michigan, USA
    Posts
    33

    Default Re: USB CDC with DT_INTS

    Hi mackrackit,
    Thanks for the reply. Sorry about the link. Let me try it again.
    http://www.picbasic.co.uk/forum/show...4292#post94292


    Well I see in your code that it is different than Darrel's original post. It has more
    USBINIT and USBSERVICE statements.

    My Code: (copied from the bad link)
    -----------
    PAUSE 100
    USBINIT
    USBSERVICE
    UIE = $7F
    UEIE = $9F
    @ INT_ENABLE USB_INT


    Your Code:
    -------------
    PAUSE 100
    USBINIT
    USBSERVICE
    UIE = $7F
    UEIE = $9F
    PAUSE 500
    USBINIT
    USBSERVICE
    @ INT_ENABLE USB_INT
    USBSERVICE

    That would be great if that's all it is. I will try it tonight and let you know.
    If it doesn't work, I will post my code and configs.

  4. #4
    Join Date
    Feb 2011
    Location
    Michigan, USA
    Posts
    33

    Default Re: USB CDC with DT_INTS

    Well I tried it at work with a 18F4458 and still couldn't get it to connect. I verified my hardware setup was good by loading the code with the timer interrupt and that works fine.

    Here is my complete program:
    Code:
    '***************************************************************************************
    '	Title:		USB CDC and DT_INTS Testing
    '	CPU:		18F4458
    '   Clock:		20 MHz External Clock
    '
    '****************************************************************************************
    
    ASM
    	__CONFIG    _CONFIG1L, _PLLDIV_5_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
    	__CONFIG    _CONFIG1H, _FOSC_ECPLLIO_EC_1H & _FCMEN_OFF_1H & _IESO_OFF_1H
    	__CONFIG    _CONFIG2L, _PWRT_OFF_2L & _BOR_ON_2L & _BORV_2_2L & _VREGEN_ON_2L
    	__CONFIG    _CONFIG2H, _WDT_OFF_2H & _WDTPS_512_2H
    	__CONFIG    _CONFIG3H, _CCP2MX_ON_3H & _PBADEN_OFF_3H & _LPT1OSC_OFF_3H & _MCLRE_OFF_3H
    	__CONFIG    _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L & _XINST_OFF_4L & _DEBUG_OFF_4L
    ENDASM
    
    
    DEFINE OSC 48
    DEFINE NO_CLRWDT 1
    DEFINE USB_BUS_SENSE PORTD,3
    
    INCLUDE "cdc_desc.bas"
    INCLUDE "DT_INTS-18.bas"
    
    '---[Interrupts List]---
    ASM
    INT_LIST  macro   ;Source,   Label,          Type,  ResetFlag?
        INT_Handler   USB_INT,  USBServiceISR,  ASM,   yes
        endm
        INT_CREATE
    ENDASM
    
    
    	goto InitChip
    
    
    '----[Interrupt handler -- Service USB]--------------------------------------------------
    ASM
    USBServiceISR:
    	USBSERVICE
    	INT_RETURN
    ENDASM
    
    
    
    '---[Initialize Chip]--------------------------------------------------------------------
    InitChip:
    	PAUSE 100
    	USBINIT
    	USBSERVICE
    	UIE = $7F
    	UEIE = $9F
    	PAUSE 500
    	USBINIT
    	USBSERVICE
    	@ INT_ENABLE USB_INT
    	USBSERVICE
    
    	PORTA = 0
    	PORTB = 0
    	PORTC = 0
    	PORTD = 0
    	PORTE = 0
    
    	'setup port i/o
    	TRISA = %00000000
    	TRISB = %11111111
    	TRISC = %00110000
    	TRISD = %00001000
    	TRISE = %00000000
    
    	'all dig
    	ADCON1 = %00001111
    	
    	'enable port b pullups
    	INTCON2.7 = 0
    
    	
    
    Main:
    	goto Main
    
    
    	end

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

    Default Re: USB CDC with DT_INTS

    Tachyon,

    USBSERVICE is a PBP statement, not an ASM statement. So it can't be in an ASM/ENDASM block.
    It must be like this ...
    Code:
    '----[Interrupt handler -- Service USB]--------------------------------------------------
    USBServiceISR:
            USBSERVICE
    @   INT_RETURN
    Then add an underscore in the INT_Handler statement.
    Code:
    '---[Interrupts List]---
    ASM
    INT_LIST  macro   ;Source,   Label,          Type,  ResetFlag?
        INT_Handler   USB_INT,  _USBServiceISR,  ASM,   yes
        endm
        INT_CREATE
    ENDASM
    You can only have 1 USBINIT in your program.
    And there should never be a USBSERVICE after the interrupt has been enabled.
    Interrupting a USBSERVICE to do a USBSERVICE can cause bad things to happen.
    Code:
    '---[Initialize Chip]--------------------------------------------------------------------
    InitChip:
    	PAUSE 100
    	USBINIT
    	USBSERVICE
    	UIE = $7F
    	UEIE = $9F
    ;	PAUSE 500
    ;	USBINIT
    ;	USBSERVICE
    	@ INT_ENABLE USB_INT
    ;	USBSERVICE
    The following program works perfectly here on a LAB-XUSB with an 18F4550.
    Code:
    '***************************************************************************************
    '	Title:		USB CDC and DT_INTS Testing
    '	CPU:		18F4458
    '   Clock:		20 MHz External Clock
    '
    '****************************************************************************************
    
    ASM
    	__CONFIG    _CONFIG1L, _PLLDIV_5_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
    	__CONFIG    _CONFIG1H, _FOSC_HSPLL_HS_1H & _FCMEN_OFF_1H & _IESO_OFF_1H
    ;	__CONFIG    _CONFIG1H, _FOSC_ECPLLIO_EC_1H & _FCMEN_OFF_1H & _IESO_OFF_1H
    	__CONFIG    _CONFIG2L, _PWRT_OFF_2L & _BOR_ON_2L & _BORV_2_2L & _VREGEN_ON_2L
    	__CONFIG    _CONFIG2H, _WDT_OFF_2H & _WDTPS_512_2H
    	__CONFIG    _CONFIG3H, _CCP2MX_ON_3H & _PBADEN_OFF_3H & _LPT1OSC_OFF_3H & _MCLRE_OFF_3H
    	__CONFIG    _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L & _XINST_OFF_4L & _DEBUG_OFF_4L
    ENDASM
    
    
    DEFINE OSC 48
    DEFINE NO_CLRWDT 1
    DEFINE USB_BUS_SENSE PORTD,3
    
    INCLUDE "cdc_desc.bas"
    INCLUDE "DT_INTS-18.bas"
    
    '---[Interrupts List]---
    ASM
    INT_LIST  macro   ;Source,   Label,          Type,  ResetFlag?
        INT_Handler   USB_INT,  _USBServiceISR,  ASM,   yes
        endm
        INT_CREATE
    ENDASM
    
    
    	goto InitChip
    
    
    '----[Interrupt handler -- Service USB]--------------------------------------------------
    USBServiceISR:
    	USBSERVICE
    @	INT_RETURN
    
    
    
    '---[Initialize Chip]--------------------------------------------------------------------
    InitChip:
    	PAUSE 100
    	USBINIT
    	USBSERVICE
    	UIE = $7F
    	UEIE = $9F
    	@ INT_ENABLE USB_INT
    
    	PORTA = 0
    	PORTB = 0
    	PORTC = 0
    	PORTD = 0
    	PORTE = 0
    
    	'setup port i/o
    	TRISA = %00000000
    	TRISB = %11111111
    	TRISC = %00110000
    	TRISD = %00001000
    	TRISE = %00000000
    
    	'all dig
    	ADCON1 = %00001111
    	
    	'enable port b pullups
    	INTCON2.7 = 0
    
    	
    
    Main:
    	goto Main
    
    
    	end
    Make sure you have 0.1uF bypass capacitors from VDD to VSS.
    And some people say that you also need 0.1uF from the USB +5V to VSS, but I've never had to do that.
    DT

  6. #6
    Join Date
    Feb 2011
    Location
    Michigan, USA
    Posts
    33

    Default Re: USB CDC with DT_INTS

    Hello Darrel,
    Sorry but that code is not connecting either. I copied everything over. And it compiles OK.
    What is also concerning me is the version I have with the timer interrupt is also dropping the connection after about a half hour. This is after I shortened the interrupt time to 1.3ms. Should I shorten the time even more? Is it because its a USB 1.1 computer? I haven't seen
    it drop the connection on a USB 2.0 computer yet.

    I've tried all I could think of on the USB Interrupt version. I might have to give up on that one
    for now and just focus on the timer interrupt version.

    So I'll increase the size of cap on Vusb pin and see if that helps.

    Do you think shortening the interrupt time will help?

    Thank you for all your help.
    Regards,
    Mike

  7. #7
    Join Date
    Feb 2011
    Location
    Michigan, USA
    Posts
    33

    Default Re: USB CDC with DT_INTS

    Just an update if anyone is interested. The PIC on the USB 2.0 computer is over 6 hours and
    has not dropped its connection. The same PIC on the USB 1.1 computer could not hold its
    connection for longer than 20 minutes or so.
    I am using a timer interrupt (0.6ms) to execute the USBSERVICE routine. If I ever find an
    answer why than I will post it back here.

    As far as the USB interrupt using DT-INTS-18 v34 for CDC, I haven't a clue why it won't
    connect for me. I know the interrupt is not happening at all. And I know my hardware
    works with the timer interrupt. If I find what I'm missing than I'll post that also.

    Mike

  8. #8
    Join Date
    Feb 2011
    Location
    Michigan, USA
    Posts
    33

    Default Re: USB CDC with DT_INTS

    Eureka! Yes I'm that happy. I found the reason why the USB interrupt was not working.
    It was the line I uncommented in the cdc_desc.bas file (#define USE_USB_BUS_SENSE_IO).

    I read somewhere, don't remember where, when using self powered circuit one should
    define a Vbus sense I/0 and uncomment the line above in the cdc_desc file. This is supposed to make the design more USB compliant. If the user unplugs the USB cable, the 3V reg. is turned off. I verified this with a meter and peeked how it is done in the assembly USBSERVICE routine.

    I don't mind if the 3V reg. stays on in my design. I am using a power supply. But I guess
    it might be a concern in a battery powered design.

    I should have mentioned the uncommenting bit in my post. I ASSUMED....

    Anyway, thanks Darrel for giving me my timer back.
    This is fantastic -
    Mike

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts