cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with system clock

mircead2011
Associate
Posted on June 30, 2014 at 22:08

Hi.

I use a STM32F103ZE microcontroller.

I try to change the System Clock (default is HSI) to HSE.

On my board is a HSE - cristal oscilator which value is 8 Mhz and i want to change it to 72 Mhz and it works.

But if i want to change it to a small value , for instance 24 Mhz i cannot change it, even if i made the setup (RCC->CFGR |= (1 << 16) | (1 << 18); ).

One more quetion : how many clock cycles takes to execute an instruction ?

#include<stm32f10x.h>

void wait(void)  

{

     int  d;

     for(d = 0; d < 1000000; d++); 

}

int main (void) 

{

unsigned int i;

RCC->CR &= ~(1 << 0);

RCC->CR |= (1 << 19);

RCC->CR &= ~(1 << 16);

RCC->CR &= ~(1 << 24);

RCC->CFGR &= ~(1 << 17);

RCC->CFGR |= (1 << 0);

RCC->CFGR &= ~(1 << 1);

        RCC->CFGR |= (1 << 16) | (1 << 18) | (1 << 19) | (1 << 20);

RCC->CFGR |= (1 << 25) | (1 << 26);

RCC->CR |= (1 << 24);

RCC->CR |= (1 << 16);               

       RCC->APB2ENR |= (1UL << 7);     // Enable GPIOF

      GPIOF->CRL    =  0x33000000;       // PF.6, PF.7 defined as Outputs   

      GPIOF->CRH    =  0x33;                 // PF.8, PF.9 defined as Outputs

       while (1)  

       {                               

for(i = 1<<6; i < 1<<10; i <<= 1) 

   {     

GPIOF->BSRR = i;                 // Turn LED on

wait();                

GPIOF->BRR = i;                  // Turn LED of

}

   }

}
1 REPLY 1
Posted on June 30, 2014 at 23:45

One more question : how many clock cycles takes to execute an instruction ?

It's pipelined, so each instruction takes several cycles, though the throughput is usually one cycle. Loads from slow buses and memories will delay things, divides can take between 2 and 12 cycles.

This is for machine instructions, not C code lines

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..