Well.. finally was able to track the problem down to a conflict between the use of SPWM_INT.bas and USB_ASM_Service.pbp. If I disable the Timer1 interrupt used for sPWM then the USB works well. Strange thing is that the code works well on 3 prototypes with the older PIC silicon revision, and does not work with 3 prototypes with the newer silicon revision...
Anyway, here is the debug program I have that run the sPWM and at the same time read a string from USB and send it back (using CDC serial port emulation).
Code:INCLUDE "cdc_desc.bas" INCLUDE "DT_INTS-18.bas" ; Base Interrupt System INCLUDE "ReEnterPBP-18.bas" ; Include if using PBP interrupts INCLUDE "SPWM_INT.bas" INCLUDE "USB_ASM_Service.pbp" ' USB status variable handled by USBASMService ' "PLUGGED" indicates when the device is fully connected to the PC ' "RX_READY" indicates when a report has been received ' "TX_READY" indicates when it's OK to Send. The device is Plugged and the SIE is ready to accept data '******************************************************* 'Init the software multi_PWM system '******************************************************* DEFINE SPWM_FREQ 200 'SPWM Frequency DEFINE SPWM_RES 256 'SPWM Resolution DutyCycles VAR BYTE [3] 'DutyCycle Variables RedDutyCycle VAR DutyCycles [0] GreenDutyCycle VAR DutyCycles [1] BlueDutyCycle VAR DutyCycles [2] ASM SPWM_LIST macro ;Define Pin's to use for SPWM and the associated DutyCycle variables SPWM_PIN PORTC, 3, _RedDutyCycle SPWM_PIN PORTC, 6, _GreenDutyCycle SPWM_PIN PORTC, 4, _BlueDutyCycle endm SPWM_INIT SPWM_LIST ;Initialize the Pins ENDASM '******************************************************* 'Init the interrupt handling system '******************************************************* ASM ;----[High Priority Interrupts]------------------------- INT_LIST macro ; IntSource, Label, Type, ResetFlag? INT_Handler USB_INT, _DoUSBSERVICE, ASM, yes INT_Handler TMR1_INT, SPWMhandler, ASM, yes endm INT_CREATE ; Creates the High Priority interrupt processor ENDASM '******************************************************* 'BlueTooth module initialisation '******************************************************* @ INT_ENABLE USB_INT ; Enable USB Servicing interrupt @ INT_ENABLE TMR1_INT ; Enable PWM interrupt '******************************************************* 'Main program loop '******************************************************* MainLoop: GOSUB DoUSBIn GOTO MainLoop '******************************************************* 'Reading incoming data from USB port '******************************************************* DoUSBIn: FOR counter = 1 TO USBBufferSizeMax 'Clear the USB buffer before data is received USBBuffer [counter - 1] = 0 NEXT COUNTER WHILE !RX_READY PAUSEUS 5 WEND IF RX_READY THEN RX_READY = 0 'Clear USB data received flag USBBufferCount = USBBufferSizeRX USBIn 3, USBBuffer, USBBufferCount, DoUSBIn ENDIF GOSUB DoUSBOUT RETURN '******************************************************* 'Writing data to USB port '******************************************************* DoUSBOut: USBBufferSizeTX = 0 FOR counter = 1 TO USBBufferSizeMax 'Calculate number of valid bytes within the string IF USBBuffer [counter - 1] > 0 THEN USBBufferSizeTX = USBBufferSizeTX + 1 NEXT COUNTER IF TX_READY THEN 'USB data can be transmitted TX_READY = 0 'Clear USB data send flag USBOUT 3, USBBuffer, USBBufferSizeTX, DoUSBOut ENDIF HSEROUT [STR USBBuffer \USBBufferSizeTX] ClearUSBBuffer: FOR counter = 1 TO USBBufferSizeMax 'Clear the USB buffer after data has been sent USBBuffer [counter - 1] = 0 NEXT COUNTER RETURN END




Bookmarks