Clock gating helps save power by turning off the clock signal to parts of a chip when they are not in use. This stops unnecessary switching and reduces energy use.
Clock gating for power saving in Embedded C
void enable_clock_gating(ModuleName module); void disable_clock_gating(ModuleName module);
Clock gating is usually controlled by setting or clearing bits in special registers.
Exact syntax depends on the microcontroller and its hardware registers.
/* Enable clock gating for UART module */
enable_clock_gating(UART_MODULE);/* Disable clock gating for ADC module to start conversion */
disable_clock_gating(ADC_MODULE);This program simulates clock gating by setting bits in a register. Setting a bit means the clock is off for that module, clearing it means the clock is on.
We start with all clocks on (register 0). Then we turn off UART clock, then ADC clock, then turn UART clock back on.
#include <stdint.h> #include <stdio.h> // Simulated hardware register for clock gating control uint32_t CLOCK_GATING_REG = 0; // Define bit positions for modules #define UART_MODULE_BIT 0 #define ADC_MODULE_BIT 1 void enable_clock_gating(uint8_t module_bit) { // Set bit to 1 to gate (turn off) clock for that module CLOCK_GATING_REG |= (1U << module_bit); } void disable_clock_gating(uint8_t module_bit) { // Clear bit to 0 to enable clock for that module CLOCK_GATING_REG &= ~(1U << module_bit); } int main() { printf("Initial CLOCK_GATING_REG: 0x%X\n", CLOCK_GATING_REG); // Enable clock gating for UART (turn off UART clock) enable_clock_gating(UART_MODULE_BIT); printf("After gating UART clock: 0x%X\n", CLOCK_GATING_REG); // Enable clock gating for ADC (turn off ADC clock) enable_clock_gating(ADC_MODULE_BIT); printf("After gating ADC clock: 0x%X\n", CLOCK_GATING_REG); // Disable clock gating for UART (turn on UART clock) disable_clock_gating(UART_MODULE_BIT); printf("After ungating UART clock: 0x%X\n", CLOCK_GATING_REG); return 0; }
Clock gating saves power by stopping the clock signal to unused parts of a chip.
Always check your microcontroller's datasheet for the correct registers and bits to control clock gating.
Improper clock gating can cause modules to stop working or cause bugs, so use carefully.
Clock gating turns off clocks to unused modules to save power.
It is done by setting or clearing bits in hardware registers.
Use clock gating in embedded systems to extend battery life and reduce heat.