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.

Delay and actual clock cycle



Hi everyone !

I wanna blink LED ON/OFF with one second delay, one second ON and one second OFF. I wrote the following code, why should i use timer or system for the same purpose. coul anyone explain logically.

here is my code:


int main() {
volatile uint32_t loop;
SysClk=SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |SYSCTL_OSC_MAIN|SYSCTL_USE_PLL|SYSCTL_CFG_VCO_480),
					  	  	  	  	  	  	  	  	  	  	  	  	  	 120000000);

	 SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION);
	 GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE,GPIO_PIN_0);

	 for (loop=0; loop<120000000; loop++){

		 GPIOPinWrite(GPIO_PORTN_BASE,GPIO_PIN_0,1);
	 }
	 for (loop=0; loop<120000000; loop++){

	 		 GPIOPinWrite(GPIO_PORTN_BASE,GPIO_PIN_0,0);
	 	 }


return 0;
}
  • Hello Haroon,

    If the code is only going to blink the LED, then there is no need to use a timer. However in a parallel executing code a blocking statement as above would not meet any system performance, which would require the use of a timer or a periodic interrupt source to be able to invoke the blinking of LED's.

    Regards
    Amit