2012-08-29 10:36 PM
Hi,
I need an accurate hardware independent Dealy function for stm32l152rbt6 controller, the delay should be completely relay on the software. #silly-silly-silly-questions #!rocketscience #sloppy-thinking #hardware-independent-delay2012-08-29 11:15 PM
I need an accurate hardware independent Dealy function for stm32l152rbt6 controller,
That depends on how you define accurate. You can use the SysTick timer, which is more appropriate for delays of 100us into the seconds range or more, but has the granularity of the firing rate you define. ST provides an explicit SysTick example in the peripheral libs source. Or you can use a TIM<x> timer in a single-shot mode, where you can even trim the timing value to compensate the interrupt latency. However, the more precise your delay needs to be, the closer you need to get to the hardware. There are also several timer examples in the peripheral libs you could adapt for your purpose.2012-08-30 04:16 AM
''hardware independent''...
What a way to start the day.Even the trivial ''while( Delay-- );'' depends on the core's clock, which, in case you haven't actually thought this through, is HARDWARE.Now, what do you think you really need?2012-08-30 05:25 AM
that's indeed what I do:
-chain together two 16-bit counters to get a 32-bit one -LSB=1us - a function to read out this 32-bit counter so i have a global time, with 1us resolution. delay = get current time, add the requested delay, loop until this time is reached it is of course not hardware independent.2012-08-30 05:43 AM
I suppose a background of porting some decent written software, whith some easily portable, more abstract code, and some separated low level code, which needs to be mapped to the new peripherals, and adapted properly.
Such a Delay() function would qualify for the more abstract section. However, you are right - the required time range and accuracy/granularity is not specified.Even the trivial ''while( Delay-- );'' depends on the core's clock, which, in case you haven't actually thought this through, is HARDWARE.According to your philosophical interpretation, there is NO hardware-independant code... I specify it as code that compiles for more than one hardware setup, without changing the sources.
2012-08-30 06:49 AM
All delays will be dependent on the clocking of the part, I'm really not sure how you avoid that. Software loops are affected by code placement, compiler optimization, interrupt, etc.
Consider looking at the RTC prescaler, granularity in the 32-40 KHz range. Consider looking at the DWT's core cycle counter, ticking at the CPU's rate.2012-08-30 07:55 AM
''Philosophical interpretation''? Hardly. Try ''precisely literal''. After all, the boy did say, ''...
the delay should be completely relay on the software.''
...or does your specificity rely on not reading what's actually written? ;)But you did get one thing right: there is no hardware-independent code, irrespective of how deep the abstraction strata run. Flapping about ''specifying'' things only proves the point.2012-08-30 04:39 PM
As to the vagaries of software spin loops
[DEAD LINK /public/STe2ecommunities/mcu/Lists/STM32Discovery/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/STM32Discovery/STM32F0Discovery timing issue&FolderCTID=0x01200200770978C69A1141439FE559EB459D75800084C20D8867EAD444A5987D47BE638E0F&TopicsView=https://my.st.com/public/STe2ecommunities/mcu/Lists/STM32Discovery/AllItems.aspx¤tviews=40]https://my.st.com/public/STe2ecommunities/mcu/Lists/STM32Discovery/Flat.aspx?RootFolder=%2fpublic%2fSTe2ecommunities%2fmcu%2fLists%2fSTM32Discovery%2fSTM32F0Discovery%20timing%20issue&FolderCTID=0x01200200770978C69A1141439FE559EB459D75800084C20D8867EAD444A5987D47BE638E0F&TopicsView=https%3A%2F%2Fmy.st.com%2Fpublic%2FSTe2ecommunities%2Fmcu%2FLists%2FSTM32Discovery%2FAllItems.aspx¤tviews=40