DSP时钟
1) INTOSC1(10MHz)
内部时钟源1(INTOSC1),此时钟提供给看门狗块模块,内核和CPU定时器2 。
时钟频率默认为10MHz,可以通过INTOSCnTRIM寄存器修改频率。
2) INTOSC2(10MHz)
功能与INTOSC1是一样的。
3) 外部晶体振荡器
使用外部晶体振荡器给芯片提供时钟,晶振连接于X1/X2 脚。
4) 外部时钟源
如果不使用外部晶振作为时钟源,可以选择这种模式。时钟从外部时钟源的XCLKIN引脚输入生成。
下图可以看出SPI、SCI、I2C使用低速时钟,EPWM、ECAP、EQEP采用系统时钟、ADC采用高速时钟
步进驱动dsp2806
#define DSP28_CLKINDIV 0
#define DSP28_PLLCR 10
void InitSysCtrl(void)
{
DisableDog();
InitPll(DSP28_PLLCR, DSP28_CLKINDIV);
InitPeripheralClocks();
}
选择外部20M晶振,
系统时钟SYSCLKOUT = ( OSCCLK x 10) / div = ( 20 x 10 ) / 2 = 100MHz
平车DSP28034
#define DSP28_DIVSEL 2
#define DSP28_PLLCR 12
void InitSysCtrl(void)
{
DisableDog();
IntOsc1Sel();
InitPll(DSP28_PLLCR,DSP28_DIVSEL);
InitPeripheralClocks();
}
选择10MHz内部振荡器1作为时钟
SYSCLKOUT = ( 10 x 12 ) / 2 = 60MHz
SYSCtrlRegs.LOSPCP.all = 0x0002
低速时钟 = 60Mhz / 4 = 15MHz
#define PWMPRD 3000
EPwm2Regs.TBPRD = PWMPRD; // Period = 3001 TBCLK counts 20M HZ
EPwm2Regs.TBPHS.all = 0; // Set Phase register to zero
EPwm2Regs.TBCTR = 0; // clear TB counter
EPwm2Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN;
EPwm2Regs.TBCTL.bit.PHSEN = TB_ENABLE; // Phase loading enabled
EPwm2Regs.TBCTL.bit.PRDLD = TB_SHADOW;
EPwm2Regs.TBCTL.bit.SYNCOSEL = TB_SYNC_IN;
EPwm2Regs.TBCTL.bit.PHSDIR = TB_UP; //counts up after syn
EPwm2Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1; // TBCLK = SYSCLK
EPwm2Regs.TBCTL.bit.CLKDIV = TB_DIV1;
EPwm2Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;
EPwm2Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW;
EPwm2Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO_PRD; // load on CTR = Zero
EPwm2Regs.CMPCTL.bit.LOADBMODE = CC_CTR_ZERO_PRD; // load on CTR = Zero
EPwm2Regs.CMPA.half.CMPA = 1000; // Compare A = 350 TBCLK counts
EPwm2Regs.CMPB = 1500; // Compare B = 200 TBCLK counts
EPwm2Regs.AQCTLA.bit.ZRO = AQ_CLEAR;
EPwm2Regs.AQCTLA.bit.CAU = AQ_SET;
EPwm2Regs.AQCTLA.bit.PRD = AQ_SET;
EPwm2Regs.AQCTLA.bit.CAD = AQ_CLEAR;
EPwm2Regs.AQCTLB.bit.ZRO = AQ_CLEAR;
EPwm2Regs.AQCTLB.bit.CBU = AQ_SET;
EPwm2Regs.AQCTLB.bit.PRD = AQ_SET;
EPwm2Regs.AQCTLB.bit.CBD = AQ_CLEAR;
EPwm2Regs.DBCTL.bit.OUT_MODE = DB_FULL_ENABLE; //全部输出打开死区控制
EPwm2Regs.DBCTL.bit.POLSEL = DB_ACTV_LOC; //A输出逻辑低有效
EPwm2Regs.DBCTL.bit.IN_MODE = DBA_ALL; //AQ输出A作为死区控制输入
EPwm2Regs.DBFED = PWM_DeadbandTime; //死区时间设定
EPwm2Regs.DBRED = PWM_DeadbandTime;
EPwm2Regs.TZSEL.bit.OSHT2 = TZ_ENABLE; //TZ1 One Time Tripper Protect
EPwm2Regs.TZCTL.bit.TZA = TZ_FORCE_HI;
EPwm2Regs.TZCTL.bit.TZB = TZ_FORCE_HI; //Protect State is Forced to Low
EPwm2Regs.TZEINT.bit.OST = TZ_DISABLE; //Enable TZ Int
EPwm2Regs.TZCLR.all = 0x07; //Clear all int flag
EPwm2Regs.ETSEL.bit.INTEN = 0; // Disable EPWM interrupt
EPwm2Regs.ETSEL.bit.INTSEL = ET_CTR_ZERO;
EPwm2Regs.ETPS.bit.INTPRD = ET_1ST; // Generate an interrupt on the first event
EPwm2Regs.ETCLR.bit.INT = 1; // Clear spurious interrupt
EPwm2Regs.ETSEL.bit.INTEN = 1; // Enable EPWM interrupt
PWM采用系统时钟60MHz,周期3000,采用增减计数模式,在时基计数器值为0是产生中断。因为每6000计数产生一次中断。
中断的中期 = 1 / 60M *6000 = 0.0001(s) = 0.1 (ms) = 100 (us)
PWM的中断内包含QF_tick();,并且每进入10次处理一次。
QF_tick周期为1ms。