cancel
Showing results for 
Search instead for 
Did you mean: 

How to get the correct value of SysTick->VAL on STM32F103 board?

cnhx27
Associate III
Posted on October 21, 2014 at 18:54

Hi all,

With this code I can not get the right number of tick. I suspect the tick timer has not been initialised correctly. I do not know why ! Do you have some idea ?

int
main(
void
)
{
/* Setup SysTick Timer for 1 msec interrupts */
while
(SysTick_Config(SystemCoreClock / 1000));
SleepMilliseconds(5000); 
// Wait 5 Sec;
}
void
SleepMilliseconds(delaytime_t ms)
{
systemticks_t currenttm, starttm;
starttm = gfxSystemTicks();
do
{ currenttm = gfxSystemTicks(); }
while
(currenttm - starttm < ms);
}
/**
* @brief Gets a ''tick'' time from the hardware.
* @param None
* @retval a ''tick'' time
*/
systemticks_t gfxSystemTicks(
void
)
{
return
SysTick->VAL;
}

#stm32f103 #lmgtfy
7 REPLIES 7
Posted on October 21, 2014 at 19:10

Do you have some idea ?

It's a 24-bit value so you're math is broken?

Do you observe the count changing? Does it count down or up?
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
cnhx27
Associate III
Posted on October 26, 2014 at 08:04

systemticks_t

is an unsigned int (32 bit). The count is changing. It count down. I read that SysTick, counts down from the reload value to zero. Does it

rollover after 70 minutes

?

Do you think it

is possible to use

SysTick->VAL

to return the number

of

ticks

elapsed

=> count up the number of millisec?
zzdz2
Associate II
Posted on October 26, 2014 at 13:19

I do it like this:

static inline void waittick(uint32_t step)
{
static uint32_t tick0;
if (!step)
{
tick0 = SysTick->VAL;
return;
}
tick0 -= step;
while ((tick0 - SysTick->VAL) & ((SysTick_VAL_CURRENT_Msk+1)>>1));

}

// init SysTick:
SysTick->LOAD = SysTick_VAL_CURRENT_Msk;
SysTick->CTRL = SysTick_CTRL_ENABLE_Msk;
// init waittick
waittick(0);
// wait 1000 ticks
waittick(1000);

Posted on October 26, 2014 at 14:49

systemticks_t

is an unsigned int (32 bit). Ok, but that doesn't make the size of SysTick->Val get any wider, and you have to pay attention to this when doing the math because a 32-bit mask won't hide it.

The count is changing. It count down. I read that SysTick, counts down from the reload value to zero. Does it

rollover after 70 minutes

? The way you have it configured it will roll every millisecond. At 24-bits it can count around 16 Million cycles, at either SYSCLK or SYSCLK/8, so many applications under a second.

Do you think it

is possible to use

SysTick->VAL

to return the number

of

ticks

elapsed

=> count up the number of millisec? I wouldn't use it that way. I'd use DWT_CYCCNT, or a 32-bit timer ticking at micro-seconds, or tenths of millisecond.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
cnhx27
Associate III
Posted on October 26, 2014 at 16:37

Would you have

an

example of using

DWT_CYCCNT?

cnhx27
Associate III
Posted on October 29, 2014 at 07:56

Thank for your help