Jump to content
Sign in to follow this  
andydavy

Calibrating Osccal With Boostc

Recommended Posts

Hi,

 

Having problems with the following assembler code and I can't see what the problem is with the "call" line 108, can anyone help :D

105	asm  //Load Factory Calibration Value Into OSCCAL
106	{
107  bsf _status,RP0 
108  call 3ffh
109  movwf _osccal 
110  bcf _status,RP0
111	}

 

BoostC Optimizing C Compiler Version 1.5 Alpha (for PIC16 architecture)

http://www.picant.com/c2c/c.html

Copyright© 2004 Pavel Baranov

Copyright© 2004 David Hobday

 

 

s2kdashir.c(108): error: error in built-in assembly

failure

Exit code was 1.

Removing target: s2kdashir.obj

Failed to locate output file 's2kdashir.obj'

Done

 

Failed

Share this post


Link to post
Share on other sites

We need to investigate this issue. Currently BoostC expects a label as argument of the call instruction. What is located on address used in "call 3ffh"? How other compilers deal with such calibrating?

 

Regards,

Pavel

Share this post


Link to post
Share on other sites

With small PIC processors, address 3FF is supposed to hold a RETLW xx, where XX is a number from 00 to FF, which is a Microchip-calculated calibration value for the internal oscillator.

 

Usually, I've erased this part of the chip by the time this code runs, so I simply hard-code an OSC_CAL = $xx in my code.

 

The other approach, with MPASM tools (which don't erase that location when programming) will allow the user to not have to record the 'xx' value for each processor they program.

Share this post


Link to post
Share on other sites

The internal oscilator of most (all?) of the smaller PICs eg. OIC12F675 are "factory-calibrated" by Microchip in the following way:

 

The last program location (eg. 0x3FF) contains a RETLW xx instruction where xx is the value to be written into the OSCCAL register for best oscilator calibration.

 

So the code:

 

asm {

call 0x3FF

movw OSCCAL,F

}

 

is very commonly used.

 

I miss it too in BoostC!

 

Regards

Svend

Share this post


Link to post
Share on other sites

Thanks for the explanations. We'll try to add this feature into the next BoostC update.

 

Regards,

Pavel

Share this post


Link to post
Share on other sites
Fixed. Fix will be available in 1.7 update.

 

Regards,

Pavel

 

 

Pavel,

 

Did the OSCCAL feature/fix ever get implemented, I using BoostC 1.8 with a 12F675?

 

I try setting the osccal variable with a value within the code (osccal = 0xfe;) and I still get complaints about OSCCAL not being set from my programmer, ic-prog.

 

I also tried including the bit of assembler

 

asm

{

call 0x3FF

movw osccal, f

}

 

but I keep getting an "error in built in assembly" for the movw line.

 

Thanks,

 

Perry

Share this post


Link to post
Share on other sites

fischp,

 

Your code as one major error - using opcodes that dont exist - movw :)

The other thing you need to know is the osccal is declare as a variable (volatile char osccal @ 0x0090;) in the header file.

 

When you refer to variables in assembler then you need to prefix them with an underscore.

 

So the following code compiles :(

#include <system.h>


void main()
{
asm 
{
 call 0x3FF
 movwf _osccal
}

}

 

Regards

Dave

Share this post


Link to post
Share on other sites
Guest Joe
I try setting the osccal variable with a value within the code (osccal = 0xfe;) and I still get complaints about OSCCAL not being set from my programmer, ic-prog.

 

The oscal is factory set by microchip during manufacture. Your programmer should maintain this factory set value by reading it back, programming the device, then re-writing it to the device.

 

If your programmer doesn't do this, buy a different programmer!

Share this post


Link to post
Share on other sites

As far as I know, only MPLAB programmer's actually protect the last two locations before programming. All others just erase the calibration value just before the first programming -- or use an MPLAB programmer like PICStart.

 

So, if you want to use the calibration value, you'd better 'read' the chip first thing, write the value on a piece of paper, then program the PIC.

 

I try setting the osccal variable with a value within the code (osccal = 0xfe;) and I still get complaints about OSCCAL not being set from my programmer, ic-prog.

 

The oscal is factory set by microchip during manufacture. Your programmer should maintain this factory set value by reading it back, programming the device, then re-writing it to the device.

 

If your programmer doesn't do this, buy a different programmer!

Share this post


Link to post
Share on other sites

The latest BoostC update contains a sample osccal.c that shows how to load factory calibration value into OSCCAL. Does it work for you?

 

Regards,

Pavel

Share this post


Link to post
Share on other sites
The latest BoostC update contains a sample osccal.c that shows how to load factory calibration value into OSCCAL. Does it work for you?

 

Regards,

Pavel

 

Pavel,

 

Yes this does work, however, my ic-prog programmer software has long since "whacked" the osccal value. I presume that there's no way to recover that... Does anyone else know of a "free" programming package that doesn't erase the osccal that works with JDM programers? I don't think the MicroChip software is free...

 

Thank you though! And thank you for writing/supporting such a great development platform!

 

Regards,

 

Perry

 

P.S. Is there a more comprehensive manual that documents the full BoostC product? The help file is good but seems to skip detail in many areas. I'm looking for documentation on things like adding an underscore on a variable name allows it to be referenced in assembler and other goodies like that. I'm learning alot by searching this forum, but I'm sure there's more.

Share this post


Link to post
Share on other sites
Guest Joe
As far as I know, only MPLAB programmer's actually protect the last two locations before programming. All others just erase the calibration value just before the first programming -- or use an MPLAB programmer like PICStart.

 

So, if you want to use the calibration value, you'd better 'read' the chip first thing, write the value on a piece of paper, then program the PIC.

 

 

Oops, didn't realise that. I've only ever had 2 programmers, one that i bought the software protected against this problem, and one i designed for myself to update firmware in the field (no PC required), that also read before writing.

 

 

:)

 

 

I've had this argument before in a different forum, i dont think there is any (easy) way to recalibrate, short of getting out a freq counter and trying different values.

 

If you really need to use the internal osc at this accuracy, then you should chuck away the device and buy another one, after all they aint all that expencive.

 

When they are new, read the device and write the cal word on the under side of it in tipex (white correction fluid) or somthing.

Share this post


Link to post
Share on other sites

On reset, the hardware sets itself to 00, which is almost always wrong. A 'perfect' part would use $80, which puts the oscillator in the center of its 'range'.

 

Most parts I've used are around $80 -- 7F, 7E, 81, 82, etc. You could start with $80, use the part to blink an LED, and 'tweak' the value to get a better value. And I agree with writing the number on the underside of the chip, BTW.

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...