Help needed in understanding OSCCAL proble in Mega48

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

I have my system running fine using the internal rc osc and ckdiv/8 set. Comms works fine at 4800 baud and I understand OSCCAL is automatically set on powerup.(Comms is fine at 38400 as well.)
I thought I'd test the accuracy of OSCCAL as the data sheet says it can be altered to 'fine tune'.(The value of OSCCAL is 0xB2 with this particular chip...)
So I include this in startup:-

	LDI ZL,0	;SET INT RC CAL if NEEDED.
	LDI ZH,2
	LPM
;	INC R0
	STS OSCCAL,R0

The idea being that inc R0 (or decR0) will make a small adjustment to the frequency. As it is, (no inc) every thing is fine, and I output the value of OSCCAL to Comms and it's 0xB2.I double checked with my comms, outputting OSCCAL, having set it manually in AVRISP ( advanced tab,R/W OSCCAL to 200 hex) .
However, if I include the inc/dec R0 the comms fails, producing just garbage. Am I doing something wrong/missing something, or is it reasonable to expect a 1 bit change in OSCCAL to change the baud rate by so much? It must be at least >5% to screw the comms data.

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

OK sorted...

   LDS R0,OSCCAL
	inc R0
	STS OSCCAL,R0

This works fine.

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

That's because the OSCCAL register is memory mapped at 0x66 so it can be used like ram. At start up the register is automatically loaded with the factory value.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly