AnsweredAssumed Answered

68HC908 Convert frequency to cycle duration doesn't work

Question asked by Holger Keil on Oct 16, 2014

Hi

 

I wanna convert a frequency in Hz to its cycle duration in µs. Example, frequency is 440, result shall be 2273

 

I tried this:

 

int round(double number){

  return (number >= 0) ? (int)(number + 0.5) : (int)(number - 0.5);

}

 

int FrqGetUs(int frq){

  double period;

  period=(1/frq)*1000000;

  return (round(period));

}

 

period=FrqGetUs(440);

 

but it doesn't work. In circuit, the µC appears to be caught in a reset-loop, and while in debugger, the µC freezes somewhere in ASM on the calculation of  period=(1/frq)*100000; debugger reports "Communication with target lost".

 

Whats wrong with it?

Original Attachment has been moved to: pdeclaration.h.zip

Original Attachment has been moved to: MCUinit.c.zip

Original Attachment has been moved to: MCUinit.h.zip

Original Attachment has been moved to: drehteller_v2.zip

Original Attachment has been moved to: lib_hc08c_device_include.zip

Outcomes