Delay function and more

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Delay function and more

5,057 Views
JamesWorthy
Contributor I
Hello ppl,

I have HC12 ucontroller on a MC68HC912 board and I need a little help here.

1st, i'd like to know what is the CPU speed, as 8MHz nor 16MHz is not what i'm getting from my tests.

2nd, how many cycles is one for (;:smileywink: loop, or how much time will take one loop on my controller.

3rd and last, does anyone have a code for a delay function that will recieve the time and will create a useconds accuracy (1us, 4us, etc.) delay?
I preffer using the timer.

Thanks
Labels (1)
0 Kudos
3 Replies

667 Views
alex_spotw
Contributor III
Hi:

1. The operating frequency depends of the crystal used in the evaluation board you have, and if the FLL is enabled. Therefore we required more information to help you solve your issue ( which board, which crystal, FLL enabled, which MCU part number, which code are you using, compiler, which tess are your running, etc).

2. See response #1.

3. If you use CodeWarrior and Processor Expert, there is a Bean called TimerInt that will give you precisely that: a Programmable Timed Interrupt.

Regards,

Alex
0 Kudos

667 Views
JamesWorthy
Contributor I
Hi Alex,

I have found a pdf that helped me with the delay, so I have made this code:

void main(void) {

TSCR1_TEN=1; // Enable timer
TIOS_IOS0 = 1; // Set bit 0 as output compare

us_delay(8);

for( ; ; ) {} /* wait forever */
}

void us_delay(int useconds)
{

TSCR2_PR = 0; // Prescale = 1
TC0 = (useconds * 16) + TCNT; // 16MHz * useconds = # of ticks
TFLG1 = TFLG1_C0F_MASK; // Reset flag
while (TFLG1_C0F==0); // Wait for time out

}

But, how many ticks does it take to call and return to/from a function?
As I said before I have MC68HC912 board, and if I'm not wrong, the crystal frequency is 32MHz.
And what is FLL?

Thanks

Message Edited by JamesWorthy on 03-15-200603:22 PM

0 Kudos

667 Views
bigmac
Specialist III

Hello James,

To find out the actual delay associated with a simple non-interrupt for() loop, it is probably easiest to measure it using the debugger/simulator, with the accumulated cycle count.  Just break both before entry to, and after exit from the delay function, and note the cycles difference.  Of course, you will still need to ascertain the bus frequency to relate this to a time value.

FLL = frequency lock loop, part of the clock generator module for some MCUs.

Regards,
Mac

 

0 Kudos