Change CPU Clock of PSoC in Firmware

Question: How to change the CPU_Clock of the PSoC in the firmware (for example switch between Sysclk/2 and Sysclk/1) ?

 

Answer:

The CPU clock may be changed by writing to the first three bits of the OSC_CR0 register.  For example:

To set CPU clock to SysClk/2
OSC_CR0 &= ~0x07; // Clear Bits 0 to 2
OSC_CR0 |= 0x02;  // Set CPU Clock to SysClk/2

To set CPU clock to SysClk/1
OSC_CR0 &= ~0x07; // Clear Bits 0 to 2
OSC_CR0 |= 0x03;  // Set CPU Clock to SysClk/1