This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Timer0 Interrupt does not update

Hi Guys,

I am simulating delayed pulses for a stepper motor, and I am using timer0 on MCB2300. I setup my interrupt timer and I want it to be updated every time a pulse is fired. When I simulated my code it does not look the timer0 gets updated at all: Timer0 retain the initial value I set it to which is 1second all the time.

Below is copy of my code, please advise on how I can get the timer updated and why it does not update.

//source code:

volatile unsigned int delay_constant;

/* Function that turns on requested LED */
void LED_On (unsigned int num) { FIO2SET = (1 << num);
}

/* Function that turns off requested LED */
void LED_Off (unsigned int num) { FIO2CLR = (1 << num);
}

/* Function that initializes LEDs */
void LED_Init(void) {

PINSEL10 = 0; /* Disable ETM interface, enable LEDs */ FIO2DIR = 0x000000FF; /* P2.0..7 defined as Outputs */ FIO2MASK = 0x00000000;
}

__irq void T0_IRQHandler (void) {

int i;

LED_On (0x07);

for( i=0; i<100; i++) { ; } LED_Off (0x07); T0IR = 1; /* Clear interrupt flag */ VICVectAddr = 0; /* Acknowledge Interrupt */

}
float fastsqrt(float val) { long tmp = *(long *)&val; tmp -= 127L<<23; /* Remove IEEE bias from exponent (-2^23) */ /* tmp is now an appoximation to logbase2(val) */ tmp = tmp >> 1; /* divide by 2 */ tmp += 127L<<23; /* restore the IEEE bias from the exponent (+2^23) */ return *(float *)&tmp;
}

void timer0_initialize (void){

T0MR0 = delay_constant; /* 1msec = 12000-1 at 12.0 MHz */
T0MCR = 3; /* Interrupt and Reset on
T0TCR = 1; /* Timer0 Enable */
VICVectAddr4 = (unsigned long ) T0_IRQHandler; /* Set Interrupt Vector */
VICVectCntl4 = 15; /* use it for Timer0 Interrupt */
VICIntEnable = (1 << 4); /* Enable Timer0 Interrupt */
}

int main (void)
{

float temp0; static float temp1, temp2, temp3; unsigned int step=0; unsigned int denom;

delay_constant=12000000;

LED_Init(); /* LED Initialization */

/* Enable and setup timer interrupt, start timer */ timer0_initialize();

/*C0 equation: C0=frequency*sqrt(2*motor_step_angle/angular_accel)*/ temp0= motor_step_angle+motor_step_angle; temp0=temp0/angular_accel; temp0=fastsqrt(temp0); temp0=temp0*frequency; step++;

do{ /*Cn equation: Cn= (Cn-1)-(2*Cn-1/(4*step+1))*/ denom=(step<<2)+1; temp1=(temp0+temp0)/denom; temp0=temp0- temp1; step++;

/* normalization so that delays are obtained in Microseconds */ temp3=temp0*1000000; temp3=ceil(temp3/frequency); delay_constant=temp3;

}while(step> 0 && step<31);

}