How to program OSCCAL Byte?

Go To Last Post
12 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

At the moment I'm using avrgcc and attempting to configure a atmega8 (PDIP) to use its 8mhz internal oscillator.

I'm using a stk200 compatible programmer:

http://www.lancos.com/e2p/avrisp...

With this I'm using either avrdude or ponyprog.

How do I program the OSCCAL register using the stk200 style programmer? And what value should I put in the register to correctly suit the configured 8mhz internal RC oscillator?

do i need to program the EESAVE bit in the hfuse?

Also what values should I use in the hfuse and lfuse (start up time is not critical)?

ATM I'm trying:

hfuse
1101 1001 0xD9

lfuse
1110 0100 0xE4

Any help would be much appreciated.

Thanks,

Todd.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Todd

Atmega8 has 4 read-only registers with calibration values for 1,2,4 and 8 MHz internal oscillator. Unfortunately atmega after reset always loads into OSCCAL value for 1 MHz. If you use 2,4 or 8 - you should reload OSCCAL manually with proper value. It's yours how to do it - put value into eeprom and read it or simply rewrite code line for every new chip.
Calibration values are often very similar ( for example my current Atmega8 has 0x9a,0x9c,0x93,0x93 ) and then everything could work fine without any additional loading, but it's not guaranteed of course.
I cannot help with your programmer procedure - I use my own device. In general - you should download calibration values from the chip and then use an appropriate one in code initialization part.

EESAVE - as you need. With programmed (0) - eeprom stays untouched during ChipErase operation.

I use the same lfuse - works fine.
And hfuse almost the same :1101 0001 ( with EESAVE )

Be really careful - especially with CKSEL and DISABLE_RESET_PIN. One little mistake makes a big trouble.

Best regards
Jurek Szczesiul

admin's test signature
 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What is the process I need to follow to configure the OSCCAL to a certain value using gcc ?

ie how do i put it in the code so the correct value is loaded in OSCCAL on reboot?

I know the value i need in OSCCAL is 0x95. I worked this out by reading the calibration bytes on the M8.

How do i set this up? and when do i in relation to configuring the high and low fuse bytes?

Thanks,
Todd.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Todd

In my amateur projects I simply write this into code :

...........

int main(void)
{
OSCCAL=0x93; // calibration for internal 8 MHz
..............

Setting OSCCAL and programming fuses are quite different things.
Fuses are set once - only with external programmer.
OSCCAL should be set always after power-on-reset
( as above for example ).

Best regards
Jurek Szczesiul

admin's test signature
 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Right,

But my question is, if I have (say) 8 chips running the same code and I want their oscillators to be synced, which presumably means each one has to be individually calibrated, How do I read the cal byte once I've stored it in Flash or EEPROM?

Presumably I can use whatever macro gets me data out of the progmem, but what's the location?

sasha

admin's test signature
 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Sasha

Unfortunately just as you say : each one has to be calibrated individually. There's no way to get chip calibration bytes straigtly from application level. They are accessible in programming mode only.
You can unify application code ( for example OSCCAL could be loaded from the last eeprom cell, using eeprom_read_byte function ) but you still need to locate an appropriate value at an appropriate place during programming session ( in this example cal value for 8 MHz should be retrieved from the chip and written into
last eeprom cell ). It could be automated if a programmer gives such possibilities. I really don't know if any can do.

Best regards
Jurek Szczesiul

admin's test signature
 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

OK, I see how to do it now. I somehow missed the way to set the address in the calibration byte thingie in the dialog. So I can program each chip's eeprom with the byte and load it in at start, using the same code, so I don't need to recompile for each chip. Exactly what I needed.

Thanks for your help.

s

admin's test signature
 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ok, what confuses me is why was i getting locked out of the microcontroller programming mode after i program the micro to use the internal 8mhz oscillator? (addmitedly not setting OSCCAL)

Ie once i set it at 8mhz it stops working/ talking with the programmer.

I understand that OSCCAL has an effect on the stability of the memory timing etc. but from what i understand the OSCCAL register should be set early in the program.

My question is - what happens in programming mode? Wouldn't osccal default to the 1Mhz setting? If not how does it get loaded when the microcontoller is in programming mode?

Anyway, hopefully somebody can shed some light on the situation.

Thanks for all the replies.

Regards,
Todd.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

5 years and no answer for this. Me too ! I was locked out of my MCU ATMEGA128 and even feeding a external clock source wouldn't connect anymore to my ISP

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
I was locked out of my MCU ATMEGA128

This has absolutely nothing to do with the OSCCAL value. You simply set the fuses incorrectly. Using parallel programming will work regardless of the fuse settings.

Regards,
Steve A.

The Board helps those that help themselves.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Strange to see this thread has popped up. Bit of a spin out to see i've been using these things for 5+ years now - still love the M8 - what a great chip :)

As Koshchi says, if your getting locked out the fuses are most likely wrong. Back when I made this post I was using the wrong fuse settings. I found it helped to use the GUI in Avrstudio to set the fuse values that I required, then use the same values in avrdude.

oddbudman

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

oddbudman,please send me any code u r using in AVRstudio like GUI.....
i m also facing the same problem....
did u calibrate the uC?

SACHIN