STM32F2xx ctl tick time
Hi Guys,
I appear at present to be getting a wrong timeout to a tick and I can't yet find why.
Within a task, I have some code like the following:
n = ctl_get_ticks_per_second();
while (1)
{
ctl_timeout_wait(ctl_get_current_time()); // every 1ms
tick_ms++;
if( tick_ms & 1 )
{
set_BNC_out_high();
} else {
set_BNC_out_low();
}
}
Which normally would toggle the state of the output every millisecond, but in this case it's every 10ms.
'n' is 1000, which suggests ctl thinks it's doing 1ms ticks. But the 'scope tells a different story.
AFICS the only change I have from the default setup is that I have 12MHz crystal, not 25MHz, so I have changed PLL_M to from 25 to 12.
Does anyone have any hints of how I can find why I get the unexpected time. I can't presently find it, RCC registers seem sensible from the setup.
-
Hi Michael,
It's a cut-down from the whole code showing just the essential bits.
It would not compile without the omitted stuff.
The call to the ctl wait was cut and pasted from STM32F1xx code. Your answer suggets either things have changed, or in my earlier code I'd done something, about which obviously I've forgotten, to shorten it to 1ms.
Is there a means to get my ticker task running at 1ms increments instead of 10ms incremenms?
Thanks.
-
Thanks Michael, that's done it.
For the record, if anyone else looks for the answer, this was the change I made:
void ctl_start_timer(CTL_ISR_FN_t timerFn)
{
userTimerISR = timerFn;
SysTick->CTRL = SysTick_CTRL_TICKINT_Msk | SysTick_CTRL_ENABLE_Msk;
// We want 1ms ticks, not 10ms. ** GLS **
//SysTick->LOAD = (SystemCoreClock/8/100)-1; // interrupt every 10 ms
SysTick->LOAD = (SystemCoreClock/8/1000)-1; // interrupt every 1 ms
#ifdef CTL_TASKING
// So we don't need to increment by tens ** GLS **
// ctl_time_increment = 10; // so increment the counter by 10 to get the ms counter
ctl_time_increment = 1; // I think this is actually redundant. ** GLS **
#endif
.....
Please sign in to leave a comment.
Comments
4 comments