« Return to Thread: Problem initialise timer for 1µs cycle

Problem initialise timer for 1µs cycle

by folgli :: Rate this Message:

Reply to Author | View in Thread

Hello,

I have a problem with using the Timer on a MC9S12DP512. I want to create 1µ second cycles. Every µs I want to increment a variable, but I do not know how to initialise the timer, so that I get a timer interrupt every µs.
I hope that someone can help me.
Best regards

Here is my function to initialise the timer:
--------------------------------------------

void Init_Timers(void)
{
    TCTL2= 0;
    // TCTL2_OL3= 0;
    /*TCTL2_OM2= 0;
      TCTL2_OL2= 0;
      TCTL2_OM1= 0;
      TCTL2_OL1= 0;
      TCTL2_OM0= 0;
      TCTL2_OL0= 0;*/

    TIE&= ~(Bit5|Bit4|Bit3|Bit2|Bit1|Bit0); // C3I= 0, C2I= 0, C1I= 0, C0I= 0
                                            /*TIE_C2I= 0;
                                              TIE_C1I= 0;
                                              TIE_C0I= 0;*/

    TTOV&= ~(Bit5|Bit4|Bit3|Bit2|Bit1|Bit0); // TOV3= 0, TOV2= 0, TOV1= 0, TOV0= 0
                                             /*TTOV_TOV2= 0;
                                               TTOV_TOV1= 0;
                                               TTOV_TOV0= 0;*/
    //TTOV|= Bit6;
   
    TSCR2&= ~(Bit3); // TCRE= 0

    TIOS|= Bit5|Bit4|Bit3|Bit2|Bit1|Bit0; // IOS3= 1, IOS2= 1, IOS1= 1, IOS0= 1
                                          /*TIOS_IOS2= 1;
                                            TIOS_IOS1= 1;
                                            TIOS_IOS0= 1;*/
    //TIOS|= Bit6;
   
    TSCR1|= Bit7; // TEN= 1
    TSCR1&= ~(Bit6|Bit5); // TSWAI= 0, TSFRZ= 0
                          // TSCR1_TEN= 1;
                          // TSCR1_TSWAI= 0;
                          // TSCR1_TSFRZ= 0;

    PWMCTL&= ~(Bit3|Bit2); // PSWAI= 0, PFRZ= 0
                           // PWMCTL_PSWAI= 0;
                           // PWMCTL_PFRZ= 0;
    //TCTL2|= Bit4;
    //TC6|=  0x8000;
    PWMSDN= 0;

    ICSYS= 0;

    //MCCTL|= Bit6; // MODMC= 1
    TSCR2|= 7;      // PR2= 1, PR1= 1, PR0= 1
                    // TSCR2|= Bit2|Bit1;
                    // TSCR2_PR= 6;
    InitTimer1();
}

and here is my Timer ISR:
-------------------------

@interrupt void _ISR_Timer1(void)
{
    ISR_Timer1();
    gTimer1Count++;        
    TFLG1=  0b00000010;// C0F - Interrupt Flag: Clear Input Capture 1 Flag          
    if( IsTimer1Abgelaufen() )        
    {                                
    StartTimer1(1000);    
    }    
}

and here are some other functions I use (used in ISR):
------------------------------------------------------

void InitTimer1(void)
{
    //TC1= TCNT + 65249;
    TIE&= ~Bit1;            // C1I= 0
}

void ISR_Timer1(void)
{
    TIE&= ~Bit1;            // C1I= 0
    bTimer1Abgelaufen= YES;
    TFLG1|= Bit1;           // C1F= 1
}

void StartTimer1(unsigned int ticks)
{
    TC1= TCNT + ticks;      // 65249;
    TFLG1|= Bit1;           // C1F= 1
    bTimer1Abgelaufen= NO;
    bTimer1Laeuft= YES;
    TIE|= Bit1;             // C1I= 1
}




------------------------------------

Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/68HC12/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/68HC12/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:68HC12-digest@...
    mailto:68HC12-fullfeatured@...

<*> To unsubscribe from this group, send an email to:
    68HC12-unsubscribe@...

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/

 « Return to Thread: Problem initialise timer for 1µs cycle