How to set the system clock, in 2.0.4SDK relevant local version of the source code, there are two system clock setting, which is to set the system clock.
void SystemInit (void)
{
SystemCoreClock = __SYSTEM_CLOCK;
SetBits32(GP_CONTROL_REG, EM_MAP, 23);//EM_MAP=(0x003E)
memset((void*)0x80000,0,0x3000);
__enable_irq();
}
and
set_system_clocks();
but set_system_clocks () function can not see inside the code,Which is the real function of the system clock setting, please help answer this question, thank you very much!
Thu, 2014-02-27 08:02
#1
System clock problem
Hi Randyzhou,
To set the system clock, you only need to change those two lines from the system_ARMCM0.c file:
#define __XTAL (12000000UL) /* Oscillator frequency */
#define __SYSTEM_CLOCK (4*__XTAL)
Hope this helps,
Best regards,
DIALOG SUPPORT TEAM.
Randyzhou,
The set_system_clocks() is a ROM code function.
The source is:
void set_system_clocks(void) // set the hclk and pclk
{
BYTE i;
BYTE j;
for (i = 0; i < 4; i++)
{
SetBits16( CLK_AMBA_REG, PCLK_DIV, i);
(j = 0;j < 4;j + +)
{
SetBits16( CLK_AMBA_REG, HCLK_DIV, j);
}
}
SetWord16(CLK_AMBA_REG, 0x00); //fastest
}
So, the only thing you can do is to change the clock dividers:
// Set clocks to 16 MHz to speed up memeset operation
SetBits32(CLK_AMBA_REG, HCLK_DIV, 0);
SetBits32(CLK_AMBA_REG, PCLK_DIV, 0);
Else, you can use the internal RC16 oscillator.
Best regards,
DIALOG SUPPORT TEAM.
Extra information:
Table 48: CLK_AMBA_REG (0x50000000) of the DA14580 datasheet (p.42):
APB interface clock, Cascaded with HCLK:
00 = divide hclk by 1
01 = divide hclk by 2
10 = divide hclk by 4
11 = divide hclk by 8
AHB interface and microprocessor clock. Source clock
divided by:
00 = divide hclk by 1
01 = divide hclk by 2
10 = divide hclk by 4
11 = divide hclk by 8
Best regards,
DIALOG SUPPORT TEAM.
Hello Dialog,
I'm using SDK 5.0.2.1 with DIA14580DEVKT-B and I want to set the µC frequency to 8MHz.
I change some parameters in the file trng.c:
空白rfpt_init(void)
{
volatile uint16 wait;
SetWord16(CLK_RADIO_REG, 0x0099); // En BLE clk, dis BLE timer, En RFCU, RFCU div by 2 and BLE_DIV by 2 --> was 0x0089
SetWord16(BLE_CNTL2_REG, 0x1000); // Set BLE_CNTL2_REG, parameter BITFLD_BLE_CLK_SEL to 8 --> was 0x2000 (BITFLD_BLE_CLK_SEL = 16)
SetBits16 (CLK_AMBA_REG, OTP_ENABLE, 1);
SetBits16 (CLK_AMBA_REG, HCLK_DIV, 1); // Div by 2 microcontroler clock --> was 0
SetBits16 (TEST_CTRL_REG, ENABLE_RFPT, 1);
// Recommended settings
//set_recommended_settings();
rf_regs();
IffCalibration();
DCoffsetCalibration();
WAIT100(); // Wait 100 us to finish all DCF signals
}
I measuring the power consumption through a 100 ohm resistor (so 100mV = 1mA) and I can observe Advertising frames @8MHz and @16MHz, I expect to have half of the power consumption @8MHz but almost nothing changes (see attached file): the power comsumption fall from 3.06mA to 2.88mA.
So my question is why the power is not divided by 2 ? (the datasheet says the the power consumption is 200µA/MHz)
Remarque:
On my file system_ARMCM0.c, I have:
#define __HSI ( 8000000UL)
#define __XTAL (12000000UL) /* Oscillator frequency */
#define __SYSTEM_CLOCK (4*__XTAL)
but the on board oscillator is a 16MHz, can you say me if __XTAL is usefull ?
Thanks in advance to help me.
Regards,
Damien
Hi damien,
The clock can be lowered to 8MHz, but this is not recommended and not supported because the BLE performance can not be guaranteed. Besides that, the difference in the frequency is small you should not have a power reduction in 8MHz and 16MHz clock.
Thanks MT_dialog