USBSERVICE And SERIN2 Odd Behavior


+ Reply to Thread
Results 1 to 7 of 7
  1. #1
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    626

    Default USBSERVICE And SERIN2 Odd Behavior

    Hi,

    I have the following code below where every once in a while I'm checking the incoming data using SERIN2. If I change the WAIT-TIME in SERIN2 from 5mS to 4mS or less the USB connection would get lost and disconnected intermittently. When I use a 5mS for WAIT-TIME the program is very stable. The length of the SERIN2 incoming package is 3.6mS. Any idea why is this happening? Should I increase that 5mS to 7 or 8mS? I believe that the USBSERVICE should be done every 10 milli seconds or less, is this correct? Is there a better way to do what I'm trying to accomplish?

    Thanks,

    Robert

    Code:
        FOR J = 0 TO 7
            USBSERVICE
            GOSUB SearchForClockSignal
            USBSERVICE            
            IF ClockSignalFound = 1 THEN EXIT       'EXITS THE LOOP IF A CLOCK SIGNAL WAS RECEIVED
        NEXT J
    
    SearchForClockSignal:
                                                    
        USBSERVICE
        SERIN2 PORTB.7, 32, 5, CLOCKSEARCHFAILED, [STR RFID_IN\7]
        USBSERVICE 
    
        ClockSignalFound = 1    'SETS FLAG TO STOP SEARCH
    
        CLOCKSEARCHFAILED:
    
        return
    "No one is completely worthless. They can always serve as a bad example."

    Anonymous

  2. #2
    Join Date
    May 2013
    Location
    australia
    Posts
    1,714

    Default Re: USBSERVICE And SERIN2 Odd Behavior

    I believe that the USBSERVICE should be done every 10 milli seconds or less, is this correct? Is there a better way to do what I'm trying to accomplish?
    its not so much as to service it every 10ms or less but to respond to polls before the host times you out. i use the isr option for usb service

    Code:
    ASM
    INT_LIST  macro    ; IntSource,        Label,           Type,   ResetFlag?
           
           INT_Handler    USB_INT,  _DoUSBSERVICE,   ASM,  yes
          
        endm
        INT_CREATE
        INT_ENABLE  USB_INT   
    ENDASM
    Code:
    DoUSBSERVICE:
           USBSERVICE                   ; Run the SERVICE routines
    @ INT_RETURN
    main issue with that is that bitbanged comms like serin/out can't tolorate the interrupts
    serial comms needs to be via the eusart
    Last edited by richard; - 12th July 2020 at 05:37.
    This is more entertaining than Free to Air TV

  3. #3
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    626

    Default Re: USBSERVICE And SERIN2 Odd Behavior

    Thanks, Richard. Now, I'm using the Darrel's USB interrupt and it helps. It is not really crucial in my program if a package is lost using the SERIN2 or SEROUT2 commands. I changed my code like it's shown below and it's working fine so far.

    'FOR J = 0 TO 7
    USBSERVICE
    GOSUB SearchForClockSignal
    USBSERVICE
    'IF ClockSignalFound = 1 THEN EXIT 'EXITS THE LOOP IF A CLOCK SIGNAL WAS RECEIVED
    'NEXT J


    SearchForClockSignal:

    USBSERVICE
    SERIN2 PORTB.7, 32, 50, CLOCKSEARCHFAILED, [STR RFID_IN\7]
    USBSERVICE

    'ClockSignalFound = 1 'SETS FLAG TO STOP SEARCH

    CLOCKSEARCHFAILED:

    return
    "No one is completely worthless. They can always serve as a bad example."

    Anonymous

  4. #4
    Join Date
    May 2013
    Location
    australia
    Posts
    1,714

    Default Re: USBSERVICE And SERIN2 Odd Behavior

    if you are using USBSERVICE in a interrupt routine then its unnecessary to make additional calls to it , its probably not re-entrant code either.
    making calls to it both inside and outside the isr may have unexpected consequences
    This is more entertaining than Free to Air TV

  5. #5
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    626

    Default Re: USBSERVICE And SERIN2 Odd Behavior

    Thanks, I haven't clean up the code yet. That makes sense about the unexpected issues.
    "No one is completely worthless. They can always serve as a bad example."

    Anonymous

  6. #6
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    626

    Default Re: USBSERVICE And SERIN2 Odd Behavior

    This program having SERIN2 working together with a USB connection keeps giving me headaches . The first code below works fine for many straight hours and days. However the second code gets hung up after half an hour or so. This SUB is called once every second more or less. Is there anything that I'm missing here? Why does the second code gets hung up after a while?

    THIS CODE WORKS FINE:
    Code:
    SearchForClockSignal:
    
        @ INT_DISABLE  USB_INT 
        PIR2.5 = 0    
            
        SERIN2 PORTB.7, 32, 5, CLOCKSEARCHFAILED, [STR RFID_IN\7]
        
        @ INT_ENABLE  USB_INT
    
        '.... SOME CODE HERE TO PROCESS THE DATA
    
        CLOCKSEARCHFAILED:
        @ INT_ENABLE  USB_INT 
    
    RETURN
    THIS CODE GETS HUNG UP AFTER A WHILE:
    Code:
    SearchForClockSignal:
    
        @ INT_DISABLE  USB_INT 
        PIR2.5 = 0    
        
        FOR J = 0 TO 5        
            SERIN2 PORTB.7, 32, 5, CONTINUESERIN2, [STR RFID_IN\7]
            CONTINUESERIN2:
            USBSERVICE
            IF RFID_IN[0] = 252 THEN EXIT   'THE DATA PACKAGE WAS RECEIVED
        NEXT J
        
        @ INT_ENABLE  USB_INT
    
        '.... SOME CODE HERE TO PROCESS THE DATA
    
        CLOCKSEARCHFAILED:
    
    RETURN
    "No one is completely worthless. They can always serve as a bad example."

    Anonymous

  7. #7
    Join Date
    May 2013
    Location
    australia
    Posts
    1,714

    Default Re: USBSERVICE And SERIN2 Odd Behavior

    since only code snippets posted and
    no hardware description pic/usb descriptor and
    no explanation why eusart not employed and
    no description of failure point or why "working" code not suitable

    for a meaningful forum response more detail would not go astray.

    i'm only a novice at usb stuff at best but there is just not enough data to go on for me.
    in general i would not expect two such asynchronous time critical services to ever be reliable on a single core device
    without some hardware support.


    some thoughts
    SearchForClockSignal:
    @ INT_DISABLE USB_INT
    PIR2.5 = 0 ? why here
    FOR J = 0 TO 5
    SERIN2 PORTB.7, 32, 5, CONTINUESERIN2, [STR RFID_IN\7] ? 5ms ? usb can be polled at intervals down to 1ms device dependent
    // what is your actual poll frequency ? use wireshark to get a picture of whats happening

    CONTINUESERIN2:
    USBSERVICE
    IF RFID_IN[0] = 252 THEN EXIT 'THE DATA PACKAGE WAS RECEIVED
    NEXT J
    // no attempt here to clear irq flag before re engaging isr could be an issue
    @ INT_ENABLE USB_INT

    '.... SOME CODE HERE TO PROCESS THE DATA

    CLOCKSEARCHFAILED:
    RETURN
    This is more entertaining than Free to Air TV

Similar Threads

  1. USBSERVICE + serout2 problem
    By EToscano in forum USB
    Replies: 51
    Last Post: - 22nd December 2011, 15:35
  2. Odd behavior if too many instructions
    By dksoba in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 19th February 2010, 21:58
  3. USBSERVICE timing question
    By Kamikaze47 in forum USB
    Replies: 2
    Last Post: - 17th July 2007, 21:16
  4. USBSERVICE & timer
    By Shamir in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 3rd August 2006, 17:47
  5. USBinit and USBservice
    By Christopher4187 in forum General
    Replies: 5
    Last Post: - 4th March 2006, 15:50

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts