Jump to content
cac001

Pic18f46j50 #pragma Config Does Not Work

Recommended Posts

Bug description:

The #pragma config for the PIC18F46J50 fails to set the configuration bits correctly.

 

Steps to reproduce:

Use this configuration:

#pragma config XINST = OFF

#pragma config STVREN = OFF

#pragma config PLLDIV = 2

#pragma config WDTEN = OFF

#pragma config CP0 = OFF

#pragma config CPUDIV = OSC2_PLL2

#pragma config IESO = OFF

#pragma config FCMEN = OFF

#pragma config LPT1OSC = ON

#pragma config T1DIG = OFF

#pragma config FOSC = INTIO67

#pragma config WDTPS = 32768

#pragma config DSWDTPS = G2

#pragma config DSWDTEN = OFF

#pragma config DSBOREN = OFF

#pragma config RTCOSC = T1OSCREF

#pragma config DSWDTOSC = INTOSCREF

/* #pragma config MSSP7B_EN = MSK7 ** this pragma config does not work at all **/

#pragma config IOL1WAY = OFF

#pragma config WPCFG = OFF

#pragma config WPEND = PAGE_WPFP

#pragma config WPFP = PAGE_63

#pragma config WPDIS = OFF

 

Load the HEX file with MPLAB observer that:

PLLDIV is not set correctly

CPUDIV is not set correctly

DSWDTOSC is not set correctly

WPFP is not set correctly

WPEND is not set correctly

 

 

The problem 100% reproduceable.

 

IDE version: SouceBoost IDE 6.97RC3

Compiler: BoostC

Compiler version: BoostC Optimizing C Compiler Version 6.97 (for PIC18 architecture)

Target device: PIC18F46J50

OS: WinXPsp3

Share this post


Link to post
Share on other sites

The .tdf file sets the config address at 0x0000FFF8 and not 0x00300001 as expected.

 

Perhaps this device has a new feature that I have not seen before.

 

Cheers

 

Reynard

Share this post


Link to post
Share on other sites
The .tdf file sets the config address at 0x0000FFF8 and not 0x00300001 as expected.

 

Perhaps this device has a new feature that I have not seen before.

 

Cheers

 

Reynard

Reynard,

 

This family of devices seems to be different from other 18Fs in that the last four words of flash memory are used to store the config data which is then copied into the 'normal' config locations on power up or reset. These 'normal' locations are now volatile.

 

It seems that the last four flash words must be reserved to prevent them being overwritten by the program. Presumably SourceBoost deals with this. See section 26.1.1 of the device datasheet for more info.

 

Regards

 

davidb

Share this post


Link to post
Share on other sites

Hi David,

 

Thanks for the heads-up on this one.

 

I will have to try and remember this should I have a need for these devices.

 

Cheers

 

Reynard

Share this post


Link to post
Share on other sites
Bug description:

The #pragma config for the PIC18F46J50 fails to set the configuration bits correctly.

 

Steps to reproduce:

Use this configuration:

#pragma config XINST = OFF

#pragma config STVREN = OFF

#pragma config PLLDIV = 2

#pragma config WDTEN = OFF

#pragma config CP0 = OFF

#pragma config CPUDIV = OSC2_PLL2

#pragma config IESO = OFF

#pragma config FCMEN = OFF

#pragma config LPT1OSC = ON

#pragma config T1DIG = OFF

#pragma config FOSC = INTIO67

#pragma config WDTPS = 32768

#pragma config DSWDTPS = G2

#pragma config DSWDTEN = OFF

#pragma config DSBOREN = OFF

#pragma config RTCOSC = T1OSCREF

#pragma config DSWDTOSC = INTOSCREF

/* #pragma config MSSP7B_EN = MSK7 ** this pragma config does not work at all **/

#pragma config IOL1WAY = OFF

#pragma config WPCFG = OFF

#pragma config WPEND = PAGE_WPFP

#pragma config WPFP = PAGE_63

#pragma config WPDIS = OFF

 

Load the HEX file with MPLAB observer that:

PLLDIV is not set correctly

CPUDIV is not set correctly

DSWDTOSC is not set correctly

WPFP is not set correctly

WPEND is not set correctly

 

 

The problem 100% reproduceable.

 

IDE version: SouceBoost IDE 6.97RC3

Compiler: BoostC

Compiler version: BoostC Optimizing C Compiler Version 6.97 (for PIC18 architecture)

Target device: PIC18F46J50

OS: WinXPsp3

You can check the configuration option bit masks and data in the devices .tdf file (look for targetconfig). Pleas take a look there.

 

Regards

Dave

Share this post


Link to post
Share on other sites
You can check the configuration option bit masks and data in the devices .tdf file (look for targetconfig). Pleas take a look there.

 

Dave,

 

I looked at the \SourceBoost\config\PIC18F46J50.tdf file and it does have issues.

This is at the end of the file

TargetConfig FOSC
{
// Oscillator Selection bits:
ConfigRegAddr = 0x0000FFF8;
ConfigBitMask = 0b00001111;
ConfigSettings =
	0b00000000, "LP","LP oscillator",
	0b00000001, "XT","XT oscillator",
	0b00000010, "HS","HS oscillator",
	0b00000011, "RC","External RC oscillator, CLKOUT function on RA6",
	0b00000100, "EC","EC oscillator, CLKOUT function on RA6",
	0b00000101, "ECIO6","EC oscillator, port function on RA6",
	0b00000110, "HSPLL","HS oscillator, PLL enabled (Clock Frequency = 4 x FOSC1)",
	0b00000111, "RCIO6","External RC oscillator, port function on RA6",
	0b00001000, "INTIO67","Internal oscillator block, port function on RA6 and RA7",
	0b00001001, "INTIO7","Internal oscillator block, CLKOUT function on RA6, port function on RA7";
}

This is just wrong. It's likely wrong in all of the PIC18F parts that use this new method of addressing the configuration bits.

 

I checked the rest of the configuration word addresses and bit positions and they seem correct but the cinfiguration words generated by the compiler and linker are still wrong.

 

Your implementation of the Microchip "#pragma config" is bad. It does not work and fixing the .tdf file does not help.

 

This is a bug.

 

This code works in C18:

/*
Author: Charles Ader
Date: 2010-APRIL-28
File: main.c 
Target: PIC18F46J50
OS: WinXP, SP2
MPLAB 8.50
Compiler: C18 v3.35

*/

#include <p18Cxxx.h>

#pragma config XINST = OFF
#pragma config STVREN = OFF
#pragma config PLLDIV = 2
#pragma config WDTEN = OFF
#pragma config CP0 = OFF
#pragma config CPUDIV = OSC2_PLL2
#pragma config IESO = OFF
#pragma config FCMEN = OFF
#pragma config LPT1OSC = ON
#pragma config T1DIG = OFF
#pragma config OSC = INTOSCPLL
#pragma config WDTPS = 32768
#pragma config DSWDTPS = G2
#pragma config DSWDTEN = OFF
#pragma config DSBOREN = OFF
#pragma config RTCOSC = T1OSCREF
#pragma config DSWDTOSC = INTOSCREF
#pragma config MSSP7B_EN = MSK7
#pragma config IOL1WAY = OFF
#pragma config WPCFG = OFF
#pragma config WPEND = PAGE_WPFP
#pragma config WPFP = PAGE_63
#pragma config WPDIS = OFF

void
main( 
void 
)
{
/* wait here forever */
for(;; );
}

 

This code fails with BoostC:

/*
Author: Charles Ader
Date: 2010-APRIL-28
File: main.c 
Target: PIC18F46J50
OS: WinXP, SP2
SouceBoost IDE 6.97RC3
Compiler: BoostC Optimizing C Compiler Version 6.97 (for PIC18 architecture)

*/

#include <system.h>

#pragma config XINST = OFF
#pragma config STVREN = OFF
#pragma config PLLDIV = 2
#pragma config WDTEN = OFF
#pragma config CP0 = OFF
#pragma config CPUDIV = OSC2_PLL2
#pragma config IESO = OFF
#pragma config FCMEN = OFF
#pragma config LPT1OSC = ON
#pragma config T1DIG = OFF
#pragma config OSC = INTOSCPLL
#pragma config WDTPS = 32768
#pragma config DSWDTPS = G2
#pragma config DSWDTEN = OFF
#pragma config DSBOREN = OFF
#pragma config RTCOSC = T1OSCREF
#pragma config DSWDTOSC = INTOSCREF
/* #pragma config MSSP7B_EN = MSK7  ** this pragma config does not work **/
#pragma config IOL1WAY = OFF
#pragma config WPCFG = OFF
#pragma config WPEND = PAGE_WPFP
#pragma config WPFP = PAGE_63
#pragma config WPDIS = OFF


void
main( 
void 
)
{
/* wait here forever */
for(;; );
}

Share this post


Link to post
Share on other sites
...This is just wrong. It's likely wrong in all of the PIC18F parts that use this new method of addressing the configuration bits...

 

You must be using an old RC. All of them except the very last one had this functionality broken. The one that is on the www.sourceboost.com right now does seem to handle all configs from your code correctly (including MSSP7B_EN that you marked as not working). Attached is the picture of what MPLAB showed me. Try to download latest 6.97 RC and use it to build your code.

 

Reagrds,

Pavel

post-424-1272522857_thumb.png

Share this post


Link to post
Share on other sites
Try to download latest 6.97 RC and use it to build your code.

That fixed it.

Thanks.

 

A follow on question:

 

How do you get the external clock for TIMER0 to work in the simulator for the PIC18F46J50?

 

Charles.

Share this post


Link to post
Share on other sites
Try to download latest 6.97 RC and use it to build your code.

That fixed it.

Thanks.

 

A follow on question:

 

How do you get the external clock for TIMER0 to work in the simulator for the PIC18F46J50?

 

Charles.

Looks like there has been more than one version of RC3 posted on the site!

 

The config failed as above when I tried it this morning with a previously downloaded RC3.

 

After downloading what I thought should be the same version (RC3) it now works!

 

Regards

 

davidb

Edited by davidb

Share this post


Link to post
Share on other sites
How do you get the external clock for TIMER0 to work in the simulator for the PIC18F46J50?

 

Dave will answer this. He is traveling now and I'm not sure when he's able to access the forum.

 

Regards,

Pavel

Share this post


Link to post
Share on other sites

cac001,

How do you get the external clock for TIMER0 to work in the simulator for the PIC18F46J50?
It won't work on this device because it uses input mapping, which means some of the peripheral device pin mapping can be changed at runtime.

Here is a hack to allow timer 0 external clock function to work on a fixed pin:

1) Open the devices .TDF file.

2) Search to desired port and pin.

3) Add the additional pin name T0CKI to the PinNames string, eg:

Configure PORTB
{
// create
PinNames = "RB0|AN12|INT0|RP3|T0CKI","RB1|AN10|PMBE|RTCC|RP4", .....
}

 

I hope that helps.

 

Regards

Dave

Share this post


Link to post
Share on other sites

I tried what you suggested but I cannot get TIMER0 to count from and external input.

 

The next thing I tried was to use a PIC18F4550 as the target and RA4 as the T0CKI input.

 

I connected a button plugin to RA4 and toggled it on and off but never saw TIMER0 count.

 

Maybe I do not know how to get the simulator to see a change on T0CKI.

 

There does not seem to be much in the way of details on how to use the simulator in the SourceBoost IDE documentation.

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...