LM3S9b96 System Delay and Count Delay

Publisher:PositiveEnergyLatest update time:2016-07-30 Source: eefocusKeywords:LM3S9b96 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
When using the 9b96 chip, it is inevitable to use delays, for example, to make an LED flash. Therefore, the problem of delay time arises.
There are two common delay methods:
1. System delay: This is inherent in the 9b96 chip and can be solved using its API function, and the timing is relatively accurate.

Function prototype:
void SysCtlDelay (unsigned long ulCount)
Parameters:
ulCount is the number of iterations of the delay loop to be executed.
Description:
This function provides a method to generate a constant length delay. It is written in assembly to keep the delay consistent across toolchains
, thus avoiding the need to adjust the delay in the application based on the toolchain.
The loop takes 3 cycles/loop.
Returns:
None.

2. Counting delay: a rough delay method.

void Delay(unsigned long nCount)
{
for(; nCount != 0; nCount--);
}

 
Here is an example of blinking an LED:

#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/gpio.h"
#include "driverlib/sysctl.h"

/* For debugging PF1 <-> LED ---- --------------------------------------------------* /
#define LED_PERIPH SYSCTL_PERIPH_GPIOF
#define LED_PORT GPIO_PORTF_BASE
#define LED_PIN GPIO_PIN_1
#define LED_OFF 1 << 1
#define LED_ON ~(1 << 1) // Low level lights LED


void Delay(unsigned long nCount)
{
for(; nCount != 0; nCount--);
}


int main(void)
{
// Set the clocking to run directly from the crystal.
SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);

SysCtlPeripheralEnable(LED_PERIPH); // Enable the GPIO port where the LED is located

GPIOPinTypeGPIOOutput(LED_PORT, LED_PIN); // Set the LED pin to output

while (1)
{
GPIOPinWrite(LED_PORT, LED_PIN, LED_ON); // Click Turn on LED
Delay(0xfff); // The experimental delay is 2.5ms
GPIOPinWrite(LED_PORT, LED_PIN, LED_OFF); // Turn off LED
Delay(0xfff); // The experimental delay is 2.5ms

/*
GPIOPinWrite(LED_PORT, LED_PIN , LED_ON); // Turn on LED
SysCtlDelay(SysCtlClockGet() / 3000); // Accurate delay 1ms
GPIOPinWrite(LED_PORT, LED_PIN, LED_OFF); // Turn off LED
SysCtlDelay(SysCtlClockGet() / 3000); // Accurate delay 1ms
*/
}
}

 
The system clock is set to 16M, and the time of the two delay methods is measured with an oscilloscope:
Tip: When the system clock is 16M, you can directly use the delay time below.
            1) SysCtlDelay(SysCtlClockGet() / 3); // Accurate delay 1000ms
            2) SysCtlDelay(SysCtlClockGet() / 30); // Accurate delay 100ms
            3) SysCtlDelay(SysCtlClockGet() / 300); // Accurate delay 10ms
            4) SysCtlDelay(SysCtlClockGet() / 3000); // Accurate delay 1ms
            5) SysCtlDelay((SysCtlClockGet() / 3000) * 2); // Accurate delay 2ms
            6) Delay(0xf); // The experimental delay is 11us
            7) Delay(0xff); // The experimental delay is 160.7us
            8) Delay(0xfff); // The experimental delay is 2.5ms
            9) Delay(0xffff); // The experimental delay is 40.94ms
            a) Delay(0xfffff); // The experimental delay is 657.4ms
            b) Delay(0xffffff); // The experimental delay is 10.49s
Key points: 1) The counting delay time is related to the system clock frequency. If the system clock is set to 50M using PLL, the delay time becomes shorter.
           2) The system delay time has nothing to do with the system clock frequency. Even if the system clock is set to 50M using PLL, the delay time remains unchanged. 
 
 System clock  16M  50M
 Count delay: Delay(0xfff);  2.5ms  819us
 System delay: SysCtlDelay(SysCtlClockGet() / 3000);  1ms 1ms 

Recommendation: The system delay method is more convenient, and we can encapsulate it into a function with parameters.

//********************************************************************************
//
// Accurate delay nms
//
//********************************************************************************

void Delay(DWORD nms)
{
SysCtlDelay((SysCtlClockGet() / 3000) * nms);
}

 

Keywords:LM3S9b96 Reference address:LM3S9b96 System Delay and Count Delay

Previous article:LM3S9B96 UART print string function
Next article:LM3S9B96 IAR Create a new project

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号