AnsweredAssumed Answered

clock issue

Question asked by vinod Karuvat on Jun 26, 2014
Latest reply on Jun 26, 2014 by vinod Karuvat

Hello Friends,


I am playing with my KL05 FRDM board. I did not modify any of the clock MCG registers. I believe, if I leave them as it is it will give me a clock of 20.97M.

So ,mathematically speaking each instruction should take about (1/20.97M) = 50uSecs. As an expt I tried the following code wherein I toggle a pin with a for loop sandwiched in the middle ( with a single iteration in the for loop). Now, when I check with my probe , I get almost 1.9uSecs as the time taken, which is ridiculously high.


Could anyone point where I am doing wrong. I think, something in the MCG registers is not working. I will look into that as well. ANy pointers will be appreciated.


My code -


#include "derivative.h" /* include peripheral declarations */


    int main(void)


            int tempCount,tempCount2 = 0;

            // clocking //

            SIM_SOPT2 |= 0x01000000;      // clock sel for the timer0 //

            SIM_SCGC5 |= 0x00000400;      // gating of clock //

            SIM_SCGC6 |= 0x01000000;      // gating of timer //

            PORTB_PCR8 |= 0x00000100;    // alternative pin mux selection //

            GPIOB_PDDR |= 0x00000100;    // pin direction //

            TPM0_CONF |= 192;                        // counter runs in debug mode as well //

            TPM0_MOD = 1309;                        // period count //


                GPIOB_PSOR |= (1<<8);

                for(tempCount = 0;tempCount <= 1;tempCount++);

                GPIOB_PCOR |= (1<<8);