PDA

View Full Version : PBP and 18F2550



Fredrick
- 21st January 2009, 09:34
Is there anything special to think of when starting to use the 18F series PICīs with PBP?

I know that i must use MPASM insted of PM.EXE, is there more that are diffrent between the 16F series or do thay in "general" i work the same way.

elec_mech
- 21st January 2009, 13:10
Fredrick,

Nope, they generally work the same. The only big factor when moving from one series to other, which is the same as going from one part number to another, is the config bits. I don't recall doing anything special when going from the 16F series to the 18F. I've been using the 18F2525 myself for years and just recently started using some 16F's for small projects with no problems. If you do have problems, let us know and we'll do our best to help.

Charles Linquis
- 21st January 2009, 14:19
I'll echo this same thing - watch the Configuration Bits and the way the A/D is set up.
I have found 18Fs to be far superior in almost every way, and can't figure out why anyone would want to use 16F parts, unless the project is very cost sensitive and the volumes are large.

Archangel
- 21st January 2009, 16:58
Is there anything special to think of when starting to use the 18F series PICīs with PBP?

I know that i must use MPASM insted of PM.EXE, is there more that are diffrent between the 16F series or do thay in "general" i work the same way.
Make sure your programmer supports them, my JDM Clone would not, I had to get a PICKIT2.

Fredrick
- 21st January 2009, 20:18
I have the Microchip PICKit2 programmer so that PIC is supported.

I just tryed to recompile a PBP program with the 18F2550 and i have no errors, the PIC starts and the LCD display works but not the serin2 and serout2 commands
it only sends junk data to the serialcommunicator via a FTDI232 chip.

When i import the code into the PICKit2 program i get a warning that says "Warning, Some configurations words not in HEX file"

well i think i have to read some datasheets about the config words i guess.

Are there any good webpage exept the datasheet that explain all the common configurations words for 18F2550 and how to set them in PBP?

elec_mech
- 21st January 2009, 21:36
Fredrick,

Unfortunately, no. You have to search the datasheet quite a bit as every PIC is a little bit different. However, here's a way to make it relatively quick:

Open the .INC file for your PIC. Assuming you're using Windows and installed everything in the default locations, go to: C:\PBP and open, in this case, 18F2550.INC. You'll see the following open in Notepad.



;************************************************* ***************
;* 18F2550.INC *
;* *
;* By : Leonard Zerman, Jeff Schmoyer *
;* Notice : Copyright (c) 2007 microEngineering Labs, Inc. *
;* All Rights Reserved *
;* Date : 11/08/07 *
;* Version : 2.50a *
;* Notes : *
;************************************************* ***************
NOLIST
ifdef PM_USED
LIST
"Error: PM does not support this device. Use MPASM."
NOLIST
else
LIST
LIST p = 18F2550, r = dec, w = -311, w = -230, f = inhx32
INCLUDE "P18F2550.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 & 0DFh
NOLIST
endif
LIST
EEPROM_START EQU 0F00000h
BLOCK_SIZE EQU 32


Here you see the default configurations PBP makes if you perform no changes. You have two options to change the config settings.

Method One: modify the config bits as needed (more on this below) and save the file. The only caveat is these settings will take effect in every PIC18F2550 you program unless you remember to change this file each and every time, so it's not typically recommended you do this. Additionally, doing this prevents having people help you with your code if a config setting is wrong or off.

Method Two: put a semi-colon in front of each and every __CONFIG, like so:


;************************************************* ***************
;* 18F2550.INC *
;* *
;* By : Leonard Zerman, Jeff Schmoyer *
;* Notice : Copyright (c) 2007 microEngineering Labs, Inc. *
;* All Rights Reserved *
;* Date : 11/08/07 *
;* Version : 2.50a *
;* Notes : *
;************************************************* ***************
NOLIST
ifdef PM_USED
LIST
"Error: PM does not support this device. Use MPASM."
NOLIST
else
LIST
LIST p = 18F2550, r = dec, w = -311, w = -230, f = inhx32
INCLUDE "P18F2550.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 & 0DFh
NOLIST
endif
LIST
EEPROM_START EQU 0F00000h
BLOCK_SIZE EQU 32


and save the file. All this does is comment out the default config settings so you can use your own in your program. Next, you need to set the config bits within you program, so use the following format at the beginning of your program:


asm
__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 & 0DFh
endasm


What can I change is in the next post. Sorry, apparently this is too long for just one reply.

elec_mech
- 21st January 2009, 21:46
Now the question becomes, what can I change? Glad you asked, again assuming you've got Windows and everything is in the default location, open: C:\Program Files\Microchip\MPASM Suite. Now find and open P18F2550.INC, which will be a fairly large document. Scroll down to the very bottom and you'll see:



;================================================= =========================
;================================================= =========================
;
; Configuration Bits
;
; NAME Address
; CONFIG1L 300000h
; CONFIG1H 300001h
; CONFIG2L 300002h
; CONFIG2H 300003h
; CONFIG3H 300005h
; CONFIG4L 300006h
; CONFIG5L 300008h
; CONFIG5H 300009h
; CONFIG6L 30000Ah
; CONFIG6H 30000Bh
; CONFIG7L 30000Ch
; CONFIG7H 30000Dh
;
;================================================= =========================

; The following is an assignment of address values for all of the
; configuration registers for the purpose of table reads
_CONFIG1L EQU H'300000'
_CONFIG1H EQU H'300001'
_CONFIG2L EQU H'300002'
_CONFIG2H EQU H'300003'
_CONFIG3H EQU H'300005'
_CONFIG4L EQU H'300006'
_CONFIG5L EQU H'300008'
_CONFIG5H EQU H'300009'
_CONFIG6L EQU H'30000A'
_CONFIG6H EQU H'30000B'
_CONFIG7L EQU H'30000C'
_CONFIG7H EQU H'30000D'

;----- CONFIG1L Options --------------------------------------------------
_PLLDIV_1_1L EQU H'F8' ; No prescale (4 MHz oscillator input drives PLL directly)
_PLLDIV_2_1L EQU H'F9' ; Divide by 2 (8 MHz oscillator input)
_PLLDIV_3_1L EQU H'FA' ; Divide by 3 (12 MHz oscillator input)
_PLLDIV_4_1L EQU H'FB' ; Divide by 4 (16 MHz oscillator input)
_PLLDIV_5_1L EQU H'FC' ; Divide by 5 (20 MHz oscillator input)
_PLLDIV_6_1L EQU H'FD' ; Divide by 6 (24 MHz oscillator input)
_PLLDIV_10_1L EQU H'FE' ; Divide by 10 (40 MHz oscillator input)
_PLLDIV_12_1L EQU H'FF' ; Divide by 12 (48 MHz oscillator input)

_CPUDIV_OSC1_PLL2_1L EQU H'E7' ; [OSC1/OSC2 Src: /1][96 MHz PLL Src: /2]
_CPUDIV_OSC2_PLL3_1L EQU H'EF' ; [OSC1/OSC2 Src: /2][96 MHz PLL Src: /3]
_CPUDIV_OSC3_PLL4_1L EQU H'F7' ; [OSC1/OSC2 Src: /3][96 MHz PLL Src: /4]
_CPUDIV_OSC4_PLL6_1L EQU H'FF' ; [OSC1/OSC2 Src: /4][96 MHz PLL Src: /6]

_USBDIV_1_1L EQU H'DF' ; USB clock source comes directly from the primary oscillator block with no postscale
_USBDIV_2_1L EQU H'FF' ; USB clock source comes from the 96 MHz PLL divided by 2

;----- CONFIG1H Options --------------------------------------------------
_FOSC_XT_XT_1H EQU H'F0' ; XT oscillator, XT used by USB
_FOSC_XTPLL_XT_1H EQU H'F2' ; XT oscillator, PLL enabled, XT used by USB
_FOSC_ECIO_EC_1H EQU H'F4' ; External clock, port function on RA6, EC used by USB
_FOSC_EC_EC_1H EQU H'F5' ; External clock, CLKOUT on RA6, EC used by USB
_FOSC_ECPLLIO_EC_1H EQU H'F6' ; External clock, PLL enabled, port function on RA6, EC used by USB
_FOSC_ECPLL_EC_1H EQU H'F7' ; External clock, PLL enabled, CLKOUT on RA6, EC used by USB
_FOSC_INTOSCIO_EC_1H EQU H'F8' ; Internal oscillator, port function on RA6, EC used by USB
_FOSC_INTOSC_EC_1H EQU H'F9' ; Internal oscillator, CLKOUT on RA6, EC used by USB
_FOSC_INTOSC_XT_1H EQU H'FA' ; Internal oscillator, XT used by USB
_FOSC_INTOSC_HS_1H EQU H'FB' ; Internal oscillator, HS used by USB
_FOSC_HS_1H EQU H'FC' ; HS oscillator, HS used by USB
_FOSC_HSPLL_HS_1H EQU H'FE' ; HS oscillator, PLL enabled, HS used by USB

_FCMEN_OFF_1H EQU H'BF' ; Fail-Safe Clock Monitor disabled
_FCMEN_ON_1H EQU H'FF' ; Fail-Safe Clock Monitor enabled

_IESO_OFF_1H EQU H'7F' ; Oscillator Switchover mode disabled
_IESO_ON_1H EQU H'FF' ; Oscillator Switchover mode enabled

;----- CONFIG2L Options --------------------------------------------------
_PWRT_ON_2L EQU H'FE' ; PWRT enabled
_PWRT_OFF_2L EQU H'FF' ; PWRT disabled

_BOR_OFF_2L EQU H'F9' ; Brown-out Reset disabled in hardware and software
_BOR_SOFT_2L EQU H'FB' ; Brown-out Reset enabled and controlled by software (SBOREN is enabled)
_BOR_ON_ACTIVE_2L EQU H'FD' ; Brown-out Reset enabled in hardware only and disabled in Sleep mode (SBOREN is disabled)
_BOR_ON_2L EQU H'FF' ; Brown-out Reset enabled in hardware only (SBOREN is disabled)

_BORV_0_2L EQU H'E7' ; Maximum setting
_BORV_1_2L EQU H'EF' ;
_BORV_2_2L EQU H'F7' ;
_BORV_3_2L EQU H'FF' ; Minimum setting

_VREGEN_OFF_2L EQU H'DF' ; USB voltage regulator disabled
_VREGEN_ON_2L EQU H'FF' ; USB voltage regulator enabled

;----- CONFIG2H Options --------------------------------------------------
_WDT_OFF_2H EQU H'FE' ; HW Disabled - SW Controlled
_WDT_ON_2H EQU H'FF' ; HW Enabled - SW Disabled

_WDTPS_1_2H EQU H'E1' ; 1:1
_WDTPS_2_2H EQU H'E3' ; 1:2
_WDTPS_4_2H EQU H'E5' ; 1:4
_WDTPS_8_2H EQU H'E7' ; 1:8
_WDTPS_16_2H EQU H'E9' ; 1:16
_WDTPS_32_2H EQU H'EB' ; 1:32
_WDTPS_64_2H EQU H'ED' ; 1:64
_WDTPS_128_2H EQU H'EF' ; 1:128
_WDTPS_256_2H EQU H'F1' ; 1:256
_WDTPS_512_2H EQU H'F3' ; 1:512
_WDTPS_1024_2H EQU H'F5' ; 1:1024
_WDTPS_2048_2H EQU H'F7' ; 1:2048
_WDTPS_4096_2H EQU H'F9' ; 1:4096
_WDTPS_8192_2H EQU H'FB' ; 1:8192
_WDTPS_16384_2H EQU H'FD' ; 1:16384
_WDTPS_32768_2H EQU H'FF' ; 1:32768



This is just a portion of all the configuration options, you'll have to open it up to see them all. Note that this chip has multiple config registers, so be sure to match up the desired setting with the proper register. The tedious part will be looking up what each of these mean in the datasheet if you don't already know. Off the bat, in register CONFIG2H I know WDT is watchdog timer and for most programs, I turn it off, but you may want it. I usually copy the config settings I don't recognize and perform a find (CTRL + F) in the datasheet. This may not always work as the abbriviations in the .INC file may not be in the datasheet, but a little searching and you'll find it. Hope this helps.

-Tony

Fredrick
- 21st January 2009, 22:35
Thank you very much Tony.

That helped alot, now SERIN and SEROUT are working.

Now i trying to figure out how to make RA5 to digital input/output.

mister_e
- 21st January 2009, 22:40
Look in the Analog to digital section... maybe in the comparator section (if there's any)

Fredrick
- 21st January 2009, 23:02
Yepp i find it


ADCON1 = %000001111

sets all AN pins to Digital I/O.

See "REGISTER 21-2: ADCON1: A/D CONTROL REGISTER 1" in the datasheet for 18F2550

Thank you...

chrisshortys
- 7th January 2012, 16:26
Sorry to drag up an old thread but i am struggling to get my head around these registers. I am moving over from using a 16F876A chip and at the moment i cant get the LCD to operate correctly. The characters are displaying but every few cycles they seem to get confused with some noise and random characters appear. Could this be anything to do with having not set the oscillator in the code for my external 4Mhz (I looked for this code but couldn't see any need for it)?

Thanks for any help!




'BO = LCD INTERFACE'B1 = LCD INTERFACE
'B2 = LCD INTERFACE
'B3 = LCD INTERFACE
'B4 = LCD INTERFACE
'B5 = LCD INTERFACE
'B6 = LCD INTERFACE
'B7 = LCD INTERFACE
'
'C0 = SERVO 1
'C1 = SERVO 2
'C2 =
'C3 =
'C4 =
'C5 =
'C6 =
'C7 =




'************************************************* **********************
'****************** DEFINE ADCIN PARAMETERS*****************************
'************************************************* **********************
pause 1000




asm
__CONFIG _CONFIG1L, _PLLDIV_5_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
__CONFIG _CONFIG1H, _FOSC_HSPLL_HS_1H
__CONFIG _CONFIG2H, _WDT_OFF_2H & _WDTPS_512_2H
__CONFIG _CONFIG3H, _PBADEN_OFF_3H
__CONFIG _CONFIG4L, _LVP_OFF_4L & _XINST_OFF_4L & 0DFh
endasm




DEFINE LCD_DREG PORTB 'Define PIC port used for LCD Data lines
DEFINE LCD_DBIT 4 'Define first pin of portb connected to LCD DB4
DEFINE LCD_RSREG PORTB 'Define PIC port used for RS line of LCD
DEFINE LCD_RSBIT 3 'Define Portb pin used for RS connection
DEFINE LCD_EREG PORTB 'Define PIC prot used for E line of LCD
DEFINE LCD_EBIT 0 'Define PortB pin used for E connection
DEFINE LCD_BITS 4 'Define the 4 bit communication mode to LCD
DEFINE LCD_LINES 2 'Define using a 2 line LCD
DEFINE LCD_COMMANDUS 2000 'Define delay between sending LCD commands
DEFINE LCD_DATAUS 50 'Define delay time between data sent.




main:
LCDOUT $FE, 1
pause 10
LCDOUT $FE, 2
pause 10
LCDOUT "3 axis track V1"
pause 5000




goto main




END

Demon
- 8th January 2012, 02:15
I'd try this:

DEFINE OSC 4

Robert

EDIT: This chip (like probably most PICs), has built-in oscillator. Any reason why you don't want to use that?

And double-check the configuration fuses for the oscillator.

chrisshortys
- 9th January 2012, 20:06
Thanks, I shall try that when I am at home tomorrow evening!
Only the fact that I was always shown circuits with external ones! Are there many benifits to using the internal ones?
With the fuses what kind of thing am I looking for or do you know of a beginners guide, as I haven't really dealt with those bits yet!

Thanks!

Demon
- 10th January 2012, 03:45
...Are there many benifits to using the internal ones?...

Fewer parts, lower cost, less chance of solder problems, less space required on PCB, saving the planet, the list goes on. :D I've been using external oscillatorsmainly 'cause I bought a bag and enough capacitors, but that might change with USB.



..
With the fuses what kind of thing am I looking for or do you know of a beginners guide, as I haven't really dealt with those bits yet!

Thanks!


The datasheet is your friend:
http://ww1.microchip.com/downloads/en/DeviceDoc/39632e.pdf

Page 32, section 2-3:

When these devices are used for USB connectivity,
they must have either a 6 MHz or 48 MHz clock for
USB operation, depending on whether Low-Speed or
Full-Speed mode is being used. This may require some
forethought in selecting an oscillator frequency and
programming the device.
The full range of possible oscillator configurations
compatible with USB operation is shown in Table 2-3.


I just pulled out a 18F4550 about 10 minutes ago to get back into USB programming. We share the same datasheet, but I can't comment on config yet, I have to search the forum for examples first. (Here's an interesting thread to start with)
http://www.picbasic.co.uk/forum/showthread.php?t=5806&highlight=18f4550+config

Robert
:)


EDIT: But then it says this under the table:


Legend: All clock frequencies, except 24 MHz, are exclusively associated with full-speed USB operation (USB clock of 48 MHz).
Bold is used to highlight clock selections that are compatible with low-speed USB operation (system clock of 24 MHz,
USB clock of 6 MHz).

Since several of my PCs don't have USB 2.0, I'll be targetting low speed.

Oh yes, don't forget that new PCs have USB 3.0, you'll have to look at an expert here to know how to handle that.

chrisshortys
- 13th January 2012, 17:41
I'd try this:

DEFINE OSC 4

Robert

EDIT: This chip (like probably most PICs), has built-in oscillator. Any reason why you don't want to use that?

And double-check the configuration fuses for the oscillator.


Hi demon, I haven't had a chance to gt on the pc to try this yet but what would be the difference between using:

DEFINE OSC 4

And



Code:
@ __CONFIG _CONFIG1L, _PLLDIV_1_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
@ __CONFIG _CONFIG1H, _FOSC_HSPLL_HS_1H



Is the define a pbp level code and the config I'm guessing in asm level?


I'm not looking at USB yet but I may well try it in future projects!

I had a look at the data sheet before posting but got very confused and gave in to google which didn't help much either :p

I think I may well look to moving to onboard especially if USB will drive off this too!

Thanks again!

Demon
- 13th January 2012, 19:47
I'm on cellphone, so sorry for short reply...

Datasheet says USB requires external oscillator.

Tobias
- 15th January 2012, 06:34
On the internal vs external OSC deal

I got this from Bruce Reynolds

If you have a board that will be subject to extreme heat, external will remain constant while internal may vary.

My opinion is for the cost (minimal), space required on the board (minimal) and chances of solder joint(s) being bad (minimal) I always throw an external on the board.