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

2019-03-24 12:02发布

为什么使用ON-CHIP ROM LED 闪烁时间变快了。求助。谢谢

程序如下:

#include <stdint.h>
#include <stdbool.h>
#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条回答
yanxinboy
1楼-- · 2019-03-24 18:00
在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

chenzhufly
2楼-- · 2019-03-24 20:06
< :TI_MSP430_内容页_SA7 -->   自问自答!

一周热门 更多>

相关问题

    相关文章