【DSP学习】DSP28335定时器
发布时间:2026/10/28 19:06:27 锦皓数字建站

0 参考资料DSP自学视频顾老师 从入门到编写C2000——定时器1 原理1.1 CPU定时器的工作原理中断信号何时发出先设置 PRDH再把 PRDH 的值装载到 TIMH 中此后每经历一个 TIMCLK计数器就减 1直到减到 0 时发出中断信号。若还需继续计数则再次把 PRDH 的值装载到 TIMH 中重复上述过程。TIMCLK 信号何时发出先设置分频器 TDDRH再把该值装载到 PSCH 中此后每来一个系统时钟信号计数器就减 1直到减到 0 时输出一个 TIMCLK 信号。1.2 定时时间计算TIMCLK 的时间 1 TDR 分频值× 每个系统时钟信号的时间即 1/150M s定时器时间 1 PRD× TIMCLK 1 PRD×1/150M## 1.3 定时器中断其中 INT13、INT14 这两个中断的优先级相对较低。2 定时器跑马灯例子#includeDSP2833x_Device.h// DSP2833x Headerfile Include File#includeDSP2833x_Examples.h// DSP2833x Examples Include FileinterruptvoidISRTimer0(void);//定时器0的周期中断函数voidmain(void){// Step 1. Initialize System Control:// PLL, WatchDog, enable Peripheral Clocks// This example function is found in the DSP2833x_SysCtrl.c file.InitSysCtrl();//初始化// Step 2. Initialize GPIO初始化GPIO// This example function is found in the DSP2833x_Gpio.c file and// illustrates how to set the GPIO to its default state.InitGpio();//初始化GPIOInitCpuTimers();// 初始化定时器 For this example, only initialize the Cpu Timers// Step 3. Clear all interrupts and initialize PIE vector table:// Disable CPU interruptsDINT;// Initialize the PIE control registers to their default state.// The default state is all PIE interrupts disabled and flags// are cleared.// This function is found in the DSP2833x_PieCtrl.c file.InitPieCtrl();//初始化PIE中断// Disable CPU interrupts and clear all CPU interrupt flags:IER0x0000;IFR0x0000;// Initialize the PIE vector table with pointers to the shell Interrupt// Service Routines (ISR).// This will populate the entire table, even if the interrupt// is not used in this example. This is useful for debug purposes.// The shell ISR routines are found in DSP2833x_DefaultIsr.c.// This function is found in DSP2833x_PieVect.c.InitPieVectTable();// Interrupts that are used in this example are re-mapped to// ISR functions found within this file.EALLOW;// This is needed to write to EALLOW protected registersPieVectTable.TINT0ISRTimer0;//把定时器 0 中断向量重定向到我们自己写的ISRTimer0 也可以不用写这个直接去默认的中断函数里面写默认是函数在DSP2833x_Defaultsr.c中的interrupt void TINT0_ISR(void)EDIS;// This is needed to disable write to EALLOW protected registers// Enable CPU int1 which is connected to CPU-Timer 0IER|M_INT1;//使能CPU中断1// Enable TINT0 in the PIE: Group 1 interrupt 7PieCtrlRegs.PIEIER1.bit.INTx71;// Enable global Interrupts and higher priority real-time debug events:EINT;// Enable Global interrupt INTMERTM;// Enable Global realtime interrupt DBGM// Configure CPU-Timer 0, 1, and 2 to interrupt every second:// 150MHz CPU Freq, 1 second Period (in uSeconds)ConfigCpuTimer(CpuTimer0,150,1000000);//用的哪个中断时间频率150M,每次定时要的时间单位是微秒StartCpuTimer0();//启动定时器函数for(;;){}}接下来编写中断服务函数interruptvoidISRTimer0(void){if(status0){led1();}elseif(status1){led2();}elseif(status2){led3();}elseif(status3){led4();}elseif(status4){led5();}elseif(status5){led6();}status;if(status5)status0;// Acknowledge this interrupt to receive more interrupts from group 1PieCtrlRegs.PIEACK.allPIEACK_GROUP1;CpuTimer0Regs.TCR.bit.TIF1;CpuTimer0Regs.TCR.bit.TRB1;}voidled1(void){GpioDataRegs.GPADAT.bit.GPIO00;GpioDataRegs.GPADAT.bit.GPIO11;GpioDataRegs.GPADAT.bit.GPIO21;GpioDataRegs.GPADAT.bit.GPIO31;GpioDataRegs.GPADAT.bit.GPIO41;GpioDataRegs.GPADAT.bit.GPIO51;}...//写void led1(void)~void led6(void)
锦
锦皓数字建站
深耕本土企业品牌数字化升级,专注原创端正雅致商务官网,从视觉设计到稳定运维全程保驾护航。