Invalid OSCCAL Value detected PICKIT3 PIC10F200

Thread Starter

RodneyB

Joined Apr 28, 2012
697
I have been trying to load code into my PIC10F200. I however keep getting the above error.
I am not sure what causes it or how to fix it. I have attached a screen shot of the problem.
I change the PIC10F200 and still had the problem
I have searched the Web unsuccessfully and tried the microchip forum and had no answers.

Any advice will be greatly appreciated

Thank you in advance
 

Attachments

JohnInTX

Joined Jun 26, 2012
4,787
Its hard to read your screen shot but usually this error occurs when your programmer clobbers the factory oscillator calibration. This calibration value is stored as a MOVLW xx instruction at 0xFF - the reset vector. On reset, this value will be loaded into W, the PC will roll over to 000h and your program is supposed to MOVWF OSCCAL to calibrate the oscillator.

The chip programmer must save this value then restore it when programming or you'll get an error - check its settings. A backup value is stored at 104h (in the config memory) that is not normally erased during programming. You can restore the factory value manually by poking MOVLW xx into program memory at 0FFh. See the 10F200 Programming Spec for more info.

Good luck
 

Thread Starter

RodneyB

Joined Apr 28, 2012
697
Its hard to read your screen shot but usually this error occurs when your programmer clobbers the factory oscillator calibration. This calibration value is stored as a MOVLW xx instruction at 0xFF - the reset vector. On reset, this value will be loaded into W, the PC will roll over to 000h and your program is supposed to MOVWF OSCCAL to calibrate the oscillator.

The chip programmer must save this value then restore it when programming or you'll get an error - check its settings. A backup value is stored at 104h (in the config memory) that is not normally erased during programming. You can restore the factory value manually by poking MOVLW xx into program memory at 0FFh. See the 10F200 Programming Spec for more info.

Good luck
Thanks very much, as a beginner what most of you have written I cant follow.

C:
#include <xc.h>

// PIC10F200 Configuration Bit Settings
#pragma config WDTE = OFF  // Watchdog Timer (WDT disabled)
#pragma config CP = OFF  // Code Protect (Code protection off)
#pragma config MCLRE = ON  // Master Clear Enable (GP3/MCLR pin function  is MCLR)
  // Because PIC10F200 doesn't have configurable POR or BOR,
  // I advise an external RC reset on /MCLR.


#define  _XTAL_FREQ  4000000  //4Mhz INTOSC
#define RUN_TIME  (60*1)
#define START_TIME  (30*1)

// Hardware Support

#define SW  GPIObits.GP0
#define LED1 sGPIObits.GP1
#define LED2 sGPIObits.GP2

  //  6543210
#define myTRIS 0b1001  // sets input output bits.

// Port Shadowing
volatile unsigned char sGPIO=0; // Port shadow register (global)
#define sGPIObits (*(GPIObits_t * volatile) &sGPIO)
#define updGPIO()  (GPIO = sGPIO)

// Time to Ticks scaling for Timer 0 half period
#define Time2Ticks(t) ((unsigned int)((t)*(float)_XTAL_FREQ/(4.0*256*128)))

unsigned int ticks;

void main (void) {

  GPIO = 0;
  OPTION = 0xC7; // /GPWO off, /GPPU off, T0CS internal, -, PSA TMR0, PS 1:256
  TRISGPIO = myTRIS;
 
  ticks = Time2Ticks(START_TIME);
 
while(1) { // loop forever
 
  //Handle timer
 
  if (TMR0&0x80){ //check the high bit
 
  TMR0&=0x7F; //clear it
 
  if(ticks) --ticks; //decrement tick count
  }
 
  //Handle Switch
 
  if(SW==1 && ticks==0){
 
  ticks =Time2Ticks(RUN_TIME);
  }
  //Handle LED 
 
  if(ticks) {
 
  LED1 =1;
 
  }
  else {
 
  LED1 = 0;
 
  }
 
  updGPIO();  // Actual update the GPIO port from the shadow register
  __delay_ms(10); //*MUST* maintain loop rate >30Hz to avoid missing Timer 0 half periods
  // Caution: using the compiler generated delays costs two bytes of RAM
}
}
I am not sure in this code where the OSCCAL is set
 
Last edited:

JohnInTX

Joined Jun 26, 2012
4,787
OK. Since you are programming in C, you don't have to worry about moving W to OSCCAL when starting, the C startup code does that for you.

You probably should:
Configure the PK3 to preserve memory locations 0xfe through 0xff when programming - I tried mine and it doesn't seem to preserve this important location automatically. Do it in MPLABX->project properties->PK3->Memory Ranges. Uncheck the 'Let Tool Decide Ranges' and tell it to preserve 0xFE-oxFF.
PICkit2 had an ability to recover the calibration value - I don't know if PK3 does.
If you use the IPE (Integrated Programming Environment) you can poke 0C00 into the last word of program memory after loading your hex file. Then set the ranges there to preserve 0xfe-0xff and it should work.

I don't use these much so that's about all I know about it. You can wait for someone else here or submit a ticket to Microchip Support and ask them how to restore / preserve the calibration value.

Good luck!
 

JohnInTX

Joined Jun 26, 2012
4,787
In MPLAB v8.9 I cant find project properties->PK3->Memory Ranges.
That's for MPLABX. Its always good to post what you are using..

For MPLAB 8.x, try Programmer->Select Programmer-> PICkit3 then:
Programmer->Settings
Select Allow PICkit3 to select memories and ranges then..
Check Preserve Program Memory Range and specify FE through FF.

That's a guess - I'm working on getting something out BUT, the last time I messed with the 10F I also clobbered the factory config for the oscillator. I'll shoot them a ticket and see what they say. Meanwhile, try this.

Build your project. DON'T check Preserve Program Memory Range in PK3 Settings in the programmer setup.
Click View->Program Memory. The last location (FF) should be Cxx. It probably won't be. Click the program memory location and enter C00 ( which is MOVLW 00 ; the default OSCCAL value). Program the chip. That will at least suppress the error and set the oscillator to some default value.
After that, try the Check Preserve Program Memory Range and specify FE through FF procedure to preserve the value.

When (If!) that works, the NEXT chip you program should be OK. I don't know if all of this will work but that's what I would do.

I don't know why all of this shouldn't be taken care of in default configurations but I will ask uCHIP and see. I played around with 10F awhile back and got the same problem but never resolved it.

Time to do that. Give it a try and see if you at least can suppress the error...

Have fun.

EDIT: I opened a ticket with uCHIP, we'll see what they say.
 
Last edited:

JohnInTX

Joined Jun 26, 2012
4,787
@RodneyB uCHIP says that a Microchip programmer will save/restore the value. Hmmm... I lost my cal values and only use uCHIP stuff. I'll drag some of it out in the next couple of days and see what's what.
 

JohnInTX

Joined Jun 26, 2012
4,787
@RodneyB
So.. its unclear how these things happen and uCHIP says that it shouldn't but I was able to restore my blown value and suppress the Invalid Calibration message like this:

10F200
MPLAB 8.63 (probably good for all 8.x).
PK3 selected as Programmer then:
Programmer->Reconnect - that should find your chip and complain about the Invalid Calibration.
Load your code if you want, its not necessary for this.

Then:
Programmer->Settings
On the Program Memory tab: ensure that Allow PICkit3 to select memories and ranges and Erase all before Program are checked.
On the Calibration Memory tab: Check the Allow PICkit3 to program calibration memory and enter 00 in the movlw box. Click OK.
Click Programmer->Program or the icon on the toolbar.
Click Programmer->Read or the icon on the toolbar to load the image.

Click View->Program Memory and click the Symbolic tab. Scroll to the bottom. At Address FF, you should see MOVLW 0x00. This is your restored calibration constant.
Be sure to visit Programmer->Settings and uncheck Allow PICkit3 to program calibration memory to avoid clobbering it again.

So far all this does is put something into the cal constant to suppress the error and set the oscillator to the center frequency. You'll have to check the timing and adjust the cal constant for now. Microchip says that none of their programmers will read the backup value.... Pic

Until you get a handle on what went wrong, I would suggest that you immediately read any new chips and log the cal value in case you have to restore it.

If I hear anything more on the ticket, I'll let you know.

Good luck.

BTW: PICkit2 with the standalone programming software has an auto-recover function for the calibration value..
 

Thread Starter

RodneyB

Joined Apr 28, 2012
697
@RodneyB
So.. its unclear how these things happen and uCHIP says that it shouldn't but I was able to restore my blown value and suppress the Invalid Calibration message like this:

10F200
MPLAB 8.63 (probably good for all 8.x).
PK3 selected as Programmer then:
Programmer->Reconnect - that should find your chip and complain about the Invalid Calibration.
Load your code if you want, its not necessary for this.

Then:
Programmer->Settings
On the Program Memory tab: ensure that Allow PICkit3 to select memories and ranges and Erase all before Program are checked.
On the Calibration Memory tab: Check the Allow PICkit3 to program calibration memory and enter 00 in the movlw box. Click OK.
Click Programmer->Program or the icon on the toolbar.
Click Programmer->Read or the icon on the toolbar to load the image.

Click View->Program Memory and click the Symbolic tab. Scroll to the bottom. At Address FF, you should see MOVLW 0x00. This is your restored calibration constant.
Be sure to visit Programmer->Settings and uncheck Allow PICkit3 to program calibration memory to avoid clobbering it again.

So far all this does is put something into the cal constant to suppress the error and set the oscillator to the center frequency. You'll have to check the timing and adjust the cal constant for now. Microchip says that none of their programmers will read the backup value.... Pic

Until you get a handle on what went wrong, I would suggest that you immediately read any new chips and log the cal value in case you have to restore it.

If I hear anything more on the ticket, I'll let you know.

Good luck.

BTW: PICkit2 with the standalone programming software has an auto-recover function for the calibration value..
I have been away will do this tomorrow and report back to you.

Thanks

Rodney
 
Top