USBSERVICE + serout2 problem


Closed Thread
Results 1 to 40 of 52

Hybrid View

  1. #1
    Join Date
    Dec 2007
    Location
    Paris
    Posts
    101

    Default

    I think that most of my USB problems are solved now!

    I rewrote the USB Out routine as such:

    Code:
    '*******************************************************
    '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
    
    FOR Counter = 1 TO USBBufferSizeMax 'Clear the USB buffer after data has been sent
    USBBuffer [Counter - 1] = 0
    NEXT Counter
    
    RETURN
    - Fist step is to calculate how many bytes are used in the string (not = 0)
    - Second, sending data
    - third, blanking the data buffer for next operation

    I have no more garbage data in my strings, and I was able to remove the Pause without any data loss. Transmission is very fast now, with over 10kB/s (I have large conversion routines between my DoUSBOut, could even be faster without these).

    Now onto other problems, especially getting all the interrupts to work together,and implementing ADC and ultra-low power routine.

    What about publishing the generic code for CDC? I'll let you decide since it is actually minor modification to code you have written.

  2. #2
    Join Date
    Dec 2007
    Location
    Paris
    Posts
    101

    Default Re: USBSERVICE + serout2 problem

    And everything collapsed!

    The CDC USB routine was working well until now. It is working very well on my early prototypes, I made 3 more identical one and the PIC just stop running randomly after a few seconds up to several minutes. USB communication stops and LEDs turns off. It still respond to the INT0 interrupt though, and resume normal operation after reset... until it crashes again randomly.

    I am puzzled as the hardware is strictly identical, the only difference I could spot is in the silicon revision of the PIC18LF14K50, says 0000006 on the working batch and 0000005 on the batch that crashes. I have inserted a simple blinking LED loop routine at the very beginning of my code, and it still crashes and stop blinking. Removing part of the program related to USB solve the crashing problem so I would think that there is something wrong in the USB CDC code I have modified.

    Problem is that in the revision errata there is nothing linked to the USB SIE, and I am totally clueless about where to start to debug this issue. What could be wrong to have the PIC crash at a random time interval? some kind of buffer overflow?

  3. #3
    Join Date
    Dec 2007
    Location
    Paris
    Posts
    101

    Default Re: USBSERVICE + serout2 problem

    A bit more debugging, it seems that only the USBIN side does crash.

    Code:
    '*******************************************************
    '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                                                                   
        GOSUB UpdateLEDStatus
    WEND
                                       
    IF RX_READY THEN
        RX_READY = 0 'Clear USB data received flag
        USBBufferCount = USBBufferSizeRX
        USBIn 3, USBBuffer, USBBufferCount, DoUSBIn    
    ENDIF
    
    RETURN
    At random the UpdateLEDStatus subroutine stop to be serviced, and the USBIN does not receive anymore data. When it crashes, RX_READY = 0, then if I send data RX_READY = 1 and just stay there, without being cleared. the USBOUT side toes work well though, even when the IN side has crashed.

    Might have something to do with USB_ASM_Service.pbp not working properly?

    -> A bit more debug introducing some LED blink to see if the USB_ASM_Service is being called: it stops being called when it crashes...
    Last edited by aberco; - 10th December 2011 at 20:15.

  4. #4
    Join Date
    Dec 2007
    Location
    Paris
    Posts
    101

    Default Re: USBSERVICE + serout2 problem

    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

  5. #5
    Join Date
    Dec 2007
    Location
    Paris
    Posts
    101

    Default Re: USBSERVICE + serout2 problem

    After debugging everything pinpoint an issue coming from the different revision of the PIC. The CDC routine works with silicon revision 0000006 of the PIC18LF14K50, but not 0000005.
    Really getting stuck there as I have no clue of how to solve the problem, and I cannot rely on ordering a specific revision of the microcontroller...

Members who have read this thread : 2

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