Hi! I'm trying to use timer 4 to generate an 1MHz interrupt to count microsseconds precisely, however it's not working well. Here's my code:
//Timer 4 Setup function void Timer4_init(void) { //******************** Timer4, channel // Timer 4 channel 0 compare value. CLKCONCMD = (CLKCONCMD & ~CLKCON_TICKSPD) | CLKCON_TICKSPD_32M; T4IE = 1; /*************************************************************************** * Timer 4 setup * * Timer 4 channel 0 compare value. Initiates the Timer terminal count value * to 224. This value is reseted at each Timer compare match interrupt. */ T4CC0 = e0;//224 -> 256 - (32MHz/(Prescaler*Target_Frequency)): Target_frequency=1MHz /* Timer 4 channel 0 (T4CCTL0) configuration: * - Channel 0 interrupt enabled. * - Compare mode. */ T4CCTL0 = T4CCTLn_IM | T4CCTLn_MODE; /* Timer 4 control (T4CTL) configuration: * - Prescaler divider value: 1. * - Modulo mode. * The Timer is also cleared and started. */ T4CTL = T4CTL_DIV_1 | T4CTL_MODE_MODULO | T4CTL_CLR | T4CTL_START; } //Interrupt function #pragma vector = T4_VECTOR __interrupt void t4_isr(void) { // // Clears the module interrupt flag. T4OVFIF = 0; static uint16 micros = 0; micros ++; // Clears the CPU interrupt flag. T4IF = 0; }