OK, this program should work with Steve's original USBDemo GUI.
18F2550/4550, 8Mhz, DT_INTS-18, DT_HID260.
Cheers,
OK, this program should work with Steve's original USBDemo GUI.
18F2550/4550, 8Mhz, DT_INTS-18, DT_HID260.
Cheers,
DT
Darrel,
Everything compiles/assembles/programs in my EasyPic6 configuration with 18F4550 (8 MHz crystal), and it does run with Steve's VB6 GUI, but only for data from the PIC....data to PIC side of the GUI doesn't work. I double checked that I didn't have anytheng on the EasyPic6 connected to the pins you are using. See attached screen snapshot of the VB6 GUI that shows what is working and what isn't.
I also notice that when I remove the comments on the DEFINE statements for the status LEDs that they do not light during the PLUGGED, TX or RX actions are supposedly taking place that they are suppose to indicate.
I looked at your code and I couldn't see where the problem is. Any ideas??
Last edited by jellis00; - 10th November 2009 at 19:24. Reason: Added comments re: status LEDs
The ones on the left require 8-LEDs on PORTB, and 2 other LEDs on the CCP outputs, RC1/RC2.
Previously you said you disconnected the LED's to get things working with the EasyPIC.
The USB D-/D+ are on RC4/RC5, so I don't think you can just enable the whole bank of LED's on PORTC. You'll need to attach LEDs to only the 2 CCP Pins to get the faders working. But you should be ok with LEDs on PORTB.
HTH,
DT
Turns out you can enable all the whole bank of LED's on PORTC and it keeps working. You can then see the LEDs on RC1 and RC2 vary in brightness as you change the sliders.The USB D-/D+ are on RC4/RC5, so I don't think you can just enable the whole bank of LED's on PORTC. You'll need to attach LEDs to only the 2 CCP Pins to get the faders working.
Except for the LEDs on RB0, RB5, Rb6 & RB7 (which are used in your code) you can now click the check boxes on B1 thru B4 on the VB6 Gui and they work to light the corresponding LEDs.But you should be ok with LEDs on PORTB.
I now have Steve's VB6 GUI and the DT_HID monitor running side by side and everything works as advertised except for the exceptions I listed above for the B0 thru B7 check boxes. Your support to me in getting to this has been outstanding, Darrel. Thanks so much!
Now I only have to figure out how to capture the data coming across the USB interface from the PIC into a spreadsheet. Your suggestion to use CDC and HYPERTERM would be an easier option except that my application requires a USB interface that is also used to connect to a cell phone, and I don't have physical room for both an RS232 and a USB interface within the physical board size contstraint or panel connector space. Looks like I have to figure out how to do the capture in Steve's USB VB6 GUI. I will modify the PIC side to send comman delimited data per your suggestion, but don't know how to approach capturing the comma delimited data from the VB6 USB Gui that is showing into a spreadsheet. Can you refer me to any forum ideas or reference tutorials in this area??
Thanks again, Darrell. Your contributions & presence on this forum is what makes it worthwhile.
Last edited by jellis00; - 11th November 2009 at 00:19.
PORTB.0 is not used anywhere in the program (other than output from the Demo).
PORTB.5-7 are only used if the USB Status LED lines are uncommented (I left them commented). And they can be assigned to any pin, they don't have to be PORTB.5-7
CDC is USB, there's no RS232 connector.
In excel, use the Data | Import External Data | Import Data menu item to just plop your CSV file right into your spreadsheet. Then when the data changes, use Data | Refresh Data to update everything automatically.
<br>
DT
Sorry to be such a pest, Darrell, but am now trying to adapt your USBdemo_DTID so that it will go into USB connection mode as an interrupt when the USB cable is connected, permitting me in the Interrupt Service Routine to execute some code that is only intended to be executed when the USB cable is connected.
I thought I could make the simple changes to your code as shown in my attachment below, where I just used a USB_INT with the DT_INTS-18 include file to perform the interrupt to my label "USBhandler".
This compiles and assembles OK and starts on power up, but when the USB cable is connected I get a WINDOWS error saying "USB Device Not Recognized". Am I missing something here on how to make this work as a USB connection interrupt??
Code:'************************************************************************** '* Name : USBdemo_DTHID2.pbp * '* Author : Modification of Steve Monfette/Darrel Taylor * '* Date : 11/9/2009 * '* Version : 2.0 * '* Notes : This is a re-creation of mister-e's USBdemo for DT_HID * '* : Meant to work with mister-e's GUI but with a USB interrupt * '* : service routine where some specific code will be executed * '* : only during USB connection. * '************************************************************************** ;-- if you un-comment these, you must comment the ones in the .inc file -- ASM ; 18F2550/4550, 8mhz crystal __CONFIG _CONFIG1L, _PLLDIV_2_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_ON_2H & _WDTPS_512_2H __CONFIG _CONFIG3H, _PBADEN_OFF_3H __CONFIG _CONFIG4L, _LVP_OFF_4L & _XINST_OFF_4L ENDASM DEFINE OSC 48 CLEAR ;--- Setup Interrupts ------------------------------------------------------ INCLUDE "DT_INTS-18.bas" ; Base Interrupt System INCLUDE "ReEnterPBP-18.bas" ' Include if using PBP high priority interrupts ASM INT_LIST macro ; IntSource, Label, Type, ResetFlag? INT_Handler USB_INT, _USBhandler, PBP, yes endm INT_CREATE ; Creates the interrupt processor endasm @ INT_ENABLE USB_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 "Mister E/DT" DEFINE USB_PRODUCTNAME "USBDemo" 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 PORTB,7 ; LED indicates if USB is connected ;DEFINE USB_TXLED PORTB,6 ; " " data being sent to PC ;DEFINE USB_RXLED PORTB,5 ; " " data being received from PC ;--- Variables ------------------------------------------------------------- Value0 VAR WORD Value1 VAR WORD X VAR WORD DUTY1 VAR WORD DUTY2 VAR WORD Old_PORTA VAR BYTE New_PORTA VAR BYTE ;--- Setup ADC ------------------------------------------------------------- DEFINE ADC_BITS 8 ; Number of bits in ADCIN result ;--- Initialize ------------------------------------------------------------ CCPR1L = 0 CCPR2L = 0 CCP1CON = %00001100 ' CCP1, PWM mode CCP2CON = %00001100 ' CCP2, PWM mode PR2 = 249 ' 0-1000 duty range T2CON = %00000101 ' TMR2 on, prescaler 1:4 TRISB = 0 OUTPUT PORTC.1 OUTPUT PORTC.2 ADCON2.7 = 0 ; left justify (Change this if ADFM in diff register) ADCON1 = %1101 ; AN0/AN1 Analog ;--- The Main Loop --------------------------------------------------------- Main: 'Normally in sleep mode waiting for interrupts Toggle PORTE.2 ' Test LED flashing during Main loop GOTO Main '----------------Interrupt Service Routines Start Here-------------------- USBhandler: FOR X = 0 to 1000 ; Check for incomming USB data while waiting @ ON_USBRX_GOSUB _HandleRX PAUSE 1 New_PORTA = PORTA ; Check PORTA pins IF New_PORTA != Old_PORTA THEN Old_PORTA = New_PORTA ARRAYWRITE USBTXBuffer, ["USB Demo"] GOSUB WaitToSend ARRAYWRITE USBTXBuffer, [Value0, Value1, PORTA.2, _ PORTA.3, PORTA.4, PORTA.5,0,0] GOSUB WaitToSend ENDIF NEXT X ADCIN 0, Value0 ; Send A/D about once/sec ADCIN 1, Value1 ARRAYWRITE USBTXBuffer, [Value0, Value1, PORTA.2, _ PORTA.3, PORTA.4, PORTA.5,0,0] GOSUB SendIfReady 'Code to be processed only during USB connection. TOGGLE PortE.3 ' Test LED that USB interrupt occured @ INT_RETURN ;--- Send Data if Plugged and ready, otherwise discard -------------------- SendIfReady: IF Plugged AND TX_READY THEN DoUSBOut RETURN ;--- Wait till Ready to send of until unplugged --------------------------- WaitToSend: WHILE Plugged and !TX_READY : WEND IF TX_READY THEN GOSUB DoUSBOut RETURN ;---- Receive incoming data PORTB LEDS and CCP PWM dutycycle --------------- HandleRX: ARRAYREAD USBRXBuffer,[PORTB, DUTY1.LowByte, DUTY1.HighByte, _ DUTY2.LowByte, DUTY2.HighByte] 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 Duty2 CCPR2L=DUTY2>>2 ' return
DT_HID already uses the USB interrupt.
If you override it, then USB can't happen anymore.
Besides, your routine is not suitable for interrupts anyway.
There's 1000 loops with pauses and gosubs ... wouldn't work.
There is already a way to determine if the cable is plugged in or not, and that is handled by DT_HID.
When the cable is plugged in, and the USB is connected to the PC and has fully enumerated. The Plugged bit will be 1. When not plugged, it's 0.
So just put your routine in the Main loop, and only run it IF Plugged = 1.
Don't forget to restore the INT_Handler ...Also, DO NOT enter sleep mode when using USB.Code:ASM INT_LIST macro ; IntSource, Label, Type, ResetFlag? INT_Handler USB_Handler endm INT_CREATE ; Creates the interrupt processor endasm
<br>
DT
Bookmarks