您好!
如何在计时器中实现"20"纳秒延迟?
在示例时间代码中进行20纳秒的转换以用于我们的测试。 下面给出了代码。
#包含
#包含
#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/debug.h"
#include "driverlib/fpu.h"
#include "driverlib/gpio.h"
#include "driverlib/interrupt.h"
#include "driverlib/pin_map.h"
#include "driverlib/rom.h"
#include "driverlib/rom_map.h"
#include "driverlib/sysctl.h"
#include "driverlib/timer.h"
#include "driverlib/uart.h"
#include "utils/uartstdio.h"
//以 Hz 为单位的系统时钟速率。
uint32_t g_ui32SysClock;
//包含 UART 上显示的中断指示器的当前值的标志。
uint32_t g_ui32Flags;
//配置 UART 及其引脚。 这必须在 UARTprintf()之前调用。
空 ConfigureUART (void)
{
MAP_SysCtlPeripheralEnable (SYSCTL_Periph_GPIOA);
MAP_SysCtlPeripheralEnable (SYSCTL_Periph_UART0);
MAP_GPIOPinConfigure (GPIO_PA0_U0RX);
MAP_GPIOPinConfigure (GPIO_PA1_U0TX);
MAP_GPIOPinTypeUART (GPIO_PORTA_BASE、GPIO_PIN_0 | GPIO_PIN_1);
UARTStdioConfig (0115200、g_ui32SysClock);
}
//第一个定时器中断的中断处理程序。
空 Timer0IntHandler (void)
{
字符圆锥;
uint32_t Load_Value = 0U、Match_Value = 0U、TimConfi Clock_Value = 0U;
MAP_TimerIntClear (TIMER0_BASE、TIMER_TIMA_TIMEOUT);
Tim惊 悚 Clock_Value = MAP_TimerClockSourceGet (TIMER0_BASE);
Load_Value = MAP_TimerLoadGet (TIMER0_BASE、TIMER_A)
Match_Value = MAP_TimerMatchGet (TIMER0_BASE、TIMER_A);
HWREGBITW (&g_ui32Flags、0)^= 1;
GPIOPinWrite (GPIO_PORTN_BASE、GPIO_PIN_0、g_ui32Flags);
Map_IntMasterDisable ();
Cone = HWREGBITW (&g_ui32Flags、0)? '1':'0';
UARTprintf("\r ");
UARTprintf ("\RT1:%c"、cone);
UARTprintf ("\rSysClock:%d"、g_ui32SysClock);
UARTprintf ("\rTimerClock:%d"、Tim52 Clock_Value);
UARTprintf ("\rLoadValue:%d"、Load_Value);
UARTprintf ("\rMatchValue:%d"、Match_Value);
Map_IntMasterEnable ();
}
//第二个定时器中断的中断处理程序。
空 Timer1IntHandler (void)
{}
//该示例应用演示了如何使用计时器来生成周期性中断。
int main (空)
{
g_ui32SysClock = MAP_SysCtlClockFreqSet ((SYSCTL_XTAL_25MHz |
SYSCTL_OSC_MAIN |
SYSCTL_USE_PLL |
SYSCTL_CFG_VCO_240)、120000000);
ConfigureUART();
UARTprintf ("\n 定时器示例\n");
MAP_SysCtlPeripheralEnable (SYSCTL_Periph_GPION);
MAP_GPIOPinTypeGPIOOutput (GPIO_PORTN_BASE、GPIO_PIN_0);
MAP_SysCtlPeripheralEnable (SYSCTL_Periph_TIMER0);
MAP_TimerConfigure (TIMER0_BASE、TIMER_CFG_PERIOD_UP);
MAP_TimerLoadSet (TIMER0_BASE、TIMER_A、(g_ui32SysClock / 60000000));
Map_IntMasterEnable ();
MAP_IntEnable (INT_TIMER0A);
MAP_TimerIntEnable (TIMER0_BASE、TIMER_TIMA_TIMEOUT);
MAP_TimerEnable (TIMER0_BASE、TIMER_A);
while (1)
{
}
}
