[Editor’s Note] I started this post months ago, but a stressful bit of time at work led to me putting this on the back burner. It has already proven its worth as I remembered none of what I’ve written here + managed to quickly get back up to speed. Hope it proves worthwhile to you!
One of the challenging aspects of moving to programming microprocessors is managing the multiple clocks available. The MSP430 documentation refers to this as a “Flexible Clock System” which we can take as a “steep learning curve clock system,” that I butted heads with last time when I tried to get 1-wire up and running. This post is an attempt to better understand the complexity of the architecture and save myself issues in the future.
The first challenge is getting through the acronyms. Each component of this detailed system has its own acronym which all sound pretty similar. I’ll throw out the acronyms + basic definitiens first before we dive into each piece.
Clocks:
- ACLK – Auxillary Clock. Low frequency, used for standby mode + wakeup.
- MCLK – Master Clock. For processor and high speed peripherals
- SMCLK – Sub-system Master Clock.
Oscillators:
- DCO – Digitally Controlled Oscillator. Internal oscillator. High frequency, quickly stable
- LFO – Internal low frequency oscillator. Sub 12kHz, very low power
- LFXT1 – Low Frequency/High Frequency External Oscillator – this sources a watch crystal on XIN/XOUT.
- XT2 – An external Oscillator that can go to high frequencies.
Now some nomenclature notes. CLK means the actual signal. What this means is that you often run into DCOCLK and LFXT1CLK which refers to the clock signals coming out of the DCO or LFXT1. Now with that in mind, lets see where each of the clocks can be sourced. Each row represents a clock that powers some part of the system which may be sourced from one of the oscillators in each column.
Clock |
DCOCLK |
VLOCLK |
LFXT1CLK |
XT2CLK |
ACLK |
|
Yes |
Yes |
|
MCLK |
Yes |
Yes |
Yes |
Yes |
SMCLK |
Yes |
Yes |
Yes |
Yes |
Each of the ‘Yes’ boxes is actually adjustable by ‘/1, /2, /4 or /8.’
Wait, what is with the “/1, /2, /4, /8?” Well, there are dividers in the chain. Lets say that the VLOCLK is configured to run at 12kHz for MCLK, the ACLK could be set to 3kHz (12kHz/4) if needed. Why would would we want to do this? (Why so many rhetorical questions?) Well, if we’re sourcing a counter to ACLK and don’t need more accuracy than 3kHz, this keeps our register from filling up and overflowing too quickly, allowing longer timers.
A discussion of clocks can’t really happen without a discussion of power consumption. A full discussion on power saving will have to wait for another time, but there are some high level concepts we can consider now. First, we want to spend most of the time in low power with a slow clock to conserve power. Then, when required, we want to be able to quickly do a bunch of processing with a high frequency clock so a minimum of time is spent in the high power mode. This aligns well to the clock options – ACLK can be sourced to a low frequency source for low power sleeping and MCLK to DCO or another high frequency source for moments of high activity.
Ok, some details. First, if an external clock is being used (LFXT1) the internal low-frequency oscillator won’t be (VLO). Just happens to be that’s where the switch happens. A crystal would be a more stable source while the internal VLO is liable to drift with temperature.
The MCLK is the easiest piece to understand. That’s the speed the CPU runs at and is a direct analog to what you’d think of as processor speed in a full computer. MCLK typically runs off of DCO
ACLK and SMCLK are used to drive peripherals – i.e. Timer, A2D, etc. The difference is that ACLK is only sourcable from the low frequency sources while SMCLK can come from any of the clocks.
While the DCO is configurable over a wide range of frequencies, configuration is imprecise. The internal resistor and capacitor used in the DCO are on silicon, so there is a variation between otherwise identical processors. To work around this limitation, MSP430 series has one or more ‘calibrated’ frequencies with configurations burned to ROM. For the value line processors, they only have 1MHz calibrated. This doesn’t mean you can use a different frequency, just that you can’t expect it to be precise or function the same over different chips.
Now the question rapidly becomes how to configure these bits + pieces to do what we want. The traditional way is to play with a bunch of registers, play with code, then change it into hard-coded strings to save on program space. When I started writing this all up, that was how things went, but now there is Grace. Grace is a graphical tool that integrates into CCS allowing you to configure peripherals (including the clocks) using a simple graphical interface. It then generates the registry strings for you. I have yet to play with it, but expect it to be a valuable tool, particularly in the beginning as I develop further confidence and understanding.
Next up, playing with 1-wire on the MSP430.
References: