To choose a crystal that maches a baudrate and a RTC

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

Hi guys,
I am wondering if there is an ideal chrystal when the UART and a software RTC is used. ( I mean a RTC based on timer interrupts and not a separate RTC device ) . Thanks

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

Any of the oddball frequencies given in the baud-rate chart in the datasheet will work well for both (1.8432, 3.6864, 7.3728, etc.).

Regards,
Steve A.

The Board helps those that help themselves.

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

To expand on Steve's answer; the oddball frequencies are all multiples of the standard baud rates, which themselves are all integer multiples (usually two) of each other.

This means that you will always get exact baud rates (0% error) when you use one of these crystals; they'll divide down the usual sequences and end up with - depending on the crystal, since there's a limit to how far you can divide in the pre-scaler (and I have an idea that not all UBR registers have the same range) - the familiar 19,200/9,600/4,800/2,400/1,200 etc range.

Each of these is also an integer multiplier of 1Hz, so it's easy to generate an interrupt for your rtc. Of course, you can't just use powers of two - that would be too easy... but for example, if you have a 1.8432MHz crystal, you would prescale by 16 to get 115200 baud, by 32 to get 57600 baud, by 192 to get 9600 baud and so on. With the ten-bit UBR the lowest rate you could get would be 1800 baud.

For the real time clock using the same crystal you might find it convenient to again use a 1024 prescale. That gives you a clock input to a timer at 1800Hz. You may the use either an eight or a sixteen bit counter to generate a convenient interrupt (CTC mode, interrupt on compare); the sixteen bit counter will return a tick every second, while the eight bit counter might be better used to count to 180 and return a tick every tenth of a second.

Neil

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

Thank You Steve
Thank You Neil for this tutorial. I learned again today, Dieder

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

Slight correction to my post above; on the AVR the baud rate divider is of course sixteen times the baud rate. So with the 1.8MHz crystal the divider is 1 to get 115200; minimum standard frequency is 150 baud. It can't quite get 110 baud, but who uses that these days?

Neil