AnsweredAssumed Answered

S08RN TIMER

Question asked by Robin S on Jun 16, 2014
Latest reply on Jul 15, 2014 by Arpita Agarwal

Hi All,

 

please can anybody help me .

 

In the following code i am using S08RN8 Flex Timer and  Just switching ON and OFF the PORTB4 .

 

My problem is when i am flashing the code in  micro controller (S08RN8) and Testing the code on Oscilloscope i am getting the switching Total time ON n OFF 11.34 msec and as soon as I Reset the power supply of controller the Total time I am getting 12.34 msec i.e. around 1msec more,please can anybody tell me what is the reason behind that?

 

   struct _Timer_

    {

      unsigned  int active;                                         // FRA Timer, zur zeitlichen Steuerung des Wischens, 100µs Auflösung

    };

    typedef struct _Timer_ Timer;

 

 

  // prototypes

 

    void                      main(void);

    static void             startTimer(void);

    static void             TMR_CNTRL(void);

    void                      REFRESH_WDT(void);

    void                      delay(unsigned int k);

 

 

 

 

void main(void)

 

    {

   

         DisableInterrupts;

 

       __RESET_WATCHDOG();                                                            // Watchdog Timer is enabled : is having 1 Khz Internal Default clock and Default Values of  appx.4 msec but

                                                                                                                                

        ICS_C1 = 0x04;                                                                         // internal reference clock to FLL and FLL is generating 16000-20000 Khz  ; Ref. Freqeuncy  is set at 31250-39250 Hz * 512 = Appx.16-20 Mhz

        ICS_C2 = 0x00;                                                                        // BDIV = 00, Freq is now 16-20Mhz

     //  ICS_C3 = 0x80;                                                                      //Trimmed Value of Internal System Frequency

 

        PORT_PTBOE_PTBOE4= 1;                                   // PortB4 as Output enable

        PORT_PTBD_PTBD4 = 0;                                        // Initilise PortB4

  

        timer_.active = 0;                                                       // Initilise Active Timer

 

        startTimer();                                                                 // Start Flex Timer

 

        timer_.active=1;                                                      // Start Active timer

        while(1)

 

          {

            TMR_CNTRL();                                                                     // Increment Active Timer

            REFRESH_WDT();                                                            // Refresh Watchdog Timer

 

                 if(timer_.active >= 1850){timer_.active=1;}                                       //Restart Timer                                   

           

            

                else if(timer_.active >=1825 ){PORT_PTBD_PTBD4 = 0;}              //Switch OFF PortB4

                else if(timer_.active >= 1225) {PORT_PTBD_PTBD4 = 1;}                 //Switch ON PortB4

    

 

                else if(timer_.active >= 625){PORT_PTBD_PTBD4 = 0;}                      //  Switch OFF PortB4                                                                            

                else if(timer_.active >= 25)  {PORT_PTBD_PTBD4 = 1;}                      // Switch ON PortB4                               

       

       

        }

        }

 

 

static void startTimer(void)

    {

        FTM0_CNT = 0x0000;

        FTM0_MOD = 0xFFFF;                                                               // The FTM Counter is Free Running Counter by Defining MODH:L=0x0000 or MODH:L=0xFFFF;

 

        FTM0_SC  =  0x0F;                                                                     //CPWMS=0; Counter Mode;System Clock (Deafult) 16  Mhz, FEI mode Default, Prescaler Factor 1:128    

    }

 

  void REFRESH_WDT(void)

    {

   

        DisableInterrupts;                                          //  Refreshing the Watchdog 

 

        delay(5);                                                    // small Delay before writing refresh word

        WDOG_CNT   = 0xA602;                                        // write the 1st refresh word

        WDOG_CNT   = 0xB480;                                            //write the 2nd refresh word to refresh counter

 

    //    EnableInterrupts;                                            //Disable interrupt

   

    }

 

 

static void TMR_CNTRL(void)

    {

        unsigned int x = 0;

 

        x = FTM0_CNT ;                                                                    // Initilise FTM0 Counter or  Flex Modulo Timer

                                                   

        FTM0_CNT = FTM0_CNT - x;

 

        if(timer_.active)

        {

            if((timer_.active + x) < (unsigned int)0xFFFF)                                // If Active counter is less than 0XFFFF ,increment timer.active

            {

              timer_.active = timer_.active + x;

            }

        }

 

    }

 

 

void delay(unsigned int k) {

         unsigned int delay ;

         for (delay=0;delay<k;delay++);

       }

Outcomes