SEARCH
TOOLBOX
LANGUAGES
Register    Login    Forum    Search    FAQ

Board index » Electronics Projects » General Project Questions




Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: Configuration Bits & the Compiler
 Post Posted: Mon Oct 25, 2010 11:21 pm 
Offline

Joined: Thu Oct 21, 2010 9:08 pm
Posts: 1
I'm not trying to make anything work specifically. That is, I'm not troubleshooting an issue, but I would like to learn how something is working. Here goes:

I've got a general question about the following line of code (inside main.c):

__CONFIG(1, USBPLL & IESODIS & FCMDIS & HSPLL & CPUDIV1 & PLLDIV5);

I'm curious to know where the parameters USBPLL, IESODIS, etc. are defined in the "PIC18F Generic HID Device" project.

Within the project IDE I checked the file pane for any file (besides main.c) containing (and defining) USBPLL, IESODIS, etc., but I was unable to find such a file.

The file pane I speak of is inside the MPLAB IDE, usually to the left, has the title "PIC18F Generic HID Device.mcw," and shows a file tree with all the *.c, *.h (and often *.inc) files, the source files.

Next, I thought that the compiler, MPLAB, must be using another directory not listed in the source file pane, or my project directory, and in that directory there's a file that defines USBPLL, IESODIS, etc.

I was able to find such a directory and I did find a file in use by the compiler located here:

C:\Microchip Starter Kits\PIC18F Starter Kit 1\MPLAB C18\h\p18f4550.h

I verified that p18f4550.h was in use by temporarily renaming this file, pressing F10 to compile, and observing that when the file was renamed compile errors resulted.

I thought I was done! However, upon looking inside p18f4550.h I did not see a definitions for USBPLL, IESODIS, etc.

I searched more, finding another similarly named file called pic18f4550.h.

Located in: C:\Program Files\HI-TECH Software\PICC-18\PRO\9.63\include

This time I did see definitions for USBPLL, IESODIS, etc., but when I tested to see if this file was in use by renaming and then compiling I found no errors at compile time.

Where else could USBPLL, IESODIS, etc., be defined?

I checked my environment variable and I see that it points here:

MCC_INCLUDE pointing to "C:\Microchip Starter Kits\PIC18F Starter Kit 1\MPLAB C18\h"

but this directory is where I found p18f4550.h (not pic18f4550.h).

Inside MPLAB's IDE (Project-->Build Options...-->project) I did not see any explicit directories, just that my driver (PRO for the PIC18 MCU Family (Lite) V9.63PL2) is set up (High-Tech C).

I had a look through the following documents, but maybe I've missed something. At first I thought I found my answer in the "The Pic 18 Configuration Settings Addendum" since this has many configuration acronyms specific to the PIC18F4550 (as well as many other chips), however I didn't find, precisely, these: USBPLL, IESODIS, PLLDIV5, etc.

Anyway, I would be interested to know how USBPLL, IESODIS, PLLDIV5, and etc. are defined exactly.

My goal is to discover, exactly, how my compiler knows what USBPLL, IESODIS, PLLDIV5, and etc. are and I would expect to find a file with lines shown below in it (and an obvious dependency - i.e. if you delete the file you get compile errors) :

#define USBPLL 0xFFFF // clk src from 96MHz PLL/2
#define USBOSC 0xFFDF // clk src from OSC1/OSC2
#define CPUDIV4 0xFFFF // div by 4
#define CPUDIV3 0xFFF7 // div by 3
#define CPUDIV2 0xFFEF // div by 2
#define CPUDIV1 0xFFE7 // no divide

Thanks!

[1] PIC18F2455/2550/4455/4550 Data Sheet
[2] MPLAB® C18 C COMPILER LIBRARIES
[3] MPLAB® C18 C COMPILER GETTING STARTED
[4] PIC 18 CONFIGURATION SETTINGS ADDENDUM


Top 
 Profile  
 
 Post subject: Re: Configuration Bits & the Compiler
 Post Posted: Tue Oct 26, 2010 6:21 am 
Offline

Joined: Thu Apr 01, 2010 6:23 am
Posts: 1051
For the HiTech C compiler used in my projects the line you are looking for is:

#include <htc.h>

which is included by every .c file. This header automatically includes the correct definitions for your currently selected device (PIC18F4550 for example).

The actual definitions are supplied by 2 files located (on my machine) under:

C:\Program Files (x86)\HI-TECH Software\PICC-18\PRO\9.63\include

For the 4550 the files are 18f4550.h and pic18f4550.h

Since the compiler takes care of including and linking the right headers you do not need to include them in your 'project view' they are included by default when you link. It can be useful to look in the pic18f4550.h file though, especially when you can't remember the right abbreviation (and they are not always named the same as the datasheet - which is a little confusing) :)

Hope this helps!


Top 
 Profile  
 
 Post subject: Re: Configuration Bits & the Compiler
 Post Posted: Wed Oct 26, 2011 6:39 pm 
Offline

Joined: Wed Oct 26, 2011 6:21 pm
Posts: 4
Hi,

I found that, in the Hi-tech version I'm using (9,66), USBPLL an the other parameters are defined in the file:

C:\Program Files\HI-TECH Software\PICC-18\PRO\9.66\include\legacy\ppic18f4550.h

the definition looks like this:

#define USBPLL 0xFFDF // clk src from 96MHz PLL/2

this is the one is using, since if you comment the line, it gives an error..


Top 
 Profile  
 
 Post subject: Re: Configuration Bits & the Compiler
 Post Posted: Wed Oct 26, 2011 10:20 pm 
Offline

Joined: Thu Apr 01, 2010 6:23 am
Posts: 1051
To better understand the configuration bits I suggest you take another look at the datasheet. The details are a little buried though :)

If you look in the section called 'Special Features of the CPU' (specifically section 25.1) there are a lot of details of what the configuration bits are. You can then track this information back through the header files included by the IDE at compile time.


Top 
 Profile  
 
 Post subject: Re: Configuration Bits & the Compiler
 Post Posted: Thu Oct 27, 2011 1:12 pm 
Offline

Joined: Wed Oct 26, 2011 6:21 pm
Posts: 4
Thanks Simon ;)


but, taking a closer look into it:

as usbpll is defined 0xffdf it means, in binary: 1111 1111 1101 1111.

that means, as we use the "&" operator with the other parameters like IESODIS, etc..

that bit 5, in the registry CONFIG1L, will be "0".



now, if we take a look in the datasheet it says:


"bit 5 USBDIV: USB Clock Selection bit (used in Full-Speed USB mode only; UCFG:FSEN = 1)
1 = USB clock source comes from the 96 MHz PLL divided by 2
0 = USB clock source comes directly from the primary oscillator block with no postscale"

I thought the correct setting should be 1 for that bit!!!


not only for USBPLL, but for the others: HSPLL and PLLDIV5, happens the same.

it seems that should be:


USBPLL: 0xff2f

HSPLL: 0xfbff

PLLDIV5: 0xfff4



did I miss sth? Am i completely lost? :P


thank you!!


Top 
 Profile  
 
 Post subject: Re: Configuration Bits & the Compiler
 Post Posted: Thu Oct 27, 2011 2:22 pm 
Offline

Joined: Thu Apr 01, 2010 6:23 am
Posts: 1051
Well first of all we have to decide which compiler we are discussing; you seem to be using _CONFIG (Hi-Tech PICC18 format) but you are looking at the Microchip C18 includes...

(Edit: Sorry I just noticed you were not the OP and the OP's examples were C18 - yours are all HiTech)

The definition of the SFRs is not the same (only soon it will be since Hi-Tech is moving to Microchips format). As a side note I think they are removing the usage of header files for this an moving to a more centralised database style.

In any case, if you want USBDIV to be 'true' then you must set bit 5 of the CONFIG1L SFR (Special Function Register).

This is defined in the hitech headers as:

#define USBPLL 0xFFDF // clk src from 96MHz PLL/2

Which is a bit-mask for 1111 1111 1101 1111

Now, 'bitmask' is the important term here (since you can use a bitmask to change a particular bit in a binary representation). If you want it on in the config you do:

CONFIG1 = CONFIG1 AND 0xFFDF

and if you want it off you do:

CONFIG1 = CONFIG1 OR 0xFFDF

Now I'm not 100% sure I understood the question :) but perhaps the above is what you were after?

/Simon


Top 
 Profile  
 
 Post subject: Re: Configuration Bits & the Compiler
 Post Posted: Thu Oct 27, 2011 4:47 pm 
Offline

Joined: Wed Oct 26, 2011 6:21 pm
Posts: 4
Absolutely, that's what I was after thanks a lot Simon ;)


in this macro:

"
// PIC 18F4550 fuse configuration:
// Config word 1 (Oscillator configuration)
// 20Mhz crystal input scaled to 48Mhz and configured for USB operation
__CONFIG(1, USBPLL & IESODIS & FCMDIS & HSPLL & CPUDIV1 & PLLDIV5)"



as long as I know , the function of this macro is to set the config1 word, mapped starting at program memory 300000h.



now, as IESODIS, FCMDIS and CPUDIV1 are 0xffff( defined in ppic18f4550.h), they're inivisble to the operator "&".

the declaration of IESODIS is:

// Internal External Switch Over Mode
#define IESODIS 0xFFFF // Disabled

so, if we operate the resting 3 parameters the result will be:

1111 1111 1101 1111 --->usbpll
1111 0100 1111 1111 ---->hspll
1111 1111 1111 1011 ---->plldiv5

1111 0100 1101 1011 ------>the word CONFIG1 would be like this.


1111 0100---> config1h
1101 1011---> config1l




At that point, if we look at the datasheet,

- USBDIV, bit 5 of config1l , should be 1 for use 48mhz to the usb, and its 0
-IESO, bit 7 of config1h, should be 0 as in the declaration of IESODIS we disable it, and its 1(enabled)

- PLLDIV2:PLLDIV0, bits 2,1,0 of config1l ; should be "100" as the definition of PLLDIV5 is to divide by 5 ; and its "011"(divide by for)

- etc....



it seems that somewhere must be the operation

config1 = NOT config..






well , thanks for your time anyway!


Top 
 Profile  
 
 Post subject: Re: Configuration Bits & the Compiler
 Post Posted: Thu Oct 27, 2011 5:08 pm 
Offline

Joined: Thu Apr 01, 2010 6:23 am
Posts: 1051
A NOT operation in C is easy to miss:

invertedByte = ~Byte;

There's probably something like that in there

Anyway, glad you got somewhere with your questioning; it's always good to know how things really work :)


Top 
 Profile  
 
 Post subject: Re: Configuration Bits & the Compiler
 Post Posted: Mon Jul 16, 2012 7:05 am 
Offline

Joined: Sat Jul 14, 2012 7:00 pm
Posts: 7
This has been a very helpful thread...

I'm using MPLAB X with HiTech PIC18 ...

The project complies and runs, but generates underscores for the __Config statements, and also generates warnings..

../graph.c:40 warning: variable "RB1" is deprecated (declared at C:\Program Files\HI-TECH Software\PICC-18\9.80\include\pic18f4550.h:5156)

How can I change the code to fix these warnings... I've been reading and trying for a couple of days.


Top 
 Profile  
 
 Post subject: Re: Configuration Bits & the Compiler
 Post Posted: Mon Jul 16, 2012 2:20 pm 
Offline

Joined: Thu Apr 01, 2010 6:23 am
Posts: 1051
The reason for the error is that HiTech have changed the default headers and replaced them with new ones. This means the 'old' headers are now 'depreciated' and throw warnings on compilation.

Check google for LEGACY_HEADERS and the HiTech compiler for details of this and how to compile. There are also a number of threads on this forum on the subject.

/Simon


Top 
 Profile  
 
Display posts from previous:  Sort by  
 
Post new topic Reply to topic  [ 10 posts ] 

Board index » Electronics Projects » General Project Questions


Who is online

Users browsing this forum: No registered users and 1 guest

 
 

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Translated by Maël Soucaze © 2009 phpBB.fr