PDA

View Full Version : PIC 18F2455 USB code compiling problem



abdy37
- 3rd July 2007, 10:11
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.

http://img259.imageshack.us/img259/7471/errors1hy3.jpg (http://imageshack.us)
Shot at 2007-07-03

skimask
- 3rd July 2007, 14:49
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...

abdy37
- 3rd July 2007, 15:35
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

skimask
- 3rd July 2007, 15:45
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.

abdy37
- 3rd July 2007, 16:18
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.

mister_e
- 4th July 2007, 00:31
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


;************************************************* ***************
;* 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 ...

abdy37
- 4th July 2007, 11:24
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.

http://img233.imageshack.us/img233/2580/screenshotxf6.th.jpg (http://img233.imageshack.us/my.php?image=screenshotxf6.jpg)

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?

mister_e
- 4th July 2007, 14:13
what happen if you select PIC18F2550 or 18F4550?

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

abdy37
- 4th July 2007, 15:30
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.

mister_e
- 4th July 2007, 17:20
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



Paste your code here



Please check you p18F2455.INC file in MPASM SUITE folder and search for TRNIF...line 234 or so

;----- 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'

skimask
- 5th July 2007, 04:21
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.

abdy37
- 5th July 2007, 14:01
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.

armand1987
- 28th March 2009, 15:31
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

abdy37
- 30th March 2009, 11:01
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.

armand1987
- 31st March 2009, 13:04
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!!!