AnsweredAssumed Answered

Delay function - the microsecond one doesn't work!!!

Question asked by Rizky Prasetya on Mar 10, 2011
Latest reply on Mar 29, 2011 by Jim Potteabaum

Hi all,

 

I am a beginner to freescale microcontrollers. Right now i'm trying to make a delay function that can be used to build an LCD function. I have succeeded in making a millisecond delay, but for some reasons i don't understand, the microsecond delay is not working.... seems like it's trapped. BTW, i check it by turning a led on and turn it off while at the same time turning another led after delaying it for 1000 us, and then turn it off and turn the first one after the same delay time. It all done in a while(1) loop. To my eyes, it should look as if the two leds are turned on.

 

here is my code

 

----on main module-------------

 

extern uint16_t flag;

void delay_ms(uint32_t delay) {
  TI1_Enable();
  TI1_EnableEvent();
  TI1_SetPeriodMode(0);
  while(delay!=0){
    if(flag){
      delay--;
      flag = 0;
    }
  }
  TI1_DisableEvent();
  TI1_Disable();
}

void delay_us(uint32_t delay) {
  TI1_Enable();
  TI1_EnableEvent();
  TI1_SetPeriodMode(1);
  while(delay!=0){
    if(flag){
      delay--;
      flag = 0;
    }
  }
  TI1_DisableEvent();
  TI1_Disable();
}

 

I use TimerInt with runtime setting type : from list of values. Mode 0 has 1ms period and mode 1 has 1us period. In addition, i use TPM12 for periodic interrupt source

 

 

-----------On Event------------------------------

uint16_t flag = 0;
void TI1_OnInterrupt(void)
{
  /* Write your code here ... */
  flag = 1;
 
}

 

FYI, i am using CodeWarrior v6.3 and MC9S08AW60

 

Thanks in advance

Outcomes