Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] Delay calculation with frequency

Status
Not open for further replies.

chandu.kurapati

Full Member level 3
Joined
Oct 31, 2013
Messages
186
Helped
5
Reputation
10
Reaction score
5
Trophy points
1,298
Location
Bengaluru, India
Activity points
2,778
Hi every one,

I have too much trouble with delay calculation, here my doubt is for ex: some controller working with some frequency(ex: 48MHZ or 84 MHZ some thing else).

I want to provide 100 ms delay in my program with for loop or while loop, How to calculate the max count for that.

please any one can understand my problem and provide some solution for that.

Thanks & Regards,
Chandu.Kurapati.
 

Hi,

This sureley depends on what device you are using (like in another thread of you)
You are keeping informations in secret.

*****

somehow you need a fixed frequency you can rely on.

I don´t like to do this in a "busy wait loop", instead i´d use timer/counters to do this. It is the most exact, simple, reliable and less processing power solution.

Klaus
 

Hi KlausST,

I agree with you it's depend on device but we calculate the count by using frequency only then it's doesn't depend on the device.

my doubt is how much time it's take to complete one for loop iteration.


I calculated like this:

Count = SYS_FREQUENCY(48MHZ or 84MHZ any thing else) / 6(it's like a prescalar);

count *= u8_lDelay(100ms);

Count = count/1000;(for ms);

I taken for loop like this:

for(i=0; i<Count;i++);// i waited up to count is completed.

here frequency changed for device to device but logic is same, is this logic works to provide the delay for any device.

Thanks & Regards,
Chandu.Kurapati.
 

Hi,

but we calculate the count by using frequency only

counts of for...while loops is unprecise..
with C you usually don´t know the exact number of clock cycles for a loop (you could do this by a simulator or go through ASM code)
So you have tor try this.

but after every new compilation ths value may vary, it is not stable
... and if there is any interrupt running, or anything else is within the while loop this will influence the timing also
... and the next hardware generation maybe needs less clock cycles than the one before
... then you get the "packman" effect. Do you know about this mature game? Written without interrupts the game speed was dependent of processor speed. If you started the game even with a 386 processor you just saw a flicker in screen and game was over...

********
why not writing 5 lines of code for setting up a timer interrupt that absolute precisely gives you 100ms ticks?
Independent of compiler, of prcessing load, processing power, other interrupts....

Once you used it you will never loose it.

Klaus
 
Hi KlausST,

Thank you very much, timer code is available for me but just i want to check in this way also. I understand that when we want provide the delay with for loop processor speed, compiler dependency, processing power and interrupt mechanism plays the major role.

Thanks & Regards,
Chandu.Kurapati.
 

use an interrupt instead it will be easy for to change

timer delay loop
Code:
void TimerDelay_10ms(unsigned int delay)
{
	while(delay)
	{
		if(FlagofTimerDelay_10ms == 1)
		{
			FlagofTimerDelay_10ms = 0;
			delay--;
		}
	}
	Flag.TimerDelay_10ms = 0;
}

timer interrupt handler
Code:
void __TimerInterrupt(void)
{
        //Clear Timer1 interrupt flag
	FlagofTimerDelay_10ms = 1;

}

Timer Delay Calculations:
1.Timer Frequency Ftimer=Fcy
2. Using a Prescalar 1:8, then
Ftimer = Fcy / scalar value
3. Time Interval Ttimer = 1/Ftimer
4. To calculate the value to be filled in Timer rolling over or TMR register
No of count for 10m sec delay = 10m / Ttimer

- - - Updated - - -

in a header file keep values of Fcy and scaler value.
if you change those values in header that will be change to the whole timer.
 
Hi Raddy Here,

Thanks for your support, i configured that timer it's working fine.

one doubt for me apart from the subject, how to get (helped me) tag in the below in your post, please tell me.

Thanks & Regards,
Chandu.Kurapati.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top