cancel
Showing results for 
Search instead for 
Did you mean: 

Accurate hardware independent Dealy function

Manjunatha S
Associate II
Posted on August 30, 2012 at 07:36

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-delay
7 REPLIES 7
frankmeyer9
Associate II
Posted on August 30, 2012 at 08:15

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.

Posted on August 30, 2012 at 13:16

''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?

bart2399
Associate II
Posted on August 30, 2012 at 14:25

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.

frankmeyer9
Associate II
Posted on August 30, 2012 at 14:43

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.

Posted on August 30, 2012 at 15:49

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.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on August 30, 2012 at 16:55

''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.

Posted on August 31, 2012 at 01:39

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&currentviews=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

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..