DSP

28335之定时器原理

2019-07-13 11:44发布

单片机的定时器就很简单,28335的定时器也没难道那里去。参考文章《https://blog.csdn.net/hmf1235789/article/details/51891997》涉及经常使用的就一个time0定时器,其他两个不用。用的话,原理也一样。涉及time0的寄存器也就5个:TDDRH:TDDR                   PSCH:PSC                                               PRDH :PRD                      TIMH:TIM

还有一个crl寄存器,主要管理中断控制类的,在此不细说。看上边4个寄存器,其实用得就两个,而且一个还经常是0.TDDRH:TDDR  :作用将系统时钟分频(降低频率),供定时器用。经常设置为0PRDH :PRD :查数用的
PSCH:PSC  和  TIMH:TIM分别装载以上连个寄存器的数据;PSCH:PSC 减到0之后发出一个时钟信号给TIMH:TIM,然后自动装载TDDRH:TDDR。TIMH:TIM 减到0之后,发出一个中断信号,然后自动装载PRDH :PRD

如何计算:参考《手把手教你学DSP2812》里边的解释很清晰
提醒:CpuTimer0.RegsAddr = &CpuTimer0Regs;是什么?

(cputime.c的代码)struct CPUTIMER_VARS CpuTimer0; // CpuTimer 1 and CpuTimer2 are used by DSP BIOS & other RTOS. Comment out if using DSP BIOS or other RTOS. struct CPUTIMER_VARS CpuTimer1; struct CPUTIMER_VARS CpuTimer2; //--------------------------------------------------------------------------- // InitCpuTimers: //--------------------------------------------------------------------------- // This function initializes all three CPU timers to a known state. // void InitCpuTimers(void) { // CPU Timer 0 // Initialize address pointers to respective timer registers: CpuTimer0.RegsAddr = &CpuTimer0Regs; // Initialize timer period to maximum: CpuTimer0Regs.PRD.all = 0xFFFFFFFF; // Initialize pre-scale counter to divide by 1 (SYSCLKOUT): CpuTimer0Regs.TPR.all = 0; CpuTimer0Regs.TPRH.all = 0; // Make sure timer is stopped: CpuTimer0Regs.TCR.bit.TSS = 1; // Reload all counter register with period value: CpuTimer0Regs.TCR.bit.TRB = 1; // Reset interrupt counters: CpuTimer0.InterruptCount = 0;cputime.h的代码
struct CPUTIMER_REGS { union TIM_GROUP TIM; // Timer counter register union PRD_GROUP PRD; // Period register union TCR_REG TCR; // Timer control register Uint16 rsvd1; // reserved union TPR_REG TPR; // Timer pre-scale low union TPRH_REG TPRH; // Timer pre-scale high }; //--------------------------------------------------------------------------- // CPU Timer Support Variables: // struct CPUTIMER_VARS { volatile struct CPUTIMER_REGS *RegsAddr; Uint32 InterruptCount; float CPUFreqInMHz; float PeriodInUSec; }; //--------------------------------------------------------------------------- // Function prototypes and external definitions: // void InitCpuTimers(void); void ConfigCpuTimer(struct CPUTIMER_VARS *Timer, float Freq, float Period); extern volatile struct CPUTIMER_REGS CpuTimer0Regs; extern struct CPUTIMER_VARS CpuTimer0; // CpuTimer 1 and CpuTimer2 are reserved for DSP BIOS & other RTOS. Comment out CpuTimer1 and CpuTimer2 if using DSP BIOS or other RTOS extern volatile struct CPUTIMER_REGS CpuTimer1Regs; extern volatile struct CPUTIMER_REGS CpuTimer2Regs; extern struct CPUTIMER_VARS CpuTimer1; extern struct CPUTIMER_VARS CpuTimer2;