![]() |
David Cook ROBOT ROOM™ |
|
| home | projects | contact | copyright & disclaimer | books | links | ||
|
Trimming the Internal Clock Generator on the 68HC908KX8 Microcontroller
|
|
One of the nicest features of the 8-bit KX8 microcontroller (manufactured by Freescale Semiconductor)
is that it includes an internal clock generator (ICG).
This allows the chip to run without the trouble and expense of an external crystal or canned oscillator. The downside is that the built-in oscillator can be pretty inaccurate. Theoretically, the frequency could be off by up to 25% on an untrimmed chip (worst case). If you test the individual chip and place its specific trim value into the code, then the base frequency may be as accurate as 0.3% when averaging combined pulses (best case). (For more information, see the MC68HC908KX8 datasheet or AN2498 technical notes.) Realistically, if you need better than 1% accuracy you should probably use a crystal. I use the 16-pin DIP KX8 as the primary brain for many of my robots. In particular, I use that microcontroller in Roundabout, the robot from the book Intermediate Robot Building. I decided to make pre-programmed microcontrollers available for readers that want to reproduce Roundabout but don't have a programming board for installing the downloadable HC08 source code (see the link in Appendix A of the book). Since Roundabout plays music during operation, reasonably accurate frequency is important for the notes to be in tune. So, that meant that I needed to know the best trim value for the internal clock generator of each individual chip before programming. MANUAL TRIMMING In the past, when I was only trimming one or two MCUs a year, I'd simply hand tune them.
AUTOMATIC TRIMMING The process I am about to describe could be better optimized for assembly lines where time is money. Nonetheless, here's an automated technique that works acceptably well for small lots (a few hundred chips).
|
|
TRIM DISTRIBUTION I had two batches of MC68HC908KX8CP microcontrollers on hand for testing. 21 had a date code of 0035 (mask 1K45D) and 100 had a date code of 0403 (mask 2L09H). They were trimmed at room temperature all on the same day. About 10% were randomly retested at the end, and all were reconfirmed to be within 1 of the originally determined trim value. ![]() Decimal quantity on the vertical axis. Trim values in hexadecimal on the horizontal axis. Data code 0035 batch in red. As you can see, the trim values varied considerably from chip to chip and batch to batch, with some moderate clumping towards to center. Values ranged from $4F to $B5. Only 16% of the microcontrollers reasonably matched (+/- 1) the default $80 trim value. CONCLUSION The internal clock generator is a wonderful feature for convenience, reduced cost, reduced board space, and as a backup to a more accurate clock source. With a little work, the ICG can easily be trimmed (manually or automatically) to within a couple of percent accuracy over time (not pulse-to-pulse). Based on the variations in internal oscillator speeds as shown in the test results, it is worth trimming the microcontroller. |