2014-10-21 09:54 AM
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
2014-10-21 10:10 AM
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?2014-10-26 12:04 AM
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->VALto return the number
of
ticks
elapsed
=> count up the number of millisec?2014-10-26 05:19 AM
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);
2014-10-26 06:49 AM
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->VALto 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.2014-10-26 08:37 AM
Would you have
an
example of using
DWT_CYCCNT?2014-10-26 08:42 AM
2014-10-28 11:56 PM
Thank for your help