USBDemo, something to learn USB a little bit - Page 7


Closed Thread
Page 7 of 7 FirstFirst ... 34567
Results 241 to 279 of 279
  1. #241
    Join Date
    Dec 2006
    Posts
    32


    Did you find this post helpful? Yes | No

    Default

    Doh, I suppose I should have looked a bit more deeply on the forum! lol.
    I did see this ages ago and it slipped my memory, but found DT's USB_ASM_Service file and tried that and BINGO! sorted it PHEW!

    Must say thanks to DT as it seems that whenever I see someone (even myself!) get stuck with something, a quick delve into the forums usually finds a post by Darrel that sorts it!

    Mark

  2. #242
    Join Date
    Dec 2010
    Location
    Tokyo
    Posts
    3


    Did you find this post helpful? Yes | No

    Default USBout sends garbage byte ahead of message

    Hi,
    I am new and this is my first posting, please don't shoot me in case of mistakes.

    Today I started to use PicPasic Pro 2.6 with MPLAB IDE 8.60 and tried out the usb_demo.bas sample immediately.

    MPLAB file list:
    CDC_DEMO.BAS
    CDC_DESC.BAS
    USB_CDC.ASM
    USB_CDC.INC
    USB_MEM.ASM
    USB_DEV.ASM
    USB_DEV.INC


    CDC_DEMO.BAS Code:
    Code:
    ' USB sample program for PIC18F4550 CDC serial port emulation
    '  Requires PBP 2.60 or later
    
    '  Compilation of this program requires that specific support files be
    '  available in the source directory.  For detailed information, see
    '  the file PBP\USB18\USB.TXT.
    
    	Include	"cdc_desc.bas"	' Include the HID descriptors
    
    Define  OSC     48
    
    buffer	Var	Byte[16]
    cnt	Var	Byte
    
    
    	OSCTUNE.6 = 1		' Enable PLL for 18F87J50 family
    	Pause 10
    
    	USBInit			' Get USB going
    
    ' Wait for USB input
    idleloop:
    	USBService		' Must service USB regularly
    	cnt = 16		' Specify input buffer size
    	USBIn 3, buffer, cnt, idleloop
    
    ' Message received
    	buffer[0] = "H"
    	buffer[1] = "e"
    	buffer[2] = "l"
    	buffer[3] = "l"
    	buffer[4] = "o"
    	buffer[5] = " "
    	buffer[6] = "W"
    	buffer[7] = "o"
    	buffer[8] = "r"
    	buffer[9] = "l"
    	buffer[10] = "d"
    	buffer[11] = 13
    	buffer[12] = 10
    	buffer[13] = 0
    
    outloop:
    	USBService		' Must service USB regularly
    	USBOut 3, buffer, 14, outloop
    
    	Goto idleloop		' Wait for next buffer
    The test program in the PC is a simple VB6 routine:
    Code:
    ;---------------- Write to PIC --------------------------
    Private Sub Out3Byte(bus As Byte, adr As Byte, data As Byte)
    Dim Com(2) As Byte
    Com(0) = bus: Com(1) = adr: Com(2) = data
        '3 byte send
        MSComm1.Output = Com
    End Sub
    ;----------------- Receive from PIC ----------------------
    Private Sub MSComm1_OnComm()
    Dim data As String, ende As Boolean
    ende = False: Text1.Text = ""
        Static IsActive As Boolean
        MSComm1.RThreshold = 0
        If IsActive Then
            Label4.Caption = "OnComm Ueberschneidung"
           Exit Sub
        End If
            Do Until ende
                If MSComm1.InBufferCount > 1 Then     'min 1byte recvd
                data = MSComm1.Input
                Text1.Text = Text1.Text + Hex$(AscB(data)) + " "
                Else
                ende = True
                End If
            DoEvents
            Loop
    IsActive = False
    MSComm1.RThreshold = 1
    End Sub
    In general it works fine but, for one little but crucial problem I cant find the reason, so I suspect the problem to be with the PBP compilation.

    The 3 bytes from the PC are always received properly, but the "Hello World" message arrives in the PC correctly only the first time immediately after Com Port Open statement. When continuously sending and receiving, at the beginning of the messages there is always one garbage byte ahead of "Hello World". The value is always the same, but depends one actual memory location in PIC RAM of "buffer Var Byte[16]"

    Can anyone help?

    CDC_DEMO_transmission_log:
    Code:
    35	VB6.EXE	IOCTL_SERIAL_SET_BAUD_RATE	USBSER000	SUCCESS	Rate: 115200	
    36	VB6.EXE	IOCTL_SERIAL_CLR_RTS	USBSER000	SUCCESS		
    37	VB6.EXE	IOCTL_SERIAL_SET_DTR	USBSER000	SUCCESS		
    38	VB6.EXE	IOCTL_SERIAL_SET_LINE_CONTROL	USBSER000	SUCCESS	StopBits: 1 Parity: NONE WordLength: 8	
    39	VB6.EXE	IOCTL_SERIAL_SET_CHAR	USBSER000	SUCCESS	EOF:1a ERR:0 BRK:0 EVT:0 XON:11 XOFF:13	
    40	VB6.EXE	IOCTL_SERIAL_SET_HANDFLOW	USBSER000	SUCCESS	Shake:1 Replace:0 XonLimit:8000 XoffLimit:8000	
    41	VB6.EXE	IOCTL_SERIAL_GET_COMMSTATUS	USBSER000	SUCCESS		
    42	VB6.EXE	IRP_MJ_WRITE	USBSER000	SUCCESS	Length 3: A1 A9 AF	<3 bytes send 	
    43	VB6.EXE	IOCTL_SERIAL_GET_COMMSTATUS	USBSER000	SUCCESS		
    44	VB6.EXE	IOCTL_SERIAL_SET_WAIT_MASK	USBSER000	SUCCESS	Mask: RXCHAR TXEMPTY CTS DSR RLSD BRK ERR RING 	
    45	VB6.EXE	IOCTL_SERIAL_GET_COMMSTATUS	USBSER000	SUCCESS		
    46	VB6.EXE	IOCTL_SERIAL_WAIT_ON_MASK	USBSER000	SUCCESS		
    47	VB6.EXE	IOCTL_SERIAL_GET_COMMSTATUS	USBSER000	SUCCESS		
    48	VB6.EXE	IRP_MJ_READ	USBSER000	SUCCESS	Length 1: 48 	   <----- Starts with "H"
    49	VB6.EXE	IOCTL_SERIAL_GET_COMMSTATUS	USBSER000	SUCCESS		
    50	VB6.EXE	IOCTL_SERIAL_GET_COMMSTATUS	USBSER000	SUCCESS		
    51	VB6.EXE	IRP_MJ_READ	USBSER000	SUCCESS	Length 1: 65 	
    52	VB6.EXE	IOCTL_SERIAL_GET_COMMSTATUS	USBSER000	SUCCESS		
    53	VB6.EXE	IOCTL_SERIAL_GET_COMMSTATUS	USBSER000	SUCCESS		
    54	VB6.EXE	IRP_MJ_READ	USBSER000	SUCCESS	Length 1: 6C 	
    55	VB6.EXE	IOCTL_SERIAL_GET_COMMSTATUS	USBSER000	SUCCESS		
    56	VB6.EXE	IOCTL_SERIAL_GET_COMMSTATUS	USBSER000	SUCCESS		
    57	VB6.EXE	IRP_MJ_READ	USBSER000	SUCCESS	Length 1: 6C 	
    58	VB6.EXE	IOCTL_SERIAL_GET_COMMSTATUS	USBSER000	SUCCESS		
    59	VB6.EXE	IOCTL_SERIAL_GET_COMMSTATUS	USBSER000	SUCCESS		
    60	VB6.EXE	IRP_MJ_READ	USBSER000	SUCCESS	Length 1: 6F 	
    61	VB6.EXE	IOCTL_SERIAL_GET_COMMSTATUS	USBSER000	SUCCESS		
    62	VB6.EXE	IOCTL_SERIAL_GET_COMMSTATUS	USBSER000	SUCCESS		
    63	VB6.EXE	IRP_MJ_READ	USBSER000	SUCCESS	Length 1: 20 	
    64	VB6.EXE	IOCTL_SERIAL_GET_COMMSTATUS	USBSER000	SUCCESS		
    65	VB6.EXE	IOCTL_SERIAL_GET_COMMSTATUS	USBSER000	SUCCESS		
    66	VB6.EXE	IRP_MJ_READ	USBSER000	SUCCESS	Length 1: 57 	
    67	VB6.EXE	IOCTL_SERIAL_GET_COMMSTATUS	USBSER000	SUCCESS		
    68	VB6.EXE	IOCTL_SERIAL_GET_COMMSTATUS	USBSER000	SUCCESS		
    69	VB6.EXE	IRP_MJ_READ	USBSER000	SUCCESS	Length 1: 6F 	
    70	VB6.EXE	IOCTL_SERIAL_GET_COMMSTATUS	USBSER000	SUCCESS		
    71	VB6.EXE	IOCTL_SERIAL_GET_COMMSTATUS	USBSER000	SUCCESS		
    72	VB6.EXE	IRP_MJ_READ	USBSER000	SUCCESS	Length 1: 72 	
    73	VB6.EXE	IOCTL_SERIAL_GET_COMMSTATUS	USBSER000	SUCCESS		
    74	VB6.EXE	IOCTL_SERIAL_GET_COMMSTATUS	USBSER000	SUCCESS		
    75	VB6.EXE	IRP_MJ_READ	USBSER000	SUCCESS	Length 1: 6C 	
    76	VB6.EXE	IOCTL_SERIAL_GET_COMMSTATUS	USBSER000	SUCCESS		
    77	VB6.EXE	IOCTL_SERIAL_GET_COMMSTATUS	USBSER000	SUCCESS		
    78	VB6.EXE	IRP_MJ_READ	USBSER000	SUCCESS	Length 1: 64 	
    79	VB6.EXE	IOCTL_SERIAL_GET_COMMSTATUS	USBSER000	SUCCESS		
    80	VB6.EXE	IOCTL_SERIAL_GET_COMMSTATUS	USBSER000	SUCCESS		
    81	VB6.EXE	IRP_MJ_READ	USBSER000	SUCCESS	Length 1: 0D 	
    82	VB6.EXE	IOCTL_SERIAL_GET_COMMSTATUS	USBSER000	SUCCESS		
    83	VB6.EXE	IOCTL_SERIAL_GET_COMMSTATUS	USBSER000	SUCCESS		
    84	VB6.EXE	IRP_MJ_READ	USBSER000	SUCCESS	Length 1: 0A 	
    85	VB6.EXE	IOCTL_SERIAL_GET_COMMSTATUS	USBSER000	SUCCESS		
    86	VB6.EXE	IOCTL_SERIAL_GET_COMMSTATUS	USBSER000	SUCCESS		
    87	VB6.EXE	IOCTL_SERIAL_GET_COMMSTATUS	USBSER000	SUCCESS		
    88	VB6.EXE	IOCTL_SERIAL_GET_COMMSTATUS	USBSER000	SUCCESS		
    89	VB6.EXE	IOCTL_SERIAL_GET_PROPERTIES	USBSER000	SUCCESS		
    90	VB6.EXE	IRP_MJ_WRITE	USBSER000	SUCCESS	Length 3: A1 A9 AF	<3bytes send 	
    91	VB6.EXE	IOCTL_SERIAL_GET_COMMSTATUS	USBSER000	SUCCESS		
    92	VB6.EXE	IOCTL_SERIAL_SET_WAIT_MASK	USBSER000	SUCCESS	Mask: RXCHAR TXEMPTY CTS DSR RLSD BRK ERR RING 	
    93	B6.EXE	IOCTL_SERIAL_WAIT_ON_MASK	USBSER000	SUCCESS		
    94	VB6.EXE	IOCTL_SERIAL_GET_COMMSTATUS	USBSER000	SUCCESS		
    95	VB6.EXE	IOCTL_SERIAL_GET_COMMSTATUS	USBSER000	SUCCESS		
    96	VB6.EXE	IRP_MJ_READ	USBSER000	SUCCESS	Length 1: 00		<----- starts with "0x00"
    97	VB6.EXE	IOCTL_SERIAL_GET_COMMSTATUS	USBSER000	SUCCESS		
    98	VB6.EXE	IOCTL_SERIAL_GET_COMMSTATUS	USBSER000	SUCCESS		
    99	B6.EXE	IRP_MJ_READ	USBSER000	SUCCESS	Length 1: 48 		<----- "H" is 2nd byte
    100	VB6.EXE	IOCTL_SERIAL_GET_COMMSTATUS	USBSER000	SUCCESS		
    101	VB6.EXE	IOCTL_SERIAL_GET_COMMSTATUS	USBSER000	SUCCESS		
    102	VB6.EXE	IRP_MJ_READ	USBSER000	SUCCESS	Length 1: 65 	
    103	VB6.EXE	IOCTL_SERIAL_GET_COMMSTATUS	USBSER000	SUCCESS		
    104	VB6.EXE	IOCTL_SERIAL_GET_COMMSTATUS	USBSER000	SUCCESS		
    105	VB6.EXE	IRP_MJ_READ	USBSER000	SUCCESS	Length 1: 6C 	
    106	VB6.EXE	IOCTL_SERIAL_GET_COMMSTATUS	USBSER000	SUCCESS		
    107	VB6.EXE	IOCTL_SERIAL_GET_COMMSTATUS	USBSER000	SUCCESS		
    108	VB6.EXE	IRP_MJ_READ	USBSER000	SUCCESS	Length 1: 6C 	
    109	VB6.EXE	IOCTL_SERIAL_GET_COMMSTATUS	USBSER000	SUCCESS		
    110	VB6.EXE	IOCTL_SERIAL_GET_COMMSTATUS	USBSER000	SUCCESS		
    111	VB6.EXE	IRP_MJ_READ	USBSER000	SUCCESS	Length 1: 6F 	
    112	VB6.EXE	IOCTL_SERIAL_GET_COMMSTATUS	USBSER000	SUCCESS		
    113	VB6.EXE	IOCTL_SERIAL_GET_COMMSTATUS	USBSER000	SUCCESS		
    114	VB6.EXE	IRP_MJ_READ	USBSER000	SUCCESS	Length 1: 20 	
    115	VB6.EXE	IOCTL_SERIAL_GET_COMMSTATUS	USBSER000	SUCCESS		
    116	VB6.EXE	IOCTL_SERIAL_GET_COMMSTATUS	USBSER000	SUCCESS		
    117	VB6.EXE	IRP_MJ_READ	USBSER000	SUCCESS	Length 1: 57 	
    118	VB6.EXE	IOCTL_SERIAL_GET_COMMSTATUS	USBSER000	SUCCESS		
    119	VB6.EXE	IOCTL_SERIAL_GET_COMMSTATUS	USBSER000	SUCCESS		
    120	VB6.EXE	IRP_MJ_READ	USBSER000	SUCCESS	Length 1: 6F 	
    121	VB6.EXE	IOCTL_SERIAL_GET_COMMSTATUS	USBSER000	SUCCESS		
    122	VB6.EXE	IOCTL_SERIAL_GET_COMMSTATUS	USBSER000	SUCCESS		
    123	VB6.EXE	IRP_MJ_READ	USBSER000	SUCCESS	Length 1: 72 	
    124	VB6.EXE	IOCTL_SERIAL_GET_COMMSTATUS	USBSER000	SUCCESS		
    125	VB6.EXE	IOCTL_SERIAL_GET_COMMSTATUS	USBSER000	SUCCESS		
    126	VB6.EXE	IRP_MJ_READ	USBSER000	SUCCESS	Length 1: 6C 	
    127	VB6.EXE	IOCTL_SERIAL_GET_COMMSTATUS	USBSER000	SUCCESS		
    128	VB6.EXE	IOCTL_SERIAL_GET_COMMSTATUS	USBSER000	SUCCESS		
    129	VB6.EXE	IRP_MJ_READ	USBSER000	SUCCESS	Length 1: 64 	
    130	VB6.EXE	IOCTL_SERIAL_GET_COMMSTATUS	USBSER000	SUCCESS		
    131	VB6.EXE	IOCTL_SERIAL_GET_COMMSTATUS	USBSER000	SUCCESS		
    132	VB6.EXE	IRP_MJ_READ	USBSER000	SUCCESS	Length 1: 0D 	
    133	VB6.EXE	IOCTL_SERIAL_GET_COMMSTATUS	USBSER000	SUCCESS		
    134	VB6.EXE	IOCTL_SERIAL_GET_COMMSTATUS	USBSER000	SUCCESS		
    135	VB6.EXE	IRP_MJ_READ	USBSER000	SUCCESS	Length 1: 0A 	
    136	VB6.EXE	IOCTL_SERIAL_GET_COMMSTATUS	USBSER000	SUCCESS		
    137	VB6.EXE	IOCTL_SERIAL_GET_COMMSTATUS	USBSER000	SUCCESS		
    138	VB6.EXE	IOCTL_SERIAL_GET_COMMSTATUS	USBSER000	SUCCESS		
    139	VB6.EXE	IOCTL_SERIAL_GET_COMMSTATUS	USBSER000	SUCCESS		
    140	VB6.EXE	IOCTL_SERIAL_GET_PROPERTIES	USBSER000	SUCCESS		
    141	VB6.EXE	IRP_MJ_WRITE	USBSER000	SUCCESS	Length 3: A1 A9 AF	<3 bytes send	
    142	VB6.EXE	IOCTL_SERIAL_GET_COMMSTATUS	USBSER000	SUCCESS		
    143	VB6.EXE	IOCTL_SERIAL_SET_WAIT_MASK	USBSER000	SUCCESS	Mask: RXCHAR TXEMPTY CTS DSR RLSD BRK ERR RING 	
    144	VB6.EXE	IOCTL_SERIAL_WAIT_ON_MASK	USBSER000	SUCCESS		
    145	VB6.EXE	IOCTL_SERIAL_GET_COMMSTATUS	USBSER000	SUCCESS		
    146	VB6.EXE	IOCTL_SERIAL_GET_COMMSTATUS	USBSER000	SUCCESS		
    147	VB6.EXE	IRP_MJ_READ	USBSER000	SUCCESS	Length 1: 00 <garbage again
    148	VB6.EXE	IOCTL_SERIAL_GET_COMMSTATUS	USBSER000	SUCCESS		
    149	VB6.EXE	IOCTL_SERIAL_GET_COMMSTATUS	USBSER000	SUCCESS		
    150	VB6.EXE	IRP_MJ_READ	USBSER000	SUCCESS	Length 1: 48 
    
    
    Last edited by sjm2000; - 3rd December 2010 at 13:03.

  3. #243
    Join Date
    Dec 2010
    Location
    Tokyo
    Posts
    3


    Did you find this post helpful? Yes | No

    Default USBOut out byte mixup

    Hi,

    I am still stuck with my proplem, therefore, I modified the cdc_demo.bas to be able to change the outbuffer contents:
    Code:
    ' USB sample program for PIC18F4550 CDC serial port emulation
    '  Requires PBP 2.60 or later
    
    '  Compilation of this program requires that specific support files be
    '  available in the source directory.  For detailed information, see
    '  the file PBP\USB18\USB.TXT.
    
    	Include	"cdc_desc.bas"	' Include the HID descriptors
    
    Define  OSC     48
    
    inbuffer	Var	Byte[15]
    outbuffer	Var	Byte[15]
    icnt	Var	Byte
    ocnt	Var	Byte
    
    	OSCTUNE.6 = 1		' Enable PLL for 18F87J50 family
    	Pause 10
    
    	USBInit			' Get USB going
    
    ' Wait for USB input
    idleloop:
    
    	icnt = 6		' Specify input buffer size
    	USBService		' Must service USB regularly
    	USBIn 3, inbuffer, icnt, idleloop
    
    ' Message received
    	outbuffer[0] = inbuffer[0]
    	outbuffer[1] = inbuffer[1]
    	outbuffer[2] = inbuffer[2]
    	outbuffer[3] = inbuffer[3] 
    	outbuffer[4] = 0
    	outbuffer[5] = icnt
    	outbuffer[6] = 0
    	outbuffer[7] = $AA
    	outbuffer[8] = $BB
    	outbuffer[9] = $CC
    	outbuffer[10] = $DD
    	outbuffer[11] = 0
    	outbuffer[12] = inbuffer[0]
    	outbuffer[13] = inbuffer[1]
    	outbuffer[14] = inbuffer[2]
    
    outloop:
    	USBService		' Must service USB regularly
    	ocnt = 14
    	USBOut 3, outbuffer, ocnt, outloop
    
    	Goto idleloop		' Wait for next buffer
    I continued testing and found out:

    With ocnt = 14

    The first USBOut after com port open in PC test program is actually

    outbuffer[0]....outbuffer[12] -> in total 13 bytes

    from the second output it is always the same

    outbuffer[13], outbuffer[0], outbuffer[1]...., outbuffer[12] ->in total 14 bytes


    I suspect in the appended .inc and .asm files might be a definition mistake, but since I do not understand the code written there, I really need the help of an USB specialist in this Forum to overcome this problem.

    To all the USB experts in this Forum, please Help.

  4. #244
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default

    This is a update to Mister E's VB6 demo program, and firmware that uses Darrel's DT_HID260.pbp include file. It brings back some of the functions that went away with the HID update, and it adds a few more. It now transfers 10 bit A/D conversions to the PC, and it has a really low bandwidth mschart function. It also transfers the port info up to the computer in a single byte, and it's read by VB in bits. (It is hard to read bits with VB!) Ports are changed to match the Olimex PIC-USB-STK ( http://www.olimex.com/dev/pic-usb-stk.html ) . On the chart, it's a little over a second from left to right. By the way, if anyone knows how to keep the mschart from flickering as it is being redrawn, please let me know.

    Name:  scope.PNG
Views: 16546
Size:  41.6 KB


    VB6 doesn't make it very easy to be sure you have include all the necessary files, so if you have issues, let me know. The code was made for a PIC18F4550 with a 20 mhz crystal. You will also need Darrel's DT_HID260 file from here: http://www.picbasic.co.uk/forum/show...0434#post80434

    (Thanks Steve and Darrel for giving me the USB bug!)

    Code:
    '****************************************************************************
    '*  Name    : USB_Demo_4_HID.pbp                                            *
    '*  Author  : Walter Dunckel ScaleRobotics using Darrels example as template*
    '*  Notice  : Copyright (c) 2011                                            *
    '*  Date    : 1/13/2011                                                     *
    '*  Version : 1.1                                                           *
    '*  Notes   : Added Darrel's text example                                   *
    '*          :                                                               *
    '****************************************************************************
    ;--- if you un-comment these, you must comment the ones in the .inc file ---
    ASM  ; 18F2550/4550, 20mhz crystal
       __CONFIG    _CONFIG1L, _PLLDIV_5_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
       __CONFIG    _CONFIG1H, _FOSC_HSPLL_HS_1H
       __CONFIG    _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H
       __CONFIG    _CONFIG3H, _PBADEN_OFF_3H
       __CONFIG    _CONFIG4L, _LVP_OFF_4L & _XINST_OFF_4L
    ENDASM
    'add if using Microchip's HID Bootloader
    'DEFINE LOADER_USED 1
    'DEFINE RESET_ORG 1000h ' For Microchip USB Bootloader
     
    ;ASM  ; 18F13K50/14K50  Only 12mhz crystal can be used for USB
    ;    __CONFIG    _CONFIG1L, _CPUDIV_NOCLKDIV_1L & _USBDIV_OFF_1L
    ;    __CONFIG    _CONFIG1H, _FOSC_HS_1H & _PLLEN_ON_1H & _PCLKEN_ON_1H & _FCMEN_OFF_1H & _IESO_OFF_1H
    ;    
    ;    ;added
    ;    __CONFIG    _CONFIG2H, _WDTEN_ON_2H & _WDTPS_512_2H
    ;    __CONFIG    _CONFIG3H, _MCLRE_ON_3H 
    ;    __CONFIG    _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L & _BBSIZ_OFF_4L & _XINST_OFF_4L
    ;ENDASM
     
    DEFINE OSC 48
    clear
     
    PortA = %00000000
    TrisA = %00000001
    PortB = %00000000
    TrisB = %11110100        'make pushbuttons inputs for PIC-USB-STK
    'TrisB = %00010000 'for 18k50
    PortC = %00000000
    TrisC = %00000000
    TrisD = %00000000
    CMCON = 7
    'CM1CON0 = 7  'for 18f14k50
    'CM2CON0 = 7
     
            '   CCP/PWM
            '   -------
    CCP1CON =   %00001100       ' CCP1, PWM mode
    CCP2CON =   %00001100       ' CCP2, PWM mode
    PR2     =   249             ' 12khz PWM Freq
    T2CON   =   %00000101       ' TMR2 on, prescaler 1:4
    ;--- Setup Interrupts ------------------------------------------------------
    INCLUDE "DT_INTS-18.bas"     ; Base Interrupt System
    ASM
    INT_LIST  macro    ; IntSource,          Label,  Type, ResetFlag?
            INT_Handler   USB_Handler
        endm
        INT_CREATE               ; Creates the interrupt processor
    endasm
     
    ;--- Setup USB -------------------------------------------------------------
    INCLUDE "DT_HID260.pbp"
     
    DEFINE USB_VENDORID    6017
    DEFINE USB_PRODUCTID   2000
    DEFINE USB_VERSION     1
    DEFINE USB_VENDORNAME  "ScaleRobotics"
    DEFINE USB_PRODUCTNAME "Cheap-Scope"
    DEFINE USB_SERIAL      "001"
    DEFINE USB_INSIZE      8   ;was 32  IN report is PIC to PC (8,16,32,64)
    DEFINE USB_OUTSIZE     16   ; OUT report is PC to PIC
    DEFINE USB_POLLIN      10   ; Polling times in mS, MIN=1 MAX=10
    DEFINE USB_POLLOUT     10
     
    ; --- Each USB LED is optional, comment them if not used ----
    DEFINE USB_LEDPOLARITY 1       ; LED ON State [0 or 1]  (default = 1)
    'DEFINE USB_PLUGGEDLED  PORTD,0 ; LED indicates if USB is connected
    'DEFINE USB_TXLED       PORTD,2 ;  "      "     data being sent to PC
    'DEFINE USB_RXLED       PORTD,1 ;  "      "     data being received from PC
     
    OutCount    VAR  WORD : OutCount = 0
    Value       VAR  word   'analog result from AN0
    Value2      var  word   'analog result from AN11
    X           VAR  WORD
    counter     var  byte
    Duty1       var  word EXT ' make them available 
    Duty2       var  byte EXT
    smallvalue  var  byte
     
    ;--- Setup ADC -------------------------------------------------------------
    DEFINE ADC_BITS 10 ; Number of bits in ADCIN result
    ADCON2.7 = 1       ; right justify    (Change this if ADFM in diff register)
    'ANSEL = %00000000  'for 18f14k50
    'ANSELH = %00000100  'for 18f14k50
    ADCON0 = %00000001 ' turn on a/d   AN0
     
    ;--- The Main Loop ---------------------------------------------------------
    pause 2000                               'wait for connection
    ARRAYWRITE USBTXBuffer, ["USB Demo"]    'show text example
    GOSUB WaitToSend  
     
    Main:
        FOR X = 0 to 2           ; Check for incomming USB data while pausing
    @     ON_USBRX_GOSUB  _HandleRX
          PAUSE 1
        NEXT X
        ADCin 8, value2
    @Duty1=_USBRXBuffer+1 
    @Duty2=_USBRXBuffer+3 
        counter = counter +1 
        ADCIN 0, Value
        ARRAYWRITE USBTXBuffer,[portb,counter,value.highbyte,value.lowbyte,Value2.highbyte,Value2.lowbyte,0,0]
        CCP1CON.5=DUTY1.1       ' load CCP1 duty value            
        CCP1CON.4=DUTY1.0       '      with Duty1 
        CCPR1L=DUTY1>>2 
        CCP2CON.5=DUTY2.1       ' load CCP2 duty value            
        CCP2CON.4=DUTY2.0       '      with Duty1 
        CCPR2L=DUTY2>>2 
        portd = usbrxbuffer[0]
        'IF Plugged THEN GOSUB DoUSBOut     ; only send when USB is connected
        gosub SendIfReady
    GOTO Main
     
    ;---- This just sends the received packet back to the PC -------------------
    HandleRX:
        ARRAYWRITE USBTXBuffer,[STR USBRXBuffer\USBBufferSizeRX]
    return
     
    SendIfReady:
        IF Plugged AND TX_READY THEN DoUSBOut
    RETURN
     
    WaitToSend:
        WHILE Plugged and !TX_READY : WEND
        IF TX_READY THEN GOSUB DoUSBOut
    RETURN
    Edit:
    Ok, now looking at Darrel's post 221 http://www.picbasic.co.uk/forum/show...0611#post80611 , he already made the program compatible with most of the original functions for the 18F4550. So I (also) lifted his code to transfer text to the PC. However, I only do this at power up, so I don't slow the analog transfers down.
    Attached Images Attached Images  
    Attached Files Attached Files
    Last edited by ScaleRobotics; - 2nd May 2011 at 02:30. Reason: Added code in code tags
    http://www.scalerobotics.com

  5. #245
    Join Date
    Sep 2009
    Posts
    737


    Did you find this post helpful? Yes | No

    Default

    FormMain.frm is missing...

  6. #246
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by pedja089 View Post
    FormMain.frm is missing...
    Thanks pedja089, I just added it.
    http://www.scalerobotics.com

  7. #247
    Join Date
    Sep 2009
    Posts
    737


    Did you find this post helpful? Yes | No

    Default

    Excellent project!
    Not too complicated, but there are interesting examples of communication and usage of DT's include files.
    Perhaps you should add the LCD.
    Here is my example how to sendtext from winamp to lcd:
    http://www.elektronika.ba/506/lcd-winamp-plugin-on-usb/
    I hope that you will manage the translation...

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

    5 years later and this thread always evolve and got some more user in the "USB freaks" loops. Glad to see that. Congrats to all!

    Now I wish I have time to revamp it and share some part of what i've done for .NET (C# & VB) ...VB6 being a dead duck for ages now... and the .dll not that suitable now (but still workable) and then on the top of it, new PBP version

    Helm PCB (Amr Bekhit) did a good work on my first .NET version though http://helmpcb.com/?p=166
    Steve

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

  9. #249
    Join Date
    Feb 2004
    Location
    Michigan, USA
    Posts
    305


    Did you find this post helpful? Yes | No

    Default Re: USBDemo, something to learn USB a little bit

    Reading through this it looks like there was a sample of code were the 18F2550 was using an external resonator at 20mhz using the HS fuse. Looking at the datasheet, this would only enable low speed USB, right?

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


    Did you find this post helpful? Yes | No

    Default Re: USBDemo, something to learn USB a little bit

    With those chips ... you can get Full Speed with any crystal that's a multiple of 4Mhz (up to 24Mhz).
    And the processor can run at 48Mhz too.

    They have a really nice Oscillator/PLL.
    Adjusting the Configuration bits is a little tricky though.
    DT

  11. #251
    Join Date
    Dec 2010
    Location
    Tokyo
    Posts
    3


    Did you find this post helpful? Yes | No

    Default Re: USBDemo, something to learn USB a little bit

    Hello

    I use a PIC18F2550 for CDC serial port emulation based on cdc_demo.bas:

    USBInit

    For input and output I use:
    inloop:
    icnt = inbuff
    USBService
    USBIn 3, inbuffer, icnt, inloop

    outloop:
    USBService
    ocnt = outbuff
    USBOut 3, outbuffer, ocnt, outloop

    and it works really fine.


    At start PIC tests 5V from PC-USB-Port to wait with 'USBInit'. Sometimes PC is rebooting w/o switch off, but equipmend with the PIC interface still running. Is it possible to let the PIC routine know that Windows VSP is gone and the 'USBInit' has to be done again?

    Thanks to everybody who can help

  12. #252
    Join Date
    Jun 2005
    Location
    Penang
    Posts
    40


    Did you find this post helpful? Yes | No

    Default Re: USBDemo, something to learn USB a little bit

    Hello All,

    I'm new in USB.Althought i have tried all the steps necessary steps in order to compile the USB CDC source,i'm not succeeding in doing so.The errors are this :

    Name:  Captureerr.JPG
Views: 6319
Size:  41.0 KB

    What could be the problem?

    Waiting for help

    Regards.

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


    Did you find this post helpful? Yes | No

    Default Re: USBDemo, something to learn USB a little bit

    Quote Originally Posted by NatureTech View Post
    What could be the problem?
    It could be that you are using PBP version 2.46 - 2.50C with MPLAB greater than 8.15a

    Either upgrade PBP, or downgrade MPLAB.

    If you have upgraded PBP, use the new USB files from the USB18 folder.
    DT

  14. #254
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,585


    Did you find this post helpful? Yes | No

    Default Re: USBDemo, something to learn USB a little bit

    I'm able to use Steve's demo along with Darrel's include, but it only works when the MeLabs U2 USB programmer is connected. If I unplug the programmer, the 18F4550 is no longer recognized:

    Code:
    '***************************************************************************
    '*  Name    : USBLabX1_RH.pbp                                              *
    '*  Author  : Steve Monfette/Darrel Taylor/Demon                    *
    '*  Date    : Jan 11 2012                                                  *
    '*  Version : 3.0                                                          *
    '*  Notes   : This is a re-creation of mister-e's USBdemo for DT_HID       *
    '*          : Meant to work with mister-e's GUI                            *
    '*          : Modified for Lab X1                                          *
    '*  Hardware : PIC 18F4550, 20mhz crystal                                  *
    '*           : Lab X1 Experimental Board, 9.5V wall adapter                *
    '*           : MeLabs U2 Programmer v4.32                                  *
    '*  Software : PIC Basic Pro v2.60C                                        *
    '*           : MicroCode Studio Plus v2.2.1.1                              *
    '*           : MPASM WIN Assembler v4.02 (mplab tools/MPASM Suite)         *
    '*  PIC mods : plastic USB connector hot-glued onto top of PIC             *
    '*           : D- wired to C4 (pin 23) directly to top of pins             *
    '*           : D+ wired to C5 (pin 24) directly to top of pins             *
    '*           : two 0.1uF ceramic caps in parallel across VUSB and VSS      *
    '***************************************************************************
    '--- if you use these, you must comment the ones in the .inc file ---
    @   __CONFIG    _CONFIG1L, _PLLDIV_5_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
    @   __CONFIG    _CONFIG1H, _FOSC_HSPLL_HS_1H
    @   __CONFIG    _CONFIG2L, _PWRT_OFF_2L & _BOR_ON_2L & _BORV_46_2L & _VREGEN_ON_2L
    @   __CONFIG    _CONFIG2H, _WDT_OFF_2H
    @   __CONFIG    _CONFIG3H, _CCP2MX_ON_3H & _PBADEN_OFF_3H & _LPT1OSC_OFF_3H & _MCLRE_ON_3H
    @   __CONFIG    _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L & _ICPRT_OFF_4L & _XINST_OFF_4L
    
    DEFINE OSC 48
    
    DEFINE  LCD_DREG      PORTD         ' Set LCD data port
    DEFINE  LCD_DBIT      4             ' Set starting data bit
    DEFINE  LCD_RSREG     PORTE         ' Set LCD register select port
    DEFINE  LCD_RSBIT     0             ' Set LCD register select bit
    DEFINE  LCD_EREG      PORTE         ' Set LCD enable port
    DEFINE  LCD_EBIT      1             ' Set LCD enable bit
    DEFINE  LCD_BITS      4             ' Set LCD bus size
    DEFINE  LCD_LINES     2             ' Set number of lines on LCD
    DEFINE  LCD_COMMANDUS 2000          ' Set command delay time in microseconds
    DEFINE  LCD_DATAUS    50            ' Set data delay time in microseconds
    
    ;--- Setup Interrupts ------------------------------------------------------
    INCLUDE "DT_INTS-18.bas"        ; Base Interrupt System
    INCLUDE "ReEnterPBP-18.bas"     ; PBP Re-entry for external interrupt
    
    ASM
    INT_LIST  macro    ; IntSource,     Label,   Type, ResetFlag?
            INT_Handler   USB_Handler
            INT_Handler   INT_INT,   _ToggleLED1, PBP,    yes
        endm
        INT_CREATE               ; Creates the interrupt processor
    endasm
    
    @   INT_ENABLE   INT_INT        ; enable external (INT) interrupts
    
    ;--- Setup USB -------------------------------------------------------------
    INCLUDE "DT_HID260.pbp"
    
    DEFINE USB_VENDORID    6017
    DEFINE USB_PRODUCTID   2000
    DEFINE USB_VERSION     1
    DEFINE USB_VENDORNAME  "Mr E/DT/RH"
    DEFINE USB_PRODUCTNAME "USBLabX1"
    DEFINE USB_SERIAL      "001"
    DEFINE USB_INSIZE      8    ;  IN report is PIC to PC (8,16,32,64)
    DEFINE USB_OUTSIZE     8    ; OUT report is PC to PIC
    DEFINE USB_POLLIN      10   ; Polling times in mS, MIN=1 MAX=10
    DEFINE USB_POLLOUT     10
    
    ; --- Each USB status LED is optional, comment them if not used ------------
    ; --- They can be assigned to any pin, and no further action is required --- 
    DEFINE USB_LEDPOLARITY 1       ; LED ON State [0 or 1]  (default = 1)
    DEFINE USB_PLUGGEDLED  PORTD,0 ; LED indicates if USB is connected
    DEFINE USB_TXLED       PORTD,1 ;  "      "     data being sent to PC
    DEFINE USB_RXLED       PORTD,2 ;  "      "     data being received from PC
    
    ;--- Setup ADC -------------------------------------------------------------
    DEFINE ADC_BITS 8  ; Number of bits in ADCIN result
    
        TRISA = %00000011               ' Set port A pins to 6 output, 2 input
        TRISB = %00001111               ' Set port B pins to 4 output, 4 input
                                        ' B0 = External Interrupt
        TRISC = %00000000               ' Set all port C pins to output
        TRISD = %00000000               ' Set all port D pins to output
        TRISE = %00000000               ' Set all port E pins to output
    
    ;--- Variables -------------------------------------------------------------
    Value0      VAR  WORD : Value0 = 0
    Value1      VAR  WORD : Value1 = 0
    DUTY1       VAR  WORD
    DUTY2       VAR  WORD
    LED1        VAR PORTD.3
    WS_CHAR     VAR BYTE
    WS_BYTE     VAR BYTE
    WS_LOOPW    VAR WORD
    ;--- Initialize ------------------------------------------------------------
        ADCON2.7 = 0       ; left justify    (Change this if ADFM in diff register)
        ADCON1 = %00001101     ; AN0 & AN1 analog
        INTCON2 = %00000000    ; Pull-up resistors, falling edge
    
        PORTB = %00000000      ; Set output on keypad to prevent floating pins
    
    
        PAUSE   2000                     ' Wait for USB to initalize
        LCDOUT  $FE,1,"LabX1 18F4550 USB"
        PORTD = 0                       ' Clear LEDs from LCD operations
        ARRAYWRITE USBTXBuffer, ["Lab X1  "]
        IF Plugged THEN GOSUB DoUSBOut     ; only send when USB is connected
        
    ;--- The Main Loop ---------------------------------------------------------
    Main:
        FOR WS_LOOPW = 0 to 1000           ; Check for incomming USB data while waiting
    @       ON_USBRX_GOSUB  _HandleRX
            PAUSE 1
        NEXT WS_LOOPW
        
        ADCIN 0, Value0            ; Send A/D about once/sec
        ADCIN 1, Value1
        ARRAYWRITE USBTXBuffer, [Value0, Value1, PORTD.3, 0, 0, 0, 0, 0]
        IF Plugged THEN GOSUB DoUSBOut     ; only send when USB is connected
    
        GOTO Main
    end
    
    ;---- Receive incoming data PORTB LEDS and CCP PWM dutycycle ---------------
    HandleRX:
        ARRAYREAD  USBRXBuffer,[WS_BYTE, DUTY1.LowByte, DUTY1.HighByte, _
                                        DUTY2.LowByte, DUTY2.HighByte]
        LCDOUT  $FE,$C0,BIN WS_BYTE
        PORTD = 0                       ' Clear LEDs from LCD operations
    return
    
    '---[INT - interrupt handler]---------------------------------------------------
    ToggleLED1:
        TOGGLE LED1
        ARRAYWRITE USBTXBuffer, ["Button  "]
        IF Plugged THEN GOSUB DoUSBOut     ; only send when USB is connected
        PORTB = 0               ' Set output on keypad to prevent floating pins
    @ INT_RETURN
    On the Lab X1:
    - PWM logic is not active.
    - buttons 1, 2, 3 and 4 on the keypad activate Port A2 LED.
    - AN 0 and 1 work as expected.

    On the PC:
    - Port B is displayed on the LCD.

    Any idea why Windows XP Home would need the USB programmer connected in order to recognize the PIC?

    Everything works fine if I reconnect the programmer.

    Robert
    Last edited by Demon; - 4th October 2016 at 18:13.

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


    Did you find this post helpful? Yes | No

    Default Re: USBDemo, something to learn USB a little bit

    Robert,

    Check the ground from your USB connector.

    Plugging in the programmer will give a common ground with the computer.
    If there is no ground from your USB connector, it will disconnect when you unplug the U2.
    DT

  16. #256
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,585


    Did you find this post helpful? Yes | No

    Default Re: USBDemo, something to learn USB a little bit

    Yup, that fixed that problem.

    But if I leave the programmer connected, it garbles a few characters on the LCD?

    Cleaned up code (replaced PAUSE for LOOP):

    Code:
    '***************************************************************************
    '*  Name    : USBLabX1_RH.pbp                                              *
    '*  Author  : Steve Monfette/Darrel Taylor/Demon                    *
    '*  Date    : Jan 11 2012                                                  *
    '*  Version : 3.0                                                          *
    '*  Notes   : This is a re-creation of mister-e's USBdemo for DT_HID       *
    '*          : Meant to work with mister-e's GUI                            *
    '*          : Modified for Lab X1                                          *
    '*  Hardware : PIC 18F4550, 20mhz crystal                                  *
    '*           : Lab X1 Experimental Board, 9.5V wall adapter                *
    '*           : MeLabs U2 Programmer v4.32                                  *
    '*  Software : PIC Basic Pro v2.60C                                        *
    '*           : MicroCode Studio Plus v2.2.1.1                              *
    '*           : MPASM WIN Assembler v4.02 (mplab tools/MPASM Suite)         *
    '*  PIC mods : plastic USB connector hot-glued onto top of PIC             *
    '*           : D- wired to C4 (pin 23) directly to top of pins             *
    '*           : D+ wired to C5 (pin 24) directly to top of pins             *
    '*           : two 0.1uF ceramic caps in parallel across VUSB and VSS      *
    '***************************************************************************
    '--- if you use these, you must comment the ones in the .inc file ---
    @   __CONFIG    _CONFIG1L, _PLLDIV_5_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
    @   __CONFIG    _CONFIG1H, _FOSC_HSPLL_HS_1H
    @   __CONFIG    _CONFIG2L, _PWRT_ON_2L & _BOR_OFF_2L & _VREGEN_ON_2L
    @   __CONFIG    _CONFIG2H, _WDT_OFF_2H
    @   __CONFIG    _CONFIG3H, _CCP2MX_OFF_3H & _PBADEN_OFF_3H & _LPT1OSC_OFF_3H & _MCLRE_ON_3H
    @   __CONFIG    _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L & _ICPRT_OFF_4L & _XINST_OFF_4L
    
    DEFINE OSC 48
    CLEAR 
    
    DEFINE  LCD_DREG      PORTD         ' Set LCD data port
    DEFINE  LCD_DBIT      4             ' Set starting data bit
    DEFINE  LCD_RSREG     PORTE         ' Set LCD register select port
    DEFINE  LCD_RSBIT     0             ' Set LCD register select bit
    DEFINE  LCD_EREG      PORTE         ' Set LCD enable port
    DEFINE  LCD_EBIT      1             ' Set LCD enable bit
    DEFINE  LCD_BITS      4             ' Set LCD bus size
    DEFINE  LCD_LINES     2             ' Set number of lines on LCD
    DEFINE  LCD_COMMANDUS 2000          ' Set command delay time in microseconds
    DEFINE  LCD_DATAUS    50            ' Set data delay time in microseconds
    
    ;--- Setup Interrupts ------------------------------------------------------
    INCLUDE "DT_INTS-18.bas"        ; Base Interrupt System
    INCLUDE "ReEnterPBP-18.bas"     ; PBP Re-entry for external interrupt
    
    ASM
    INT_LIST  macro    ; IntSource,     Label,   Type, ResetFlag?
            INT_Handler   USB_Handler
            INT_Handler   INT_INT,   _ToggleLED1, PBP,    yes
        endm
        INT_CREATE               ; Creates the interrupt processor
    endasm
    
    @   INT_ENABLE   INT_INT        ; enable external (INT) interrupts
    
    ;--- Setup USB -------------------------------------------------------------
    INCLUDE "DT_HID260.pbp"
    
    DEFINE USB_VENDORID    6017
    DEFINE USB_PRODUCTID   2000
    DEFINE USB_VERSION     1
    DEFINE USB_VENDORNAME  "Mr E/DT/RH"
    DEFINE USB_PRODUCTNAME "USBLabX1"
    DEFINE USB_SERIAL      "001"
    DEFINE USB_INSIZE      8    ;  IN report is PIC to PC (8,16,32,64)
    DEFINE USB_OUTSIZE     8    ; OUT report is PC to PIC
    DEFINE USB_POLLIN      10   ; Polling times in mS, MIN=1 MAX=10
    DEFINE USB_POLLOUT     10
    
    ; --- Each USB status LED is optional, comment them if not used ------------
    ; --- They can be assigned to any pin, and no further action is required --- 
    DEFINE USB_LEDPOLARITY 1       ; LED ON State [0 or 1]  (default = 1)
    DEFINE USB_PLUGGEDLED  PORTD,0 ; LED indicates if USB is connected
    DEFINE USB_TXLED       PORTD,1 ;  "      "     data being sent to PC
    DEFINE USB_RXLED       PORTD,2 ;  "      "     data being received from PC
    
    ;--- Setup ADC -------------------------------------------------------------
    DEFINE ADC_BITS 8  ; Number of bits in ADCIN result
    
        TRISA = %00000011               ' Set port A pins to 6 output, 2 input
        TRISB = %00001111               ' Set port B pins to 4 output, 4 input
                                        ' B0 = External Interrupt
        TRISC = %00000000               ' Set all port C pins to output
        TRISD = %00000000               ' Set all port D pins to output
        TRISE = %00000000               ' Set all port E pins to output
    
    ;--- Variables -------------------------------------------------------------
    Value0      VAR  WORD : Value0 = 0
    Value1      VAR  WORD : Value1 = 0
    DUTY1       VAR  WORD
    DUTY2       VAR  WORD
    LED1        VAR PORTD.3
    WS_CHAR     VAR BYTE
    WS_BYTE     VAR BYTE
    WS_LOOPW    VAR WORD
    ;--- Initialize ------------------------------------------------------------
        ADCON2.7 = 0       ; left justify    (Change this if ADFM in diff register)
        ADCON1 = %00001101     ; AN0 & AN1 analog
        INTCON2 = %00000000    ; Pull-up resistors, falling edge
    
        PORTB = %00000000      ; Set output on keypad to prevent floating pins
    
        LCDOUT  $FE,1                   ' Initiate first command to LCD
        PORTD = 0                       ' Clear LEDs from LCD operations
    
        FOR WS_LOOPW = 0 to 1000        ' Wait for LCD to initalize
            PAUSE 1
        NEXT WS_LOOPW
        LCDOUT  $FE,1,"LabX1 18F4550 USB"
        PORTD = 0                       ' Clear LEDs from LCD operations
    
        FOR WS_LOOPW = 0 to 1000        ' Wait for USB to initalize
            PAUSE 1
        NEXT WS_LOOPW
        ARRAYWRITE USBTXBuffer, ["Lab X1  "]
        IF Plugged THEN GOSUB DoUSBOut     ; only send when USB is connected
        
    ;--- The Main Loop ---------------------------------------------------------
    Main:
        FOR WS_LOOPW = 0 to 1000           ; Check for incomming USB data while waiting
    @       ON_USBRX_GOSUB  _HandleRX
            PAUSE 1
        NEXT WS_LOOPW
        
        ADCIN 0, Value0            ; Send A/D about once/sec
        ADCIN 1, Value1
        ARRAYWRITE USBTXBuffer, [Value0, Value1, PORTD.3, 0, 0, 0, 0, 0]
        IF Plugged THEN GOSUB DoUSBOut     ; only send when USB is connected
    
        GOTO Main
    end
    
    ;---- Receive incoming data PORTB LEDS and CCP PWM dutycycle ---------------
    HandleRX:
        ARRAYREAD  USBRXBuffer,[WS_BYTE, DUTY1.LowByte, DUTY1.HighByte, _
                                        DUTY2.LowByte, DUTY2.HighByte]
        LCDOUT  $FE,$C0,BIN WS_BYTE
        PORTD = 0                       ' Clear LEDs from LCD operations
    return
    
    '---[INT - interrupt handler]---------------------------------------------------
    ToggleLED1:
        TOGGLE LED1
        ARRAYWRITE USBTXBuffer, ["Button  "]
        IF Plugged THEN GOSUB DoUSBOut     ; only send when USB is connected
        PORTB = 0               ' Set output on keypad to prevent floating pins
    @ INT_RETURN
    Sharing the USB NEG only seems to affect the LCD. If I unplug the programmer, Port B updates properly on the LCD, everything runs fine.

    Uh oh, just realized I might have misunderstood. There's also a GROUND eyelet coming from the USB cable, is that the ground you were referring to? If so, would that go to VSS instead of the NEG?
    Last edited by Demon; - 4th October 2016 at 18:13.

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


    Did you find this post helpful? Yes | No

    Default Re: USBDemo, something to learn USB a little bit

    Pin 4 of the USB connector is Ground.
    It and the Shield should be connected to VSS on the LAB-X1.

    Have you removed the MAX232 chip?
    You've set the RX pin to output, which is likely to cause high currents if the MAX232 is still there.
    DT

  18. #258
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,585


    Did you find this post helpful? Yes | No

    Default Re: USBDemo, something to learn USB a little bit

    Quote Originally Posted by Darrel Taylor View Post
    Pin 4 of the USB connector is Ground.
    It and the Shield should be connected to VSS on the LAB-X1.
    ...
    Tried both USB pin 4 (black wire) and the eyelet from the shielding connected to VSS, same garbles on LCD.

    I used one of the VSS pins on the PIC, does it have to be a special VSS contact on the Lab X1?


    Quote Originally Posted by Darrel Taylor View Post
    ...
    Have you removed the MAX232 chip?
    You've set the RX pin to output, which is likely to cause high currents if the MAX232 is still there.
    I didn't remove the MAX232, but I installed headers on my Lab X1. The jumpers for RX and TX pins are disabled, same with VUSB pin.


    EDIT: I didn't have the recommended capacitors so I used two 0.1uF ceramic caps in parallel across VUSB and VSS. Could that be a problem?
    Last edited by Demon; - 21st January 2012 at 05:45.

  19. #259
    Join Date
    Dec 2010
    Posts
    409


    Did you find this post helpful? Yes | No

    Default Re: USBDemo, something to learn USB a little bit

    I'm just getting started with USB. I've gone through the CDC demo and created my own variants with success (after a bit of teething pain) and now I'm trying to move on to HID. I've found the DT_HID260.zip file and I've been playing with the contents, but I'm not having any luck getting DT_HID260.pbp, DT_INTS-18.bas, ReEnterPBP-18.bas and my code to work together. I'm so close.... I think, but right now I can't even compile.

    I've got 2 errors that have me completely stumped:
    Illegal opcode (USB_INT)
    Address label duplicated or different in second pass (INT_RETURN)

    Any clues where to look? Many thanks...

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


    Did you find this post helpful? Yes | No

    Default Re: USBDemo, something to learn USB a little bit

    It sounds like you would also be getting an error that says it can't open include file DT_INTS-18.bas.

    Did you put it in your PBP folder?
    DT

  21. #261
    Join Date
    Dec 2010
    Posts
    409


    Did you find this post helpful? Yes | No

    Default Re: USBDemo, something to learn USB a little bit

    Actually I just resolved it. It seems the line to include DT_HID260.pbp must come AFTER the INT_CREATE. I moved the include from the top of the file to this location and the errors went away.

    Compiles no errors means it will work fine right? Well not exactly, but I'll chew on "why" by myself for a bit.

    Thanks for the help!

  22. #262
    Join Date
    Dec 2010
    Posts
    409


    Did you find this post helpful? Yes | No

    Default Re: USBDemo, something to learn USB a little bit

    Well I though I'd leverage Darrel's heavy lifting and put the USB code (including the interrupt structure) together with the SD card code and make myself basically an overly complicated and expensive thumb drive, purely for my education. It seems, however, that the includes consume more than the 2K space for variables, and after about an hour of trying to make things less generic by eliminating variables wherever possible in favor of fixed values, I still don't have enough space. I'm also not sure if I'm even getting close - is there any way to have the compiler tell you how much you are over by, rather than simply "unable to fit"?

  23. #263
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,585


    Did you find this post helpful? Yes | No

    Default Re: USBDemo, something to learn USB a little bit

    Charlie,

    I had a similar problem once; so I copied the Includes in the code and removed all the variables I didn't need. That worked in my particular situation.

    Robert

  24. #264
    Join Date
    Nov 2006
    Location
    Ventura, CA
    Posts
    5


    Did you find this post helpful? Yes | No

    Default Re: USBDemo, something to learn USB a little bit

    I'm just getting my feet wet with USB. I currently have PBP (2.60C). I'd like to get some recommendations, before I get too far into this project:

    1) Is there any benefit to upgrading to PBP 3.0, specifically for my USB experiments?
    2) I have very little experience with VB6, but some experience with VBA (in Excel). Back on post 248, Steve said, "...VB6 being a dead duck for ages now...". I _have_ VB6, but was wondering if there was a more current alternative (other than going out and trying to learn a completely new language, like C)

    Any tips would be greately appreciated!

    Jeff

  25. #265
    Join Date
    Aug 2008
    Location
    Portugal
    Posts
    240


    Did you find this post helpful? Yes | No

    Default Re: USBDemo, something to learn USB a little bit

    [QUOTE=JBKerner;112633Steve said, "...VB6 being a dead duck for ages now...". I _have_ VB6, but was wondering if there was a more current alternative (other than going out and trying to learn a completely new language, like C)
    [/QUOTE]

    VB.NET;

    http://www.picbasic.co.uk/forum/cont...-USB-to-VB.NET
    Thanks and Regards;
    Gadelhas

  26. #266
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,585


    Did you find this post helpful? Yes | No

    Default Re: USBDemo, something to learn USB a little bit

    Jeff, read this thread:
    http://www.picbasic.co.uk/forum/showthread.php?t=16234

    It's exactly about this topic.

    Robert

  27. #267
    Join Date
    Dec 2011
    Posts
    4


    Did you find this post helpful? Yes | No

    Unhappy Re: USBDemo, something to learn USB a little bit

    hi,

    i use USBDemo.HEX file. i send it to my PIC using USB PIC programmer (not boot loader). i use;

    18f4550
    4 MHZ crystal (with 22pF capacitors)
    3 parallel 100nF (not polarized) capacitors on pin18
    10k resistor on mclr
    100nF capacitor between VCC and GND

    my pc doesn't recognise the device. nothing happens when i connect PIC to my pc

    what is wrong. i couldn't work it. i am workin on it for months and i am going crazy.

    thanks

  28. #268
    Join Date
    Jun 2008
    Posts
    3


    Did you find this post helpful? Yes | No

    Default Re: USBDemo, something to learn USB a little bit

    ...well looking back it appears you can use a 4mhz. I used a 20mhz crystal when I was able to get it working.

    Do you have a schematic.
    Last edited by UnaKRon; - 19th November 2012 at 15:53.

  29. #269
    Join Date
    Dec 2011
    Posts
    4


    Did you find this post helpful? Yes | No

    Default Re: USBDemo, something to learn USB a little bit

    Name:  4550.jpg
Views: 5346
Size:  173.6 KB

    this is my scheme. i tried it using 20MHZ and 15pF caps. what is wrong with it?

  30. #270
    Join Date
    Jun 2008
    Posts
    3


    Did you find this post helpful? Yes | No

    Default Re: USBDemo, something to learn USB a little bit

    First thing I do when I'm having trouble is either hook up some Status LEDs or a Serial output to debug the pic. I've had trouble with a program or two..and more than once something was causing a reset. Do you have a compiler so you can add in some debugging code?

    I believe i did 22pf with my 20mhz...which is more than required by the datasheet. :/ I'm not seeing anything right off :/
    Have you verified the usb cable is providing power and works with another device?

  31. #271
    Join Date
    Dec 2011
    Posts
    4


    Did you find this post helpful? Yes | No

    Default Re: USBDemo, something to learn USB a little bit

    i use pic programmer's usb cable. cable works. can anyone send me a simple pcb layout of a working usb project and hex file. i want to improve myself about pic and usb but i couldn't get result for weeks. thanks

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


    Did you find this post helpful? Yes | No

    Default Re: USBDemo, something to learn USB a little bit

    How do you dump the .hex file into your PIC, i mean how do you program your PIC?

    Are you sure your device programmer software program the configuration fuses properly?

    Those .HEX files providen here are there since 6 years or so, they're working.
    Steve

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

  33. #273
    Join Date
    Dec 2005
    Posts
    1,073


    Did you find this post helpful? Yes | No

    Default Re: USBDemo, something to learn USB a little bit


  34. #274
    Join Date
    Dec 2003
    Location
    Wichita KS
    Posts
    511


    Did you find this post helpful? Yes | No

    Default Re: USBDemo, something to learn USB a little bit

    Hello Steve and Darrel,

    You mangy old farts, how are you all doing? Looks like all as been well for both of you. Its been a while since we have chatted.

    PIC's working ok? Haven't done any programming for a number of years on those chips. I probably should get back into them.

    Dwayne
    Ability to Fly:
    Hurling yourself towards the ground, and missing.

    Engineers that Contribute to flying:
    Both optimists and pessimists contribute to the society. The optimist invents the aeroplane, the pessimist the parachute

    Pilots that are Flying:
    Those who know their limitations, and respect the green side of the grass...

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


    Did you find this post helpful? Yes | No

    Default Re: USBDemo, something to learn USB a little bit

    So cool to see you back here Dwayne

    As long as I wake up, it's a good day
    Steve

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

  36. #276
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,516


    Did you find this post helpful? Yes | No

    Default Re: USBDemo, something to learn USB a little bit

    Dave,
    That board is based on a PIC24 device. PBP support the 10, 12, 16 and 18 series of PICs - so the answer is no.
    Rumour has it that there's a PBP compiler for PIC24 under development though so perhaps some time in the future.

    /Henrik.

  37. #277
    Join Date
    Dec 2005
    Posts
    1,073


    Did you find this post helpful? Yes | No

    Default Re: USBDemo, something to learn USB a little bit

    Quote Originally Posted by HenrikOlsson View Post
    That board is based on a PIC24 device. PBP support the 10, 12, 16 and 18 series of PICs - so the answer is no.
    Thanks, Henrik.

  38. #278
    Join Date
    Dec 2011
    Posts
    4


    Did you find this post helpful? Yes | No

    Default Re: USBDemo, something to learn USB a little bit

    DataToSend's array size is 8. i want to make it 16. i mean i want to send 16 variable at the same time. not 8. can anybody help me?

  39. #279
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,585


    Did you find this post helpful? Yes | No

    Default Re: USBDemo, something to learn USB a little bit

    Quote Originally Posted by Darrel Taylor View Post
    ...
    Also note: This is for PBP 2.60 only ...
    Someone found a workaround for PBP 3:

    http://www.picbasic.co.uk/forum/show...599#post126599

    Robert

Closed Thread
Page 7 of 7 FirstFirst ... 34567

Similar Threads

  1. Bits, Bytes Words and Arrays
    By Melanie in forum FAQ - Frequently Asked Questions
    Replies: 24
    Last Post: - 14th June 2016, 08:55
  2. How to receive stream of bytes using PIC USART
    By unifoxz in forum mel PIC BASIC Pro
    Replies: 34
    Last Post: - 20th June 2009, 11:38
  3. Replies: 9
    Last Post: - 31st July 2008, 09:56
  4. PICBasic newbie problem
    By ELCouz in forum mel PIC BASIC Pro
    Replies: 32
    Last Post: - 12th February 2008, 01:55
  5. USART interrupt not interrupting right
    By Morpheus in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 6th March 2005, 02:07

Members who have read this thread : 4

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