2012-10-10 04:37 AM
Hi everyone,
I'm new with STM's MCU and I'm doing some tests on the the STM32VLDiscovery board (with MCU : STM32F100RB) I've just bought.
I wrote a simple code for blinking a LED and tested it successively on the evaluation board.To make the LED blinking, I used a Delay function I found in some sample code.
My problem is
that my calculating of the time that the Delay() function would take according to its parameter doesn't mach the real time.
here is the function:
void Delay (unsigned int volatile nCount)
{ for (; nCount! = 0; nCount -);}On the board there is an external 8 Mhz oscillator. So if this is the
clock
system , the clock cycle would take : 0125 us.for example, if we use the function takes 0xFFFFF as parameter.
Delay(0xFFFFF)
0xFFFFF = 1048575
(Decimal) so the time the Delay() function
takes would be
:1048575 x 0,125 10 ^ -6 = 0,131 s
But in practice, on the Discovery board the time is much larger, the delay time is about a second or 3/4 of a second !
Where do you think is my error ? could you give me an explanation ?
Thanks in advance.
#clock #delay #stm32vldiscovery2012-10-10 06:36 AM
That does seem slow.
By default the external clock is not enabled, so you need to more carefully examine what clocks, dividers, and PLL options are being configured, and too what. For CMSIS look at SystemInit() Also the presumption that your C code will compile to a single cycle loop is awfully hopeful. You'd be hard pressed to do that in assembler, but unless you look at the instructions you're not going to know what the cycle count is likely to be. This is a pipelined RISC design, the linear throughput might peek at 1 IPC, but the latency, branching and load/store will not.2012-10-10 02:18 PM
Hi and thanks clive1,
As I understood from the
''
system_stm32f10x.c'' file
of the CMSIS folder in the Project,
by default, the MCU uses the internal clock which is HSI (8Mhz like the external), but it's the case only if no one from the other frequencies ranging from 24 Mhz to 72 Mhz !!!!! is defined/set.In my program I didn't set the frequency of the MCU (I'm using IAR as IDE).
for me now setting the system clock is not that clear, I'll try to read more about and may be i'll be back.
thank you again.