Lesson 4 – Programmable Clock Source

Background

The MSP430 can be used to generate a range of frequencies with or without an external oscillator. Using the internal Digitally Controlled Oscillator (DCO) in tandem with the Phase-Locked Loop (PLL), 1MHz, 2MHz, 4MHz, 8MHz or 16MHz can be outputted to a GPIO.

NOTE: For best precision, an external oscillator is recommended

Figure 1 – Wiring diagram

Operation

The default frequency of 1MHz can be altered by adjusting the initialization value of the one-byte command variable.

In addition to UART, the program is compatible with SPI via P2.4, P2.5, P2.6 and P3.1.

Table 1 – 4-Wire SPI settings

The GUI

Figure 2 – The GUI

The GUI can be used to set the desired frequency. When a button is pressed, the MSP430 sends a command and will reply if the request was successful.

A baud rate of 4800 is selected with one stop bit and no parity

The Code

A summary is described below:

  1. Start -> Stop WDT & enable FRAM writes
  2. Initialize GPIO, clocks, communication
  3. Configure FLL & DCO for 16MHz
  4. Enter main loop:
    1. Wait for command interrupt (LPM0)
    2. On RX ISR: read byte ->
      1. If GET: send status
      2. Else if idle: store new command, flag PROCESSING, exit LPM0
      3. Else busy: send PROCESSING
  5. In loop after wake: Command_process() -> set DCO divisors & wait states, send SUCCESS/FAIL
  6. Return to LPM0