Setting OSCCAL value

(instructions, reset, WDT, specifications...) PIC10F2xx, PIC12F5xx, PIC16F5x

Setting OSCCAL value

Postby EngineeringGuy » Thu Jun 29, 2017 6:13 pm

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?
EngineeringGuy
 
Posts: 3
Joined: Mon Jun 12, 2017 10:29 pm

Re: Setting OSCCAL value

Postby AussieSusan » Fri Jun 30, 2017 3:32 am

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
AussieSusan
Verified identity
 
Posts: 173
Joined: Mon Jun 16, 2014 4:45 am
PIC experience: Experienced Hobbyist

Re: Setting OSCCAL value

Postby EngineeringGuy » Fri Jun 30, 2017 5:34 am

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.
EngineeringGuy
 
Posts: 3
Joined: Mon Jun 12, 2017 10:29 pm

Re: Setting OSCCAL value

Postby AussieSusan » Tue Jul 04, 2017 4:15 am

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
AussieSusan
Verified identity
 
Posts: 173
Joined: Mon Jun 16, 2014 4:45 am
PIC experience: Experienced Hobbyist

Re: Setting OSCCAL value

Postby EngineeringGuy » Thu Jul 06, 2017 5:06 am

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!!
EngineeringGuy
 
Posts: 3
Joined: Mon Jun 12, 2017 10:29 pm

Re: Setting OSCCAL value

Postby David » Mon Oct 02, 2023 11:38 am

badlink.png
badlink.png (28.1 KiB) Viewed 2437 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
David
Verified identity
 
Posts: 8
Joined: Wed May 28, 2014 12:56 am
PIC experience: Professional 5+ years with MCHP products


Return to 12-Bit Core

Who is online

Users browsing this forum: No registered users and 1 guest

cron