[PIC] pPICKIT2 looses bandgap value in PIC12F629

Status
Not open for further replies.

Sonu21091990

Newbie level 6
Joined
Dec 17, 2016
Messages
12
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
83
I am new to PIC microcontroller programming. I tried to program PIC12F629. I simulate my program in Proteus, and it works fine. But when I tried to program it using PICKIT2, the band gap calibration value changes from 1000 to 0000. I have read the data sheet where it says the OSCCAL values and band gap calibration values should not be changed. I can set OSCCAL value using PICKIT2. But i don't know how to set the bandgap value. Thanks in advance
 

I guess setting the previously read calibration value might fail if programming is irregularly interrupted.

The values can however be edited in MPLAB under Programmer/Settings/Calibration Memory.
 
First check 'OSCCAL' is set to auto regenerate under the tools heading in the menu.
Second, the value is saved at the very end of normal program memory so make sure the data you are writing to the PIC doesn't overwrite that address.

Brian.
 
I guess setting the previously read calibration value might fail if programming is irregularly interrupted.

The values can however be edited in MPLAB under Programmer/Settings/Calibration Memory.

thanks. i am using mplab xc8 as a compiler. But i didn't find calibration memory setting. Please tell me where i can find it? Any other tool required for it?
 

First check 'OSCCAL' is set to auto regenerate under the tools heading in the menu.
Second, the value is saved at the very end of normal program memory so make sure the data you are writing to the PIC doesn't overwrite that address.

Brian.

thanks.i have noted the oscal value. my program does not consume large space. Here is the screen shot. please tell me if i did anything wrong
 

But i didn't find calibration memory setting. Please tell me where i can find it? Any other tool required for it?
I was referring to classical MPLAB rather than MPLAB-X. I presume the setting is also available in MPLAB-X.
 
The settings are in the 'Tools/OSCCAL' menu of the Pickit2 software, not in XC8 or MPLABX.

The danger you face is due to the value being stored in the main program memory. The way calibration works is the very last address in the program memory contains the instruction "movlw xx" where xx is the OSCCAL value. The reset vector is hard coded to point to that address. When the PIC resets (or powers up) it goes to the reset vector and executes that instruction, leaving the calibration value in the W register. Because it is the final address, as the program counter increments, it rolls over to address 0x000 where you normally start your own code from. So by the time you have reached the start of your own program, the calibration value is already in the W register, it's up to you whether you then load it into the OSCCAL register (movwf OSCCAL) or not. Bear in mind it only calibrates the internal oscillator but that PIC has options to use external clock sources as well, in some instances, for example if a quartz crystal was used, it may be more beneficial to ignore the calibration instructions and use the addresses for something else.

However, there is a danger that if you overwrite the final address with your own program code, the instruction to load W and the calibration value are lost. That is something you have to ensure can't happen in the program you write in XC8. It is probably quite rare, but not impossible that your program uses right up to and including the final word of memory.

Brian.
 

i can set the osccal value using pickit2. But i can't change the bandgap value. Please tell me how do i know my program overwrite the last memory location. Is it causing to change the bandgap value? please help me
 
Last edited:

I expect that XC8 does not overwrite the calibration word by accident, rather drops an error, but I didn't check. If it does though, you would clearly see in the assembly listing and linker map.
 
I was referring to classical MPLAB rather than MPLAB-X. I presume the setting is also available in MPLAB-X.

thanks. sorry i can't find the calibration memory settings in mplab xc8. Do i have to download anything for this particular option?

- - - Updated - - -

I expect that XC8 does not overwrite the calibration word by accident, rather drops an error, but I didn't check. If it does though, you would clearly see in the assembly listing and linker map.

my program build successfully. It did not give me any error. here is my code
View attachment main.txt
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…