硬件准备
ADSP-EDU-BF533:BF533开发板
AD-HP530ICE:ADI DSP仿真器
软件准备
Visual DSP++软件
硬件链接
接口功能介绍
ADSP-BF53x 上有 3 个通用定时器,每个定时器有三种模式:
- 脉冲宽度调制模式(PWM_OUT)
- 脉冲宽度计数捕获模式(WDTH_CAP)
- 外部事件模式(EXT_CLK)
接口寄存器说明
核心代码分析
*pTIMER0_CONFIG = 0x0019; //配置定时器为 PWM 模式
*pTIMER0_PERIOD = 0x00800000; //设置周期为 0x00800000 个系统时钟
*pTIMER0_WIDTH = 0x00400000; //设置脉宽为 0x00400000 个系统时钟
*pTIMER_ENABLE = 0x0001; //使能 Timer0
*pSIC_IAR0 = 0xffffffff;
*pSIC_IAR1 = 0xffffffff;
*pSIC_IAR2 = 0xfffffff4; //配置中断等级数据为 4
register_handler(ik_ivg11, TIMER0_ISR); //注册中断等级为 11,标识符为 TIMER0_ISR
*pSIC_IMASK = 0x00010000;
EX_INTERRUPT_HANDLER(TIMER0_ISR) //标识符为 TIMER0_ISR 的中断函数
{
*pTIMER_STATUS = 0x0001; //清除定时器中断标志
printf(“timer0 interrupt !\n”); //打印信息
}
代码实现功能
代码实现了将定时器配置为 PWM_OUT 模式,通过定时器中断来定时一个 0x00800000 个系统的时间长度,定时完成后,在中断内打印信息。
定时器没有单独的计时功能,所以如果计时,可以采用 PWM_OUT 模式,利用定时器中断来进行计时,同时在芯片的 TIMER0 管脚上,会有 PWM 波形输出。
完整源码
#include <cdefBF533.h>
#include <sys\exception.h>
EX_INTERRUPT_HANDLER(TIMER0_ISR);
void Set_PLL(unsigned int pmsel,unsigned int pssel)
{
unsigned int new_PLL_CTL;
*pPLL_DIV = pssel;
asm(“ssync;”);
new_PLL_CTL = (pmsel & 0x3f) << 9;
*pSIC_IWR |= 0xffffffff;
if (new_PLL_CTL != *pPLL_CTL)
{
*pPLL_CTL = new_PLL_CTL;
asm(“ssync;”);
asm(“idle;”);
}
}
void Init_EBIU(void)
{
*pEBIU_AMBCTL0 = 0x7bb07bb0;
*pEBIU_AMBCTL1 = 0xffc07bb0;
*pEBIU_AMGCTL = 0x000f;
}
void Init_SDRAM(void)
{
*pEBIU_SDRRC = 0x00000817;
*pEBIU_SDBCTL = 0x00000013;
*pEBIU_SDGCTL = 0x0091998d;
ssync();
}
void Init_Timers(void)
{
*pTIMER0_CONFIG = 0x0019;
*pTIMER0_PERIOD = 0x00800000;
*pTIMER0_WIDTH = 0x00400000;
*pTIMER_ENABLE = 0x0001;
}
void Init_Interrupts(void)
{
*pSIC_IAR0 = 0xffffffff;
*pSIC_IAR1 = 0xffffffff;
*pSIC_IAR2 = 0xfffffff4;
register_handler(ik_ivg11, TIMER0_ISR);
*pSIC_IMASK = 0x00010000;
}
EX_INTERRUPT_HANDLER(TIMER0_ISR)
{
*pTIMER_STATUS = 0x0001;
printf(“timer0 interrupt !\n”);
}
void main(void)
{
Set_PLL(16,4);
Init_EBIU();
Init_SDRAM();
Init_Timers();
Init_Interrupts();
while(1);
}