CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

write_configuration_memory [RESOLVED]

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
bkamen



Joined: 07 Jan 2004
Posts: 1611
Location: Central Illinois, USA

View user's profile Send private message

write_configuration_memory [RESOLVED]
PostPosted: Wed Jun 30, 2010 1:39 pm     Reply with quote

Hey guys,

I'm on 4.109 and sent this into CCS as I don't think write_configuration_memory is working for the PIC18F46J11

Here's my code -- I'm simply trying to change the Fosc bits from HS to HS+PLL (H4_SW) in software.

The initial read shows me registers that match up with MPLAB's config bits window... so the code should write out the new values... and then on reset -- nothing has happened.

Am I forgetting/missing something?

Code:
#include <18F46J11.h>

#use delay(clock=10M, crystal=10M)
#fuses HS
#fuses NOWDT,NODEBUG,NOIESO,WDT32768,NODSWDT
#fuses NOFCMEN
#fuses LPT1OSC, NOT1DIG, RTCOSC_T1

#opt 10

#use rs232 (UART1, STREAM=COMM, BAUD=57600, PARITY=N, BITS=8, ERRORS)

#define CONFIG_LEN 8

// =============================================================================

void main() {
   unsigned int buffer[CONFIG_LEN];
   unsigned int i, x, reload=0;

   setup_wdt(WDT_OFF);
   delay_ms(250);

   read_configuration_memory(&buffer, CONFIG_LEN);

   fprintf(COMM, "\r\n\r\n");

   for (i=0; i<CONFIG_LEN; i++) {
      fprintf(COMM, "%04X (%02u): %02X", 0xFFF8+i, i, buffer[i]);

      if (i==0x2 && ((buffer[i] & 0x7) != 5) ) {
         fprintf(COMM, "!");
         reload = 1;
      }
      fprintf(COMM, "\r\n");
   }


   if (!reload) {
      fprintf(COMM, "The Config is correct. Nothing to be done.\r\n");
   } else {
      x = CONFIG_LEN;
      fprintf(COMM, "Fosc is the wrong value. Reprogramming\r\n");
      buffer[0x2] = 0x15;
      write_configuration_memory(buffer, x);
   }

   fprintf(COMM, "Hit any key to reset\r\n");
   // MAIN LOOP
   while (TRUE) {
      if (kbhit(COMM))
         reset_cpu();
   }
}

_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D


Last edited by bkamen on Wed Jul 07, 2010 3:18 pm; edited 1 time in total
andy5056



Joined: 22 Nov 2009
Posts: 5
Location: Thomasboro, IL

View user's profile Send private message

PostPosted: Thu Jul 01, 2010 11:16 am     Reply with quote

Did you consider setting the PLLEN bit in OSCTUNE rather than rewriting the configuration bits?

Andrew
bkamen



Joined: 07 Jan 2004
Posts: 1611
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Thu Jul 01, 2010 1:11 pm     Reply with quote

That's what my new code does...

But it appears that if the PLL bit isn't set in the CONFIG, toggling PLLEN doesn't do anything while the Fosc fuses are HS and not H4_SW.

So I'm trying to add to my code where it check to see if the Fosc bits are what it needs and changes the CONFIG appropriately.

CCS is looking into it too since the write_configuration_memory plainly doesn't seem to be working anyway.

I figured I'd ask here if anyone had the same problem.

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
andy5056



Joined: 22 Nov 2009
Posts: 5
Location: Thomasboro, IL

View user's profile Send private message

PostPosted: Sat Jul 03, 2010 1:09 pm     Reply with quote

If you use #fuses H4_SW instead of HS, does the PIC come up running at the 4x clock rate?

I do not have a 46J11, but I am currently using a 67J11 which also has the 4x PLL. If I set fuse H4_SW, the OSCTUNE PLLEN bit is cleared at the beginning of Main. I compiled your code for the 46j11, and the list file does not show any write to OSCTUNE (0xf9b) which makes me wonder if the PLL is, in fact, enabled simply by #fuses H4_SW. Is a separate write to PLLEN required to enable the PLL?

If you want to be sure that the PLL is disabled at the beginning of Main, would something like this work:
Code:

#fuses H4_SW
#define PLL_OFF #asm BCF 0xF9B.6 #endasm
#define PLL_ON #asm BSF 0xF9B.6 #endasm

void main() {
   unsigned int (etc..)

// slow the clock to 1x
//
   PLL_OFF;  // clear PLLEN

  (startup code running 1x clock)

// enable 4x PL
//
   PLL_ON;  // set PLLEN
 
  (code now running at 4x clock)
}

Andrew
bkamen



Joined: 07 Jan 2004
Posts: 1611
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Sat Jul 03, 2010 8:52 pm     Reply with quote

andy5056 wrote:
If you use #fuses H4_SW instead of HS, does the PIC come up running at the 4x clock rate?

I do not have a 46J11, but I am currently using a 67J11 which also has the 4x PLL. If I set fuse H4_SW, the OSCTUNE PLLEN bit is cleared at the beginning of Main. I compiled your code for the 46j11, and the list file does not show any write to OSCTUNE (0xf9b) which makes me wonder if the PLL is, in fact, enabled simply by #fuses H4_SW. Is a separate write to PLLEN required to enable the PLL?


In the cases where I usually use the #use delay with the separate crystal/clock statements, that's usually taken care of.

In this case, I'm not so far as the switching PLLEN ON/OFF.

I can't get write_configuration_memory to actually change the config Fosc bits from 4 (b100) to 5 (b101) like the function is supposed to.

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
bkamen



Joined: 07 Jan 2004
Posts: 1611
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Wed Jul 07, 2010 3:20 pm     Reply with quote

It turns out that this function doesn't work on the 18FxxJ11 series because the config is held in the top bytes of program memory while write_configuration_memory attempts to write to 0x300000 -- which doesn't work.

So the function will be disabled in future versions until it's fixed.

The way it must be done (that I started originally) is to read the block, modify the bits and then write them back.

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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 vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group