Table of Contents
Overview
In this article, we go over how to measure the clock signal output by a microcontroller circuit. So if you work with microcontrollers, then you know they utilize clocks for operation.
Components required table
S.No | COMPONENTS | DESCRIPTION | QUANTITY | |
1 | TSM320f28035 Evaluation Board | TSM320f28035 Evaluation Board | 1 | Evaluation Board |
2 | Oscilloscope | Oscilloscope | 1 | Oscilloscope |
2 | Logic Analyser | Logic Analyser | 1 | Logic Analyser |
3 | connection wires | Jumper Wires | 10 | Jumper Wires |
Block Diagram
Introduction
Microcontrollers act upon instructions a few bits at a time, collecting the next batch of bits at regular intervals. Those regular intervals need to have a regular cadence for the MCU to be predictable, so MCUs have at least one clock to keep timing going at a regular pace, much like you would use a metronome to keep pace in piano playing. Clocks can be internal or external, and come in many different types and implementations, but they all keep a regular drumbeat for the MCU. The clock frequency is often discussed concerning the speed of an MCU or processor. A 32 mega Hertz (MHz) clock will cause the associated controller to complete 32 million (M) cycles per second (Hz), which is the same as 32 million instructions processed per second if one full instruction is completed in each cycle.
Why Is Clock Frequency Important?
Well, yes, a higher clock frequency means a faster processor, and in many applications faster is better. But that’s not what I mean. What I’m asking is, Why does clock frequency figure prominently in a wide variety of embedded-firmware design tasks?
Microcontrollers use clocks for things such as system operation to create time delays for circuits that need them to create signals for pulse width modulation. So clocks are vital when working with microcontrollers and embedded programming.
So at times, we want to make sure that we’re working with the right clock signal and we want to be able to measure this output clock signal so that our circuit works well.
Clock configuration is very dynamic with microcontrollers.
Clocks can be configured internally to the microcontroller, where they use components internally on the board to create the clock signal. They can also be configured by adding external components such as crystal oscillators to the board.
Clock signals can be prescaled down to lesser frequencies or when working with phase-locked loops, they can be multiplied to create a clock signal with a greater frequency than the originating frequency.
So clock configuration is very dynamic and you can see the importance of measuring this signal to know what you’re receiving as output.
How to measure the clocks signal
So to be able to measure the clock’s signal output by a microcontroller, you need to use a dedicated pin on the microcontroller that allows for the clock signal to be output.
This pin on a microcontroller is called the microcontroller clock output pin (MCO)
By doing the correct setup and configuration in software, we can output the clock signal from our circuit and program it onto this pin.
Note: Please check whether your controller contains a dedicated clock-out pin or not
If it is available please check with the clock-out keyword, most of the controllers use this keyword to set the clock-out pin.
then we can take an oscilloscope or logic analyzer and measure this clock signal at this output pin.
Example 1:
In this article, we cannot go over each type of microcontroller that there is. So we just take one microcontroller and demonstrate how this works. You then can have an idea of how this works with this microcontroller, which you can do research on and apply to other microcontrollers.
The microcontroller we will use in this circuit is the TMS320F28035 board.
The microcontroller clock frequency is given in the datasheet
Specification of TMS320F28035
This Microcontroller has trace pins available shown below figure, and these include the CLKOUT signal. CLKOUT is usually the core/system clock of the system and is a great option for verifying the CPU clock, or the output of the microcontroller.
Implement this initialization in the source code
GpioCtrlRegs.GPAMUX2.bit.GPIO18 = 3; // 0=GPIO, 1=SPICLK-A, 2=LINTX-A, 3=XCLKOUT
Final code
/*
* main2.c
*
* Created on: 30-Sep-2022
* Author: Admin
*/
#include "DSP28x_Project.h" // Device Headerfile and Examples Include File
void main(void)
{
InitSysCtrl();
EALLOW;
GpioCtrlRegs.GPAMUX2.bit.GPIO18 = 3; // 0=GPIO, 1=SPICLK-A, 2=LINTX-A, 3=XCLKOUT
EDIS;
while(1)
{
}
}
Connection for clock-out pin and oscilloscope
One end of the oscilloscope(+ve) connects to GPIO_18(clock out) and the other end connects to GND. Follow the same for another controller as well.
This below oscilloscope waveform operating with 60MHz and over TMS320f28035 also operates with 60Mhz. As above mentioned in the microcontroller specification.
Example 2:
In this example 2 I am using TMS320F28379D
It is sometimes necessary to observe a clock directly for debugging and testing purposes. The external clock output (XCLKOUT) feature supports this by connecting a clock to an external pin, GPIO73. The available clock sources are PLLSYSCLK, PLLRAWCLK, and CPU1.SYSCLK, CPU2.SYSCLK, AUXPLLRAWCLK, INTOSC1, and INTOSC2.
To use XCLKOUT, first select the clock source via the CLKSRCCTL3 register. Next, select the desired output divider via the XCLKOUTDIVSEL register. Finally, connect GPIO73 to mux channel 3 using the GPIO configuration registers.
GpioCtrlRegs.GPCMUX1.bit.GPIO73 = 3; // 0=GPIO, 1=SPICLK-A, 2=LINTX-A, 3=XCLKOUT
Final code
/*
* main.c
*
* Created on: 16-Sep-2021
* Author: Admin
*/
//
#include "F28x_Project.h"
#include "F2837xD_device.h"
#include "F2837xD_Examples.h"
#include "UART_Communication.h"
#include "device.h"
#include "driverlib.h"
void main(void)
{
Device_init();
//
// Initialize GPIO and configure GPIO pins for CANTX/CANRX
// on module A
//
Device_initGPIO();
EALLOW;
GpioCtrlRegs.GPCMUX1.bit.GPIO73 = 3; // 0=GPIO, 1=SPICLK-A, 2=LINTX-A, 3=XCLKOUT
EDIS;
while(1)
{
}
}