Page 1 of 1

Setting OSCCAL value

PostPosted: Thu Jun 29, 2017 6:13 pm
by EngineeringGuy
I have been trying to figure out how the code that Microchip uses in their template for PIC 10F206 works to set the OSCCAL value into its' register... The template has:

ORG 0x1FF ; processor reset vector

; Internal RC calibration value is placed at location 0x1FF by Microchip
; as a movlw k, where the k is a literal value.

ORG 0x000 ; coding begins here
movwf OSCCAL ; update register with factory cal value

I am familiar with the use of ORG or CODE to branch around an interrupt vector by placing vectors to the main program and interrupt routine, but in the case of OSCCAL, what is needed is to execute the code at memory location at 1FF.. which in the chip I am using at present is CFA.. which is a movlw FA. If the code was:
movlw 0xFA
OSCCAL

I can see how this would work.. but how do the two ORG statements in the template accomplish this?

Re: Setting OSCCAL value

PostPosted: Fri Jun 30, 2017 3:32 am
by AussieSusan
I don't know that chip but as a guess: if the devices PC is set to 0x1ff on reset, then the move instruction there will be executed to load a preset value into the W register, and the PC incremented. If that increment means the PC wraps back to 0x000 then the w register value will be written to OSCCAL.
Susan

Re: Setting OSCCAL value

PostPosted: Fri Jun 30, 2017 5:34 am
by EngineeringGuy
AussieSusan,
So what you are suggesting is that when the "ORG 0x1ff" sets the PC to the last memory location.. It then executes the instruction there, which is a movlw 0xFA, and when the PC rolls over to 0x000... the "ORG 0x000, OSCCAL" loads the 0xFA into the OSCCAL register. If that is what that code does, it would certainly accomplish the task. Thanks for explaining... I was not aware that the ORG statement could be used to execute existing code at an address.. I only read about it allowing code to be inserted at specific addresses in memory.

Re: Setting OSCCAL value

PostPosted: Tue Jul 04, 2017 4:15 am
by AussieSusan
No - the ORG instruction tells the assembler where to place the next code.
What sets the PC is the 'reset' of the device. Check Table 4-1 ofg the data shet for that device and you will see that the PCL register has a power on reset value of 0xff. Also read section 4.7.1.
Susan

Re: Setting OSCCAL value

PostPosted: Thu Jul 06, 2017 5:06 am
by EngineeringGuy
I get it now.. I was assuming that the reset vector pointed to 0x000.. I see now that it points to the top of memory... gets the OSCCAL value loaded into the W register by executing the instruction at 0x1FF, and then rolls over to 0x000 to load W into OSCCAL.. Thanks VERY MUCH for the clarification.. I'm learning... slowly!!

Re: Setting OSCCAL value

PostPosted: Mon Oct 02, 2023 11:38 am
by David
badlink.png
badlink.png (28.1 KiB) Viewed 2571 times


sort of irreverent please delete

link takes me to error.... Internal Server Error from url of viewtopic.php?f=30&t=416


edit now im confused , from edge which found link it fails fron your web site it works



lol