Brent, Okay, I didn't realize you needed a 115.2 kbaud UART. Even with a stable crystal frequency, software or hardware implementation could have a large error if the clock frequency is not right, just because the baud rate is so close to the clock rate. For example, at a 4 MHz clock, the bit length is 8.68 instruction cycles. But it's possible to have only integer number of cycles, so it would be either 8 or 9. The error is then roughly -8% or +4%. This might be okay though if you compensate the error each following transmitted bit, e.g. doing delays in this sequence: 8, 9, 9, 9, 8, 9, 9, 8, 9, 9, etc. But a better clock frequency would be 3.69 MHz, which divides evenly by 115.2 kbaud. Here is another idea. It would be nice to be able to change RC-oscillator frequency with external resistors. You could still calibrate the oscillator to achieve 3.69 MHz and take advantage of the hardware UART. Usually RC-oscillator is completely inside the chip, but a few PICs (like 16F628) have external resistor mode (ER) for the oscillator. The resistor is hooked between CLKIN and VSS. So, if you connect more resistors in parallel controlled by pins, the frequency could be adjusted in some range. It might be difficult to control since pins themselves add another variable, so the frequency could depend on overall power consumption of the PIC, for example... Alternatively, the resistors could be switched by an external device like analog MUX or resistor DAC. That would remove that variability. Nikolai > Subject: Re: [PIC]: Startup time for resonators > From: Brent Brown (brent.brown@CLEAR.NET.NZ) > Date: Fri Jul 12 2002 - 18:26:50 PDT > On 12 Jul 2002 at 9:48, Nikolai Golovchenko wrote: >> Hi Brent, >> >> You might want to still use the RC oscillator as it provides the >> fastest start-up. To achieve accurate baud rates you simply need to >> calibrate the RC-oscillator using a good reference, like 32768 Hz >> crystal. Some PICs can run from RC-oscillator and clock a timer from >> the crystal at the same time. So, you would have to simply wake up >> occasionaly (on timer overflow for example, which would be every 2 >> seconds), calibrate the RC-oscillator, and go back to sleep. Or do the >> calibration even less often, but it depends on how fast the frequency >> can change. If the device is indoors, where temperature doesn't change >> quickly, it's probably pretty stable. > Nikolai, > Yes this is a good idea and we do have a 32.768kHz crystal on the > second oscillator for implementing a RTC. > We thought of the scheme you describe but the problem is that the > customer wants to do IRDA with 115200 baud. This scheme does not give > enough resolution to aceive this baud rate with the UART. It is > probably OK for 9600 baud where each step in SPBRG equals about 400 > baud. In a software UART the resolution could be better but we are > already doing that to generate a second async port and would like to > the use hardware UART as well! > -- > Brent Brown, Electronic Design Solutions > 16 English Street, Hamilton, New Zealand > Ph/fax: +64 7 849 0069 > Mobile/txt: 025 334 069 > eMail: brent.brown@clear.net.nz -- http://www.piclist.com hint: The PICList is archived three different ways. See http://www.piclist.com/#archives for details.