PIC 18F2455 USB code compiling problem


Closed Thread
Results 1 to 15 of 15
  1. #1
    Join Date
    Mar 2007
    Location
    Bursa, Turkey
    Posts
    16

    Default PIC 18F2455 USB code compiling problem

    Hi. I got now stuck with USB stuff with PIC 18F2455.
    Shortly, I want to apply a sine wave to PORTA.0, do ADC conversion
    and send the data via USB to PC. Meanwhile, the PC interface is no ready as
    I couldn't compile the code. As soon as the PC interface is ready I am planning make sure that I get data on the PC side and send them out and via
    DAC reconstruct that sine wave.

    Here I modified Steve's USBDemo.zip. I am new to macro files, do not know what they are used for and need it at all. But however, I used macros. Could I figure that out without macros. Because I didn't understand some lines of the code I actaully used. Any input, help about the code and/or macros will
    be appreciated.

    My PBP version is 2.46 an I use MicroCode Studio 2.3.0.0. The necessary lines of 18F2455.INC file are commented as needed.

    And I have the errors below. Can someone help me with that.


    Shot at 2007-07-03
    Attached Images Attached Images  
    Attached Files Attached Files
    Don't worry be happy....

  2. #2
    skimask's Avatar
    skimask Guest

    Default

    Quote Originally Posted by abdy37 View Post
    Hi. I got now stuck with USB stuff with PIC 18F2455.
    Shortly, I want to apply a sine wave to PORTA.0, do ADC conversion
    and send the data via USB to PC. Meanwhile, the PC interface is no ready as
    I couldn't compile the code. As soon as the PC interface is ready I am planning make sure that I get data on the PC side and send them out and via
    DAC reconstruct that sine wave.
    Good luck doing much more than a good couple of khz with that...

    My PBP version is 2.46 an I use MicroCode Studio 2.3.0.0. The necessary lines of 18F2455.INC file are commented as needed.
    Get latest MPLAB (7.62?) and MCS 3...

  3. #3
    Join Date
    Mar 2007
    Location
    Bursa, Turkey
    Posts
    16

    Thumbs down

    Quote Originally Posted by skimask View Post
    Good luck doing much more than a good couple of khz with that...

    Thank you for your invaluable advices. It just keeps me 'better'. It seems you are enjoying making a fun of folks.

    Get latest MPLAB (7.62?) and MCS 3...
    There is no MPLAB 7.62. The latest version is 7.61 and I use v7.60.
    MCS version on the Melabs site is 2.3.0.0
    Don't worry be happy....

  4. #4
    skimask's Avatar
    skimask Guest

    Default

    Quote Originally Posted by abdy37 View Post
    There is no MPLAB 7.62. The latest version is 7.61 and I use v7.60.
    MCS version on the Melabs site is 2.3.0.0
    Ok, 7.61 then...couldn't remember...
    MCS version on MeLabs might be 2.3, but MCS version on MCS webpage is 3.0.

  5. #5
    Join Date
    Mar 2007
    Location
    Bursa, Turkey
    Posts
    16

    Talking

    Quote Originally Posted by skimask View Post
    Ok, 7.61 then...couldn't remember...
    MCS version on MeLabs might be 2.3, but MCS version on MCS webpage is 3.0.
    I will let you know if something changes.
    Don't worry be happy....

  6. #6
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898

    Default

    Hi Abdykerim,

    Error #1
    There's 2 DoUSBIn, AND 2 DoUSBOute label, They are located at the bottom of your program...

    Error #2,3,4,5,6,7,8,9,A,B,... Ok Ok
    once you have commented the default config fuses in the 18F2455.INC file located PBP folder
    Code:
    ;****************************************************************
    ;*  18F2455.INC                                                 *
    ;*                                                              *
    ;*  By        : Leonard Zerman, Jeff Schmoyer                   *
    ;*  Notice    : Copyright (c) 2006 microEngineering Labs, Inc.  *
    ;*              All Rights Reserved                             *
    ;*  Date      : 06/05/06                                        *
    ;*  Version   : 2.47                                            *
    ;*  Notes     :                                                 *
    ;****************************************************************
            NOLIST
        ifdef PM_USED
            LIST
            "Error: PM does not support this device.  Use MPASM."
            NOLIST
        else
            LIST
            LIST p = 18F2455, r = dec, w = -311, w = -230, f = inhx32
            INCLUDE "P18F2455.INC"	; MPASM  Header
           ; __CONFIG    _CONFIG1L, _PLLDIV_5_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
           ; __CONFIG    _CONFIG1H, _FOSC_HSPLL_HS_1H
           ; __CONFIG    _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H
           ; __CONFIG    _CONFIG3H, _PBADEN_OFF_3H
           ; __CONFIG    _CONFIG4L, _LVP_OFF_4L & _XINST_OFF_4L
            NOLIST
        endif
            LIST
    EEPROM_START	EQU	0F00000h
    BLOCK_SIZE	EQU	32
    ... nothing else wrong happen IF AND ONLY IF YOU HAVE SELECTED THE RIGHT PIC IN THE DROP MENU AS WELL ...
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  7. #7
    Join Date
    Mar 2007
    Location
    Bursa, Turkey
    Posts
    16

    Unhappy The problem persists

    Yeah I found out there were 2 DoUSBin and 2 DoUSBout labels after I uploaded
    the code. I deleted the bottom part of the code. I forgot to note that I use EasyHID too. In my PBP 2.46 folder the 18F2455.INC file looks like below:

    ;************************************************* ***************
    ;* 18F2455.INC *
    ;* *
    ;* By : Leonard Zerman, Jeff Schmoyer *
    ;* Notice : Copyright (c) 2004 microEngineering Labs, Inc. *
    ;* All Rights Reserved *
    ;* Date : 12/31/04 *
    ;* Version : 2.46 *
    ;* Notes : *
    ;************************************************* ***************
    NOLIST
    ifdef PM_USED
    LIST
    "Error: PM does not support this device. Use MPASM."
    NOLIST
    else
    LIST
    LIST p = 18F2455, r = dec, w = -311, f = inhx32
    INCLUDE "P18F2455.INC" ; MPASM Header
    ;__CONFIG _CONFIG1L, _PLLDIV_5_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
    ;__CONFIG _CONFIG1H, _FOSC_HSPLL_HS_1H
    ;__CONFIG _CONFIG2H, _WDT_ON_2H & _WDTPS_128_2H
    ;__CONFIG _CONFIG3H, _PBADEN_OFF_3H
    ;__CONFIG _CONFIG4L, _LVP_OFF_4L & _ICPRT_OFF_4L & _XINST_OFF_4L
    NOLIST
    endif
    LIST
    EEPROM_START EQU 0F00000h
    BLOCK_SIZE EQU 32

    From the drop down menu I choose 18F2455 too. I can give a screen shot I did.



    The code looks like:

    '
    ' MyUSB
    ' =====
    '
    ' File name : MyUSB.pbp
    ' Programmer: Abdykerim Mamedov
    ' Date : July 2, 2007
    ' Device : PIC 18F2455 & 4MHZ crystal
    '
    '
    ' Supposed to send and read from USB bus.
    '
    ' Hardware:
    ' ---------
    ' Signal genarator (Sinusoidal,triangular or square wave)
    ' USB cable
    ' 4 MHZ crystal
    '
    '
    ' Software:
    ' ---------
    ' The PC interface is not ready yet, but supposed to be VB6 source code
    '
    '
    ' Pic Configuration Fuses
    ' =======================
    @ ERRORLEVEL -230

    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 & _FCMEN_OFF_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

    '
    ' Hardware configuration
    ' ======================
    '
    ' I/O and PORTs
    ' -------------
    TRISA.0 = 1 ' Set pin 0 of PORTA an input
    '
    ' A/D converter
    ' -------------
    ADCON0 = %00000001 ' Configuring Analog Channel Select bits ,
    ' A/D Conversion Status bit, A/D On bit
    ADCON1 = %00001101 ' Configuring Voltage Reference Configuration bits,
    ' (AN0 analog, others digital), A/D Port Configuration Control bits
    ADCON2 = %10001000 ' Configuring A/D Result Format Select bit (Right justified ),
    ' A/D Acquisition Time Select bits (4 TAD),
    ' A/D Conversion Clock Select bits (Fosc/64)
    '
    ' USB module
    ' ----------
    UCFG var byte EXT ' include UCFG register... Yeah Melabs didn't
    ucfg = %00010100 ' enable internal USB pull-up, Full speed USB

    '
    ' Interrupt definition
    ' ====================
    ' TMR0 interrupt used to keep USB connection alive
    ' by sending USBSERVICE at each 100uSec or so.
    INTCON = %10100000 ' Enable global and TMR0 interrupts
    T0CON = %10000000 ' TMR0, CLK internal, prescaler 1:2, T0ON

    '
    ' Variables & constants definition
    ' ================================
    USBBufferSizeTX con 8 ' input
    USBBufferSizeRX con 8 ' output
    USBBufferCount Var Byte '
    USBBufferIn var byte[8] ' store incomming USB data
    USBBufferOut Var Byte[8] ' store outgoing USB data
    DataToSend var BYTE[8] ' store ADCs

    @ADRead = ADRESL ; use to read both ADCs register in one shot
    ADRead VAR WORD EXT ' make it available to use in PBP
    '
    ' Constants definition
    ' ====================
    TMR0IF VAR INTCON.2 ' TMR0 overflow int flag
    TMR0ON VAR T0CON.7 ' TMR0 on/off bit
    TMR0IE VAR INTCON.5 ' TMR0 interrupt enable/disable bit
    GoDone var ADCON0.1 ' ADC conversion
    '
    ' Macro(s) definition
    ' ===================
    goto SwHwInit ' skip macros
    Reload_TMR0:
    TMR0ON = 0
    TMR0L=65000
    TMR0IF = 0
    TMR0ON = 1
    RETURN
    asm
    SendUSB macro array
    ; Use to Copy an specific array to USBBufferOut AND send it
    ; to USB bus
    variable i=0
    while i<8
    MOVE?BB (array+i),(_USBBufferOut+i)
    i+=1
    endw
    L?CALL _DoUSBOut
    endm
    endasm

    '
    ' Software/Hardware initialisation
    ' ================================
    SwHwInit:
    pause 500 ' Settle delay
    usbinit ' initialise USB
    GOSUB Reload_TMR0 ; Reload timer0
    ON INTERRUPT GOTO DoUSBService
    '
    ' Main program start
    ' ==================
    Start:
    '
    '
    ' Do ADC conversion and save it to specific DataToSend array
    ' ----------------------------------------------------------
    PAUSEUS 125 ' arbitrary SamplingTime
    GODONE=1 ' start conversion
    WHILE GODONE : WEND ' wait 'till finish
    DATATOSEND = ADREAD ' save it to DataToSend array

    ' Send data to USB bus
    ' --------------------
    @ SendUSB _DataToSend
    '
    ' Check if there's any incomming data
    ' -----------------------------------
    gosub dousbin
    '
    ' Redo from start
    ' ---------------
    goto start
    END
    '
    '
    ' Subroutines area
    ' ================
    '
    DoUSBIn:
    '
    ' Check and receive data from the USB bus
    ' =======================================
    tmr0ie = 0 ' disbale TMR0 int
    USBBufferCount = USBBufferSizeRX ' RX buffer size
    USBService ' keep connection alive
    USBIn 1, USBBufferin, USBBufferCount, Timeout ' read data, if available
    Timeout: '
    GOSUB Reload_TMR0
    tmr0ie = 1 ' re-enable TMR0 int
    PORTB = USBBUFFERIN[0] ' output to PORTB
    return
    '
    '
    '
    DoUSBOut:
    '
    ' Send data to the USB bus & Wait for USB interface to attach
    ' ================================================== =========
    TMR0IE = 0 ' Disable TMR0 interrupt
    WaitPC: '
    USBBufferCount = USBBufferSizeTX ' TX buffer size
    USBService ' keep connection alive
    USBOut 1, USBBufferOut, USBBufferCount, Waitpc ' if bus available, transmit data
    GOSUB Reload_TMR0
    tmr0ie=1 ' Re-Enable TMR0 interrupt
    return

    DISABLE
    DoUSBService:
    usbservice ' keep connection alive
    GOSUB Reload_TMR0 ; reload timer
    RESUME ' get out of here
    ENABLE

    I do not know what the problem is. The errors are not "dying". Isn't there anyone using PBP 2.46 down here. Maybe it's a common problem for 18F series.

    Can anyone try this code and inform me?
    Don't worry be happy....

  8. #8
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898

    Default

    what happen if you select PIC18F2550 or 18F4550?

    Maybe it's a MPLAB/MPASM installation/Version issue ?
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  9. #9
    Join Date
    Mar 2007
    Location
    Bursa, Turkey
    Posts
    16

    Exclamation

    I use MPASM v.5.03 and MPLAB v.7.60.
    I reinstalled MPLAB.
    I tried both 2550 and 4550 too. Same errors with them too.
    Don't worry be happy....

  10. #10
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898

    Default

    Still compile fine here...

    Sure there's something weird in your PBP installation... well i think

    Anybody here still have 2.46 and may compile all the above?

    P.S.: to place your code in a window like i did, just type

    [code]
    Paste your code here
    [/code]


    Please check you p18F2455.INC file in MPASM SUITE folder and search for TRNIF...line 234 or so
    Code:
    ;----- UIR Bits -----------------------------------------------------
    URSTIF           EQU  H'0000'
    UERRIF           EQU  H'0001'
    ACTVIF           EQU  H'0002'
    TRNIF            EQU  H'0003'
    IDLEIF           EQU  H'0004'
    STALLIF          EQU  H'0005'
    SOFIF            EQU  H'0006'
    Last edited by mister_e; - 4th July 2007 at 16:26.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  11. #11
    skimask's Avatar
    skimask Guest

    Default

    Quote Originally Posted by abdy37 View Post
    I use MPASM v.5.03 and MPLAB v.7.60.
    I reinstalled MPLAB.
    I tried both 2550 and 4550 too. Same errors with them too.
    Latest version of MPASM is 5.11.
    Might be time to uninstall ALL of the old MPLAB, delete everything and do a fresh install.

  12. #12
    Join Date
    Mar 2007
    Location
    Bursa, Turkey
    Posts
    16

    Talking The program succeeded

    Thank you folks. I eventually found what the 'bug' is.
    I reinstalled MPLAB v.7.61 and MPASM v.5.11.
    The 'bug' was that I did not specify the path for Compiler.
    In the menu there is Compile and Program Options under View tab.
    In the Assembler tab I specified the path for MPASM, i.e C:\Program Files\Microchip\MPASM Suite.

    I will post my VB code as soon as I write. This thread is not finished yet.
    Thanks to Steve and Skimask.
    Don't worry be happy....

  13. #13
    Join Date
    Mar 2009
    Posts
    2

    Default

    plz abdy37 can you post your code!
    I have the same project than you and i having problems finding what functions to use to send the data to the pc via USB
    I m usinf c18 to write my code
    i have written the code that does the conversion, and i still have to write the code that send the converted data to the pc via usb
    It would be great if you can post your code so i could learn from it to write my own code
    thanks a lot

  14. #14
    Join Date
    Mar 2007
    Location
    Bursa, Turkey
    Posts
    16

    Smile

    Hi armand1987. How you're doing? I will try to upload it to the thread, or
    alternatively post it your mail. But only tomorrow or later. What do you need it for?
    Is that a university project, or thesis.

    Regards.
    Don't worry be happy....

  15. #15
    Join Date
    Mar 2009
    Posts
    2

    Default

    hey abdy37!
    i need it for my university project where we want to send converted data using the ADC from the USB port of the 18F14550.
    you can send your code to [email protected]
    10x for all ur help!!!
    Last edited by armand1987; - 31st March 2009 at 12:07.

Similar Threads

  1. Need PIC MODBUS RTU code. Will pay.
    By vsingh in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 15th February 2012, 12:04
  2. Problem runing my code
    By Mus.me in forum mel PIC BASIC Pro
    Replies: 33
    Last Post: - 1st December 2009, 20:36
  3. 16f887 44 pin demo board code problem?
    By jessey in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 7th December 2008, 14:17
  4. Apparent code size problem
    By eetech in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 30th July 2007, 15:51
  5. Microcode Studio 18f2455 problem?????
    By volkan in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 21st May 2007, 21:04

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