This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Timer is not working with clock source from PIOSC in interrupt Mode



in my program first i am setting the system clock to 120 MHz then, i am enabling the GPIO Module to blink USER LED and after that i am enabling the Timer Module.in this case everything is working fine and Corresponding Timer handler is also getting called and USER LED is blinking according to the Timer Interval set.


But when i am not setting the System clock to 120 MHz then by default it will get the clock from PIOSC which is 16 MHz.in this case if i am enabling the GPIO Module to blink USER LED and after that i am enabling the Timer Module then, the timer is not working and USER LED is not blinking.

But if i am enabling the Timer Module First and after that if i am enabling the GPIO Module then everything is working fine with both 16 and 120 MHz.

Can any one tell me the reason behind it?

  • Hi Jeke,

    I add similar problems because i forgot to add a 3-10 SysCtlDelay after SysCtlEnable

  • Hello Jeke,

    Clarification required on the fact that it is not working. Is it getting a Bus Fault?

    Addition to Luis Post: A better way is to use while(!SysCtlPeripheralReady(PERIPH)); as this will work for all frequency and eliminates the need of a delay loop.

    Regards

    Amit

  • Hi Amit,

    Below is my program that i used

    #include <stdint.h>
    void BlinkLEDbyTimer(void);
    void Timer0InterruptHandler(void);
    void Timer1InterruptHandler(void);
    int main(void) {
        BlinkLEDbyTimer();
        return 0;
    }
    uint32_t
    CPUcpsie(void)
    {
        //
        // Read PRIMASK and enable interrupts.
        //
        __asm("    mrs     r0, PRIMASK\n"
              "    cpsie   i\n"
              "    bx      lr\n");
        return(0);
    }
    void BlinkLEDbyTimer(void)
    {
    
    	//Enable the GPIO PORTN
    	(*((volatile uint32_t *)(0x400FE608)))=0x00001000;
    
    	//Configure PORTN PIN0 AND PIN1 as output
    	(*((volatile uint32_t *)(0x40064400)))=0x00000003;
    
    	//configure PORTN PIN0 AND PIN1 as Digital enable
    	(*((volatile uint32_t *)(0x4006451C)))=0x00000003;
    
    	// Enable Timer 0 and Timer1 Module
    	(*((volatile uint32_t *)0x400FE604))|=0x00000003;
    
    	//make sure Timer 0 and Timer 1 are disabled before changing its configuration
    	if(((0x00) == ((*((volatile uint32_t *)0x4003000c)) & 0x01))
    	&& ((0x00) == ((*((volatile uint32_t *)0x4003100c)) & 0x01)))
    	{
    		 //clear all the bits of the Configuration register for Timer 0  and Timer 1
    		 (*((volatile uint32_t *)0x40030000))=0x00000000;
    		 (*((volatile uint32_t *)0x40031000))=0x00000000;
    
    		 //configure Timer 0 and Timer 1 to count up
    		 (*((volatile uint32_t *)0x40030004))|=0x00000010;
    		 (*((volatile uint32_t *)0x40031004))|=0x00000010;
    
    		 //configure Timer 0 and Timer 1 for periodic
    		 (*((volatile uint32_t *)0x40030004))|=0x00000002;
    		 (*((volatile uint32_t *)0x40031004))|=0x00000002;
    
    		 //Configure the Timer 0 and Timer1 for Timeout Interval of 1Sec and 2Sec respectively
    		 (*((volatile uint32_t *)0x40030028))=16000000;
    		 (*((volatile uint32_t *)0x40031028))=32000000;
    
    		 //Enable processor interrupt
    		 CPUcpsie();
    
    		 //Register interrupt for Timer 0 and Timer 1 in NVIC
    		 (*((volatile uint32_t *)0xE000E100))|=0X00280000;
    
    		 //enable interrupt for Timer 0 and Timer 1(needed only for interrupt mode)
    		 (*((volatile uint32_t *)0x40030018))|=0X00000001;
    		 (*((volatile uint32_t *)0x40031018))|=0X00000001;
    	}
    
    	 //Enable timer 0 and timer1 to start the timer
    	 (*((volatile uint32_t *)0x4003000C))|=0X00000001;
    	 (*((volatile uint32_t *)0x4003100C))|=0X00000001;	
    	 while(1);		 
    }
    
    void Timer0InterruptHandler(void)
    {
    	//clear the status flag for timer 0
    	(*((volatile uint32_t *)0x40030024))|=0X00000001;
    	//Blink LED D1
    	(*((volatile uint32_t *)(0x40064008)))^=0x02;
    }
    
    void Timer1InterruptHandler(void)
    {
    	//clear the status flag for timer 1
    	(*((volatile uint32_t *)0x40031024))|=0X00000001;
    	//blink LED D2
    	(*((volatile uint32_t *)(0x40064004)))^=0x01;
    }

    Thanks,
    Jeke.

  • Hi,

    Your program structure is not good - you should not exit from main to landscape - because unlike the PC, the micro controller does not have an operating system. Your code should be:

    int main(void) {
        BlinkLEDbyTimer();
        while(1){
        ;
        }
        return 0;
    }

  • Hello Petrei

    Good catch (I was about to miss it). Also the poster code shows clearly that there is no waiting for the clocks to start which could be the issue Kel also mentioned

    Regards

    Amit

  • Amit Ashara said:
    could be the issue Kel also mentioned

    Perhaps you meant my friend, Luis?  (no overflowing signature area overwhelmed content - thus Luis was the more likely suspect...)

    I would have answered w/similar observations - but eyes crossed/watered reading  the nonsensical "Direct Register" - so unnecessary - so wasteful of time/effort for simple peripheral set-up/init...

  • Hello cb1,

    Yes. I meant Luis. And also did notice the Direct Register access as used by the poster may be the cause of the issue. As we update the documents/examples, the main emphasis is being put on SysCtlPeripheralReady to make sure that we do not end up in the same Fault condition posts-over-posts

    Regards

    Amit