Hi Guys,
need some advice as I'm going crazy trying to figure out what I've screwed up in the code I'm using.
A good friend of mine wrote a very basic project to control some aquarium lights. His code basically uses four CASE statements per channel to set the on time for channel 1 & 2, the ramp up time for each channel, the duration both channels are on, and the fade down duration. So for example channel one could come on at 10:00, channel two on at 10:15, both then fade up to full brightness by 11:00, channel one then begin to fade down at 20:00, turning off at 21:00, with channel two fading between 20:30 and 22:00 for example. That part works fine.
To make life easy my friend wrote a small windows application so that the on / off, fade durations etc could all be set by sliders and then the values squirted to the chip, which was originally an 18f2550. As I need more pins as I am developing his project further (with his permission) I've opted for an 18F4550. I was originally using a 20Mhz Xtal and with the following settings
The PC picks up the connection and the USB device was reported as being installed successfully. His application loads, and automatically reads the values from the PICs eprom settings and moves the sliders and displays the numbers as per the default values that are entered. However, if the sliders are changed and the "update" button is pressed the new values are not written back to the chip.Code:ASM ; 18F2550/4550, 20mhz crystal __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_ON_2H & _WDTPS_512_2H __CONFIG _CONFIG3H, _PBADEN_OFF_3H __CONFIG _CONFIG4L, _LVP_OFF_4L & _XINST_OFF_4L ENDASM DEFINE OSC 48 CLEAR
The code uses DT_HID260 which I'm guessing is something written by Darrel.
The actual bit that gets called to do the USB comms isCode:'**************************************************************** 'Setup Interrupts '**************************************************************** INCLUDE "DT_INTS-18.bas" ; Base Interrupt System INCLUDE "ReEnterPBP-18.bas" ASM INT_LIST macro ; IntSource, Label, Type, ResetFlag? INT_Handler USB_Handler INT_Handler TMR1_INT, _MyTimer, PBP, yes endm INT_CREATE ; Creates the interrupt processor endasm T1CON = %10000001 ; free-running, 1:1 prescaler @ INT_ENABLE TMR1_INT ; enable Timer1 interrupts '**************************************************************** 'Setup USB '**************************************************************** INCLUDE "DT_HID260.pbp" DEFINE USB_VENDORID 6017 DEFINE USB_PRODUCTID 1969 DEFINE USB_VERSION 1 DEFINE USB_VENDORNAME "CSL Designs" DEFINE USB_PRODUCTNAME "Aqua-LED" DEFINE USB_SERIAL "001" DEFINE USB_INSIZE 64 ; IN report is PIC to PC (8,16,32,64) DEFINE USB_OUTSIZE 64 ; OUT report is PC to PIC DEFINE USB_POLLIN 10 ; Polling times in mS, MIN=1 MAX=10 DEFINE USB_POLLOUT 10 '****************************************************************
I've tried removing the timeout option and substituting it for the getUSB so it loops and that didin't work, I've also tried using a 4Mhz resonator with the same fuse settings as the 2550 chip and that still fails to updateCode:SendUSB: for i = 0 to USBBufferCount - 1 read i,USBTXBuffer[i] 'Read the eeprom data and store in the outward bound buffer next i SendData: USBOut 1, USBTXBuffer, USBBufferCount , SendDATA ' if bus available, transmit data return GetUSB: USBin 1, USBRXBuffer, USBBufferCount, Timeout ' if bus available, receive data if Firstsend = 0 then for i = 0 to USBBufferCount - 1 write i,USBRXBuffer[i] 'Write the eeprom data received from the PC next i gosub Read_eeprom 'Read eeprom data into the variables else Firstsend = 0 endif Timeout: return ' If USB plugged display USB on the display USB_Plugged: if plugged = 0 then lcdout $FE,$91," " else lcdout $FE,$91,"USB" endif return
I've also checked the settings for PORT.C to make sure it's not all set to output - still no joy.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 & _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 & _XINST_OFF_4L & _DEBUG_OFF_4L endasm DEFINE OSC 48 clear
I would welcome suggestions on things to try, or point me to where the problem may be.... My friend thinks it must be a timing issue, which when I was running with a 20 Mhz and a divide/5 prescaler I might of agreed (however I would of thought that if this was the case then windows would of reported a device not recognised error), but then even using the 4Mhz resonator (which doesn't seem to make the code run any slower, so I would be happy with that for the performance) still didn't work.
Thanks in advance...
Malcolm




Bookmarks