2018-03-29 05:52 AM
I'm using STM32L053C6 for the project and i'm using it on the 16 MHz clock frequency,
i want to generate the delay in the microseconds but i can't found any solution regurding this,
if anyone knows please share it,
Thank you!
#stm32l053 #stm32l053-discovery-board2018-03-29 05:54 AM
it may not C6 it, so you can share it for the STM32L053 also.
2018-03-29 07:30 AM
With some timer running, get the present value of the timer, calculate the value of the timer when the delay should end and wait until the timer reaches the expected value. Do expensive calculation when starting up. Care for timer roll-over.
2018-03-29 11:41 AM
Would agree, you could free run a TIM at 16 MHz or 1 MHz depending on the granularity you want
uint16_t start, current;
start = TIM2->CNT;
do
{
current = TIM2->CNT;
} while((current - start) < 32); // 2us at 16 MHz tick
2018-03-30 04:45 AM
Cam you please explain it in briefe.
2018-03-30 07:42 AM
Pick a TIM and configure the timebase to maximal (ie 0xFFFF)
The HAL software trees have a lot of examples, you should review those.
2018-03-30 08:03 AM
I generally have a free running timer in my application. SysTick often but others do as well.
Time stamp a variable and wait for a set duration to expire.
2018-03-30 10:16 AM
The OP wants micro-second precision, not milli-second, and the CM0 doesn't provide access to 32-bit wide DWT_CYCCNT, and the SYSTICK counter goes backward, and is 24-bit making the wrapping math more tedious for tight loops.
2018-03-30 10:25 AM
STM32Cube_FW_L0_V1.10.0\Projects\STM32L053C8-Discovery\Examples\TIM\TIM_TimeBase
/*♯♯-1- Configure the TIM peripheral ♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯*/
/* Set TIMx instance */ TimHandle.Instance = TIMx;TimHandle.Init.Period = 0xFFFF; // 16-bit maximal count
TimHandle.Init.Prescaler = 0; // At CPU clock, or for 1 MHz (1us ticks) CoreMHz-1 TimHandle.Init.ClockDivision = 0; TimHandle.Init.CounterMode = TIM_COUNTERMODE_UP; if(HAL_TIM_Base_Init(&TimHandle) != HAL_OK) { /* Initialization Error */ ErrorHandler(); }Current count readable via TIMx->CNT, elapsed time computed via subtracting start count from current count, basic math, wrapping handled if math done with uint16_t
2018-03-30 10:32 AM
'
the SYSTICK counter goes backward, and is 24-bit making the wrapping math more tedious for tight loops.'so what? sounds like a non-issue.