USBSERVICE + serout2 problem


Closed Thread
Results 1 to 40 of 52

Hybrid View

  1. #1
    Join Date
    Oct 2009
    Posts
    5

    Default USBSERVICE + serout2 problem

    Good afternoon everybody, I need some asistance with a problem with a USB/Serial program.
    I'm posting this in both the USB and SERIAL groups.

    This is running on a 18f4550@48mhz using DT's "usb_asm_service".


    the thing is if in my main loop I put:

    baud485 con $4006

    mainloop:


    high en485
    serout2 tx485,baud485,["!",s485(0),s485(1),s485(2),s485(3),s485(4),s485(5), _
    s485(6),s485(7),s485(8),s485(9),s485(10),s485(11), _
    s485(12),s485(13),s485(14)]
    low en485

    pause 1000
    goto mainloop


    end



    if the usb cable is not connected, I get the sent bytes on my 485 bus, but as soon as I plug the usb cable, I start loosing some bytes(at least 1) of every cycle.

    this is not the actual code, but it does the same thing basically.

    It seems to me as if during the serout2 instruction the usbservice happens it kills the byte being transmited at the time.
    Do I make any sense?

    What I need is to be able to process serial comm using serout2 to other devices even when the device is connected to the usb host.

    Hopefully this is clear enough so someone can share some tips.


    Best regards

    Eduardo Toscano
    Seneca Sistemas

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924

    Default

    I deleted your other post as there is no need to double post.

    You may need to post your complete code also.
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959

    Default

    Anytime you are using interrupts (other than ON INTERRUPT), it interrupts things.
    USB_ASM_Service uses USB interrupts that happen quite frequently.

    Software timed routines like SEROUT2, PAUSE, PULSIN/OUT etc. Will lose time that they don't know about.

    When using interrupts, Hardware devices should be use instead of software commands.
    Instead of SEROUT2, use HSEROUT with the USART.

    PAUSE ... use a timer.
    PULSIN ... use a CCP module.
    COUNT ... use a Timer

    There are still many PBP commands you can use without problems.
    But, if if they require specific timing thru software, that timing will be disturbed.
    DT

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

    Default

    Hi Darrel,
    I'm actually back on USB development, there is quite a bit of new stuffs! your USB_ASM_Service routine is very exciting.

    If I understand correctly the timing issue will also "kill" I2CRead/Write, Shiftin/Shiftout, LCDout... There's hardware modules for SPI and I2C, even if they are not used by these instructions. However there's not much solution for driving the LCD.

    Is the delay introduced by the interrupt that long? I mean, some processes does not require an extreme regularity of clocking/data signals, an intelligent LCD display should probably cope with this.

    However I haven't been able to experiment with it yet... I have managed to compile and run successfully the DCD demo on a PIC18F13K50. Adding the USB_ASM_Service routine and commenting the USBService/USBInit in the demo makes the board unable to declare itself anymore.

    I've also tried running both the interrupt and polled USB servicing to display the status of "PLUGGED" on a LED but nothing happens. The rest of the demo works fine though.

    Any lead for this issue?
    Thanks in advance for your time

  5. #5
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924

    Default

    However I haven't been able to experiment with it yet... I have managed to compile and run successfully the DCD demo on a PIC18F13K50. Adding the USB_ASM_Service routine and commenting the USBService/USBInit in the demo makes the board unable to declare itself anymore.
    Can you post the non-working code?
    Dave
    Always wear safety glasses while programming.

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

    Default

    Yep sure!

    Code:
    ASM
    CONFIG CPUDIV=NOCLKDIV ; CPU runing at full speed
    CONFIG USBDIV=OFF ; Low speed USB clock diviser disabled, not used here
    CONFIG FOSC=HS ; Use of High Speed crystal oscillator
    CONFIG PLLEN=ON ; Enable PLL multiplier, 12Mhz oscilator x 4
    CONFIG PCLKEN=ON ; Primary clock source is enabled
    CONFIG FCMEN=OFF ; Failsafe clock off
    CONFIG IESO=OFF ; Oscillator switchover mode disabled
    CONFIG WDTEN=ON ; Watchdog timer on
    CONFIG WDTPS=512 ; Watchdog divider is 512
    CONFIG MCLRE=OFF ; Disable MCLR pin, enable RC3
    CONFIG STVREN=ON ; Stack full/underflow will cause reset
    CONFIG LVP=OFF ; Low voltage programming disabled
    CONFIG BBSIZ=OFF ; 512kW block boot size
    CONFIG XINST=OFF ; Extended instruction mode disabled
    ENDASM
    
    Include	"cdc_desc.bas"	' Include the CDC descriptors
    INCLUDE "USB_ASM_Service.pbp"  ' USB Init and Service interrupt routines
    
    'Define pin function
    TRISA = %00000000 'PortA all digital output
    TRISB = %00000000 'PortB all digital output
    TRISC = %00000000 'PortC all digital output
    
    ANSEL = %00000000 'Disable analog input on other pins
    ANSELH = %00000000 'Disable analog input on other pins
    
    'Define weak pullups
    WPUA = %00000000 'No weak pullup on portA
    WPUB = %00000000 'No weak pullup on portB
        
    Define  OSC     48
    
    buffer VAR BYTE[16]
    cnt VAR BYTE Byte
    i VAR BYTE
    
    'Pin function declaration
    
    GreenLED VAR PORTC.6
    RedLED VAR PORTC.3
    BlueLED VAR PORTC.4
    
    pwmvalue VAR BYTE
    
    'Program start
    
    pwmvalue = 130
    HPWM 1,pwmvalue,32767
    
    LOW REDLED
    LOW BLUELED
    LOW GREENLED
    
    Pause 10
    
    USBInit	' Get USB going
    
    ' Wait for USB input
    idleloop:
    USBService ' Must service USB regularly
    cnt = 16 ' Specify input buffer size
    USBIn 3, buffer, cnt, idleloop
    
    i = 0
    
    SELECT CASE buffer
            CASE "R"
                HIGH REDLED
                LOW GREENLED
                LOW BLUELED
            CASE "G"
                LOW REDLED
                HIGH GREENLED
                LOW BLUELED
            CASE "B"
                LOW REDLED
                LOW GREENLED
                HIGH BLUELED
            CASE "C"        
                LOW REDLED
                HIGH GREENLED
                HIGH BLUELED
            CASE "M"        
                HIGH REDLED
                LOW GREENLED
                HIGH BLUELED
            CASE "Y"
                HIGH REDLED
                HIGH GREENLED
                LOW BLUELED
            CASE "W"
                HIGH REDLED
                HIGH GREENLED
                HIGH BLUELED
            CASE "K"
                LOW REDLED
                LOW GREENLED
                LOW BLUELED
            CASE ELSE
                i = 1
    END SELECT
    
    ' Message received
    
    IF i = 0 THEN
    	buffer[0] = buffer
    	buffer[1] = "-"
    	buffer[2] = "O"
    	buffer[3] = "k"
    	buffer[4] = 13
    	buffer[5] = 10
    	buffer[6] = 0
    ELSE
            buffer[0] = "E"
    	buffer[1] = "r"
    	buffer[2] = "r"
    	buffer[3] = "."
    	buffer[4] = 13
    	buffer[5] = 10
    	buffer[6] = 0
    ENDIF	
    	
    
    outloop:
    	USBService		' Must service USB regularly
    	USBOut 3, buffer, 7, outloop
    	Goto idleloop		' Wait for next buffer
    It is a quick and dirty modification of the CDC demo. A RGB LED takes the color code sent on the USB port as a letter. The code works, but commenting USBInit, and both USBService kill it.

  7. #7
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    644

    Default

    Quote Originally Posted by aberco View Post
    If I understand correctly the timing issue will also "kill" I2CRead/Write, Shiftin/Shiftout, LCDout... There's hardware modules for SPI and I2C, even if they are not used by these instructions. However there's not much solution for driving the LCD.
    I use I2CRead/Write and LCDout with a USB connection at the same time with no problems. However, I haven't tried using Shiftin/Shiftout and USB at the same time.

    I got the LCDout command working together with the USB connection thanks to the great help from DT. You can see the details in the next link

    http://www.picbasic.co.uk/forum/show...4&daysprune=-1

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

    Anonymous

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

    Default

    Hi mackrackit and thanks for your attention,

    "When using Darrel's includes do not add any USBInit"

    Yes I know that, however if I comment USBInit and USBService it kill the program. It still run but it is not seen by the computer anymore. The include seems to be effective as I can use the PLUGGED, RX_READY and TX_READY variables inside my program without declaring them. They all read 0 whatever is happening though...

    Was it tested on a 13/14K50 before? With CDC profile? or am I doing something wrong? The usage seems pretty straightforward though...

    rsocor01, it is nice to know that all these can be used. Darrel's code for handling the USB is a nice time saver over handling USBService manually. It's just a nightmare when the program gets complicated.

    Thanks to both of you,
    Antoine.
    Last edited by aberco; - 25th August 2010 at 02:47.

Members who have read this thread : 1

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