[求助] [我问你答】 为什么使用片上ROM LED 闪烁变快了。

yanxinboy   2013-12-4 20:27 楼主
为什么使用ON-CHIP ROM LED 闪烁时间变快了。求助。谢谢

程序如下:

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

#define RED_LED   GPIO_PIN_1
#define BLUE_LED  GPIO_PIN_2
#define GREEN_LED GPIO_PIN_3

int
main(void)
{
    //
    // Setup the system clock to run at 50 Mhz from PLL with crystal reference
    //
    ROM_SysCtlClockSet(SYSCTL_SYSDIV_4|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|
                    SYSCTL_OSC_MAIN);
    //
    // Enable and configure the GPIO port for the LED operation.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
    ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, RED_LED|BLUE_LED|GREEN_LED);
    //
    // Loop Forever
    //
    while(1)
    {
        //
        // Turn on the LED
        //
        ROM_GPIOPinWrite(GPIO_PORTF_BASE, RED_LED|BLUE_LED|GREEN_LED, RED_LED);
        //
        // Delay for a bit
        //
        ROM_SysCtlDelay(5000000);
        //
        // Turn on the LED
        //
        ROM_GPIOPinWrite(GPIO_PORTF_BASE, RED_LED|BLUE_LED|GREEN_LED, BLUE_LED);
        //
        // Delay for a bit
        //
        ROM_SysCtlDelay(5000000);
ROM_GPIOPinWrite(GPIO_PORTF_BASE, RED_LED|BLUE_LED|GREEN_LED, GREEN_LED);
        //
        // Delay for a bit
        //
        ROM_SysCtlDelay(5000000);
    }
}

回复评论 (2)

在TI 找到答案。不错。

The actual answer here is likely to do with the fact that ROM is always accessed in a single cycle whereas flash may have different numbers of wait states depending upon the system clock frequency in use and the part you are running the code on. To further complicate matters, different parts have different instruction prefetching capabilities. Adding this all up, you will find that the nominal 3 cycle loop inside SysCtlDelay() may not take clock 3 cycles to run when you run it from flash.

We should update the function documentation to make this clear but, if you really want 3 cycle delay loops, you should use ROM_SysCtlDelay() instead (as you found out). Note that even this will be affected by interrupt latencies so the accuracy will be determined by the longest ISR in your system.

具体见:
http://e2e.ti.com/support/microc ... f/908/t/256106.aspx

点赞  2013-12-5 21:11
  自问自答!
生活就是油盐酱醋再加一点糖,快活就是一天到晚乐呵呵的忙 =================================== 做一个简单的人,踏实而务实,不沉溺幻想,不庸人自扰
点赞  2013-12-5 22:04
电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 京公网安备 11010802033920号
    写回复