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

Issues with using timer0, timer1 and timer7, interrupt of timer7 never occurs

Hello everyone,
I've been looking some infos in Inet, but I didnt really find what I was looking for.
I am working with a XC164CS32F, for my project I need various timers.
Quick explanation:
Timer0 : timer for my logical automat (set at 100ms)
Timer1 : timer for picking values from a couple of sensors (set at 50 ms).
Timer7 : I would like to generate a simple PWM signal, but as nothing was occuring, Im just increasing a dummy global variable (I will try to do the PWM on my own after being sure that the timer7 is really working!).

As far as I have debugged (and it seems to work pretty good), timer0 and 1 work perfectly. Timer7 just do not generate any interruption. My first guess was that the vector address was wrong, but it doesnt seem so. I'm using the interrupt #61 (I tried also with the 0x3D hexa value.. though I do not see the difference).

I copy/paste the code that I have for timer0, timer1 and timer7.
I would gladly appreciate some help, I'm rather stucked for now!
------------------------------
TIMER0

// Initialisieren ///////////////////////////////////////////////////////////////
int timer0_Init(void)
{
        CC1_IOC = 0;            // IO Control
        CC1_T01CON = 1;         // Timer0/1 Control (16fach Prescaler)
        CC1_T0 = 0;                     // Timer0 Register
        CC1_T0REL = 0;          // Timer0 Reloadregister

        CC1_T0IC = 0x007C;  // Timer0 Interruptpriorität

        return 0;
}

// Timer0 Überlauf ISR //////////////////////////////////////////////////////////
void timer0_ISR(void) interrupt CC1_T0INT
{
        automat();
}

void timer0_Frequenz_setzen(float T0_frequenz)
{
        unsigned int TimerWert;

        TimerWert = 0xFFFF - ((1/T0_frequenz) / 0.0000004);        // min. 40 ( 40Hz )

        CC1_T0 = TimerWert;             // Timer0 Register
        CC1_T0REL = TimerWert;  // Timer0 Reloadregister
}


-----------------
TIMER1

// Initialisieren ///////////////////////////////////////////////////////////////
int timer1_Init(void)
{
        CC1_IOC = 0;            // IO Control
        CC1_T1 = 0;                     // Timer1 Register
        CC1_T1REL = 0;          // Timer1 Reloadregister

        CC1_T1IC = 0x007F;  // Timer1 Interruptpriorität MUSS niedrieger als Timer0 (0x007C) sein, d.H. Wert größer

        return 0;
}

// Timer1 Überlauf ISR //////////////////////////////////////////////////////////
void timer1_ISR(void) interrupt CC1_T1INT
{
        sendFrame(MEASURE, 0);  // TYPE OF FRAME = MEASURE
}

// Timer1 Frequenz einstellen ///////////////////////////////////////////////////
// Parameter: Word (Frequenz) ///////////////////////////////////////////////////
void timer1_Set_Frequency(unsigned int ui_frequency)
{
        unsigned int ui_timervalue;
                                                                //CPU-Frequenz/Prescaler
        ui_timervalue = (unsigned int)(0xFFFF - (1250000/ui_frequency));
                                                                // -> Minimum 20Hz!

        CC1_T1 = ui_timervalue;         // Timer1 Register
        CC1_T1REL = ui_timervalue;      // Timer1 Reloadregister
}


-------------------
TIMER7

// Initialisieren ///////////////////////////////////////////////////////////////
int timer7_Init(void)
{
        CC2_IOC = 0;            // IO Control
        CC2_T78CON = 1;         // Timer7/8 Control (16fach Prescaler)
        CC2_T7 = 0;                     // Timer7 Register
        CC2_T7REL = 0;          // Timer7 Reloadregister

        CC2_T7IC = 0x007F;  // Timer7 Interruptpriorität

        return 0;
}

void timer7_Reset(void) {
        timer7_Stop(); // stop timer7
        t7_ms_counter = 0;
}


// Timer1 Überlauf ISR //////////////////////////////////////////////////////////
void timer7_ISR(void) interrupt 61
{
      bluenicecom_Send_String("! ");
        t7_ms_counter++;
}


// Timer1 Frequenz einstellen ///////////////////////////////////////////////////
// Parameter: Word (Frequenz) ///////////////////////////////////////////////////
void timer7_Set_Frequency(unsigned int ui_frequency)
{
        unsigned int ui_timervalue;
                                                                //CPU-Frequenz/Prescaler
        ui_timervalue = (unsigned int)(0xFFFF - (1250000/ui_frequency));
                                                                // -> Minimum 20Hz!

        CC2_T7 = ui_timervalue;         // Timer7 Register
        CC2_T7REL = ui_timervalue;      // Timer7 Reloadregister
}

--------------------
I start my timers with this method:

#define timer7_Start() CC2_T78CON_T7R = 1; PSW_IEN = 1;
#define timer7_Stop() CC2_T78CON_T7R = 0; PSW_IEN = 0;
#define CC2_T7INT 0x3D                  // Interruptvektor

---------------------------------------------------- I'm a beginner in the field of microcontroller programming, I reckon my code is not optimized but well.. As said before, timer0 and timer1 work really good. But I just do know why timer7 doest not :( Any guess?

0