±ÏÒµÉè¼Æ£¨ÂÛÎÄ£©
ÆäÖУ¬nΪÖÜÆڼĴæÆ÷µÄʱ¼ä³£Êý£¬TpΪ¼ÆʱÆ÷ʱ»ùÖÜÆÚ£¬kÔÚÁ¬ÐøÔö/¼õ¼ÆÊýģʽʱȡ2¡£ÔÚÁ¬ÐøÔö/¼õ¼ÆÊýģʽÏ£¬¼ÆÊýÆ÷µÄÖµ´Ó¡°0¡±¿ªÊ¼¼ÆÊý£¬µ½´ïÖÜÆÚֵʱÔÙÍùϼÆÊý¡£ÔÚÕâÆڼ䣬Èý¸öÈ«±È½Ï¼Ä´æÆ÷µÄÖµÓë¼ÆÊýÆ÷µÄÖµ½øÐбȽϣ¬ÔÚµÚÒ»´ÎÏàͬʱ£¨Ôö¼ÆÊý£©£¬¶ÔÓ¦µÄPWMÊä³ö½Å£¨PWM1,2¡¢PWM3,4¡¢PWM5,6£©µÄÊä³ö¼«ÐÔ·¢Éú±ä»¯£»µÚ¶þ´ÎÏàͬʱ£¨¼õ¼ÆÊý£©£¬¶ÔÓ¦µÄPWMÊä³ö½Å£¨PWM1,2¡¢PWM3,4¡¢PWM5,6£©µÄÊä³ö¼«ÐÔÔٴη¢Éú±ä»¯£¬ÕâÑù¾ÍʵÏÖÁËPWMÊä³ö¡£DSPµÄÕâЩ±È½Ï£¬È«²¿ÓÉÓ²¼þʵÏÖ£¬ËùÒÔֻҪÿ¸ö¿ª¹ØÖÜÆÚ¸üÐÂÈ«±È½Ï¼Ä´æÆ÷µÄÖµ£¬¾Í¿ÉÒÔʵÏÖPWM¿ØÖÆ¡£Í¼Öиø³öÁ˲ÉÓÃDSPµÄÈ«±È½Ï¹¦ÄܲúÉúÁù·PWMµÄʾÒâͼ¡£
¶¨Ê±Æ÷T1±È½ÏÖµCMP1È«±È½Ï±È½ÏÖµCMP2PWM1PWM2PWM3PWM4PWM5PWM6±È½ÏÖµCMP3
ͼ4-2-1 DSPÖÐÈ«±È½Ï¹¦ÄÜ¿òͼ
23
±ÏÒµÉè¼Æ£¨ÂÛÎÄ£©
CMP1ÖµCMP2ÖµT1(x)1CMP3Öµ¼ÆÊýÆ÷ÖµPWM1PWM2PWM3CMP(x)0.501PWM4PWM(x)0.50PWM5PWM6
ͼ4-2-2 SPWM²¨µÄ²úÉú
4.3 ³õʼ»¯
ÔÚTMS320F2812Õý³£¹¤×÷Ç°£¬±ØÐë¶ÔËü½øÐгõʼ»¯ÉèÖᣳõʼ»¯ÉèÖðü À¨ÏµÍ³ÅäÖüĴæÆ÷µÄ³õʼ»¯ºÍʼþ¹ÜÀíÆ÷µÄ³õʼ»¯Á½²¿·Ö£¬ÏÂÃ潫·Ö±ðÓèÒÔ ½éÉÜ¡£
4.3.1 ϵͳʱÖÓºÍÍâÉèʱÖÓ
F2812×î´óʱÖÓƵÂÊ150MHz,ÓÉÓÚ²ÉÓõÄÍⲿ¾§ÕñΪ30MHz,ËùÒÔÒª¾¹ýËøÏà»·PLL½øÐÐ5±¶Æµ£»¶ÔϵͳʱÖÓ½øÐÐ2·ÖƵ¼´75MHz×÷ΪÍâÉè¸ßËÙÔ¤¶¨±êʱÖÓ £»È»ºóʹÄÜÓõ½µÄÍâÉèʱÖÓ£¬Ã»ÓÐÓõ½µÄÍâÉ費ʹÄÜʱÖÓÒÔ½µµÍ¹¦ºÄ¡£
void InitSysCtrl(void) { Uint16 i; EALLOW;
SysCtrlRegs.WDCR= 0x0068;//½ûÖ¹¿´ÃŹ·Ä£¿é
24
±ÏÒµÉè¼Æ£¨ÂÛÎÄ£©
SysCtrlRegs.PLLCR = 0xA;//Íⲿ¾§Õñ30MHz¾ËøÏà»·PLL 5±¶ÆµÏµÍ³Ê±ÖÓ Îª150MHz
for(i= 0; i< 5000; i++){} //µÈ´ýPLLÍê³ÉËøÏà
SysCtrlRegs.HISPCP.all = 0x0001; //¸ßËÙʱÖÓhscplk=150m/2*n=75m SysCtrlRegs.LOSPCP.all = 0x0002;//µÍËÙÍâÉèʱÖÓΪ37.5m
SysCtrlRegs.PCLKCR.bit.EVAENCLK=1;//ʹÄÜEVAÍâÉèÖеĸßËÙʱÖÓ SysCtrlRegs.PCLKCR.bit.ADCENCLK=1;//ʹÄÜADCÍâÉèÖеĸßËÙʱÖÓ
}
4.3.2 ͨÓÃIOÉèÖÃ
DSPоƬÌṩÁ˶à¸öͨÓÃÊäÈë/Êä³ö¶Ë¿Ú£¨GPIO£©ºÜ¶à¶Ë¿ÚÒý½ÅÊǸ´ÓÃÒý½Å£¬Óɸ´Óù¦ÄÜÑ¡Ôñ¼Ä´æÆ÷GPxMUXÑ¡Ôñ¾ßÌ幦ÄÜ£¬¿ÉÒÔ½«Òý½ÅÉ趨ΪƬÄÚÍâÉèµÄÊäÈë/Êä³öÒý½Å£¬Ò²¿ÉÒÔÉ趨ΪÊý×ÖÁ¿ÊäÈë/Êä³öÒý½Å¡£¸ù¾Ý±¾ÏµÍ³µÄÉè¼Æ£¬ÐèÒªÓõ½Ê¼þ¹ÜÀíÄ£¿éEVAÊä³öpwm²¨£¬¶ÔÓ¦µÄÊä³öÒý½ÅΪGPIOA0~GPIOA7£¬½«Õ⼸¸öÒý½ÅÉèÖÃΪÍâÉ蹦ÄÜÒý½Å£»»¹Óõ½Ò»¸öÊý×ÖÊä³ö¿ÚGPIOB0ÓÃÀ´Êä³ö±£»¤Ö¸Ê¾Ðźš£
void InitGpio(void) {
EALLOW;
GpioMuxRegs.GPAMUX.all=0x00FF; //°ÑGPIOA0~GPIOA7 ÅäÖóÉÍâΧ¹¦ÄÜ GpioMuxRegs.GPADIR.all=0xFFFF; // °ÑGPIOA¶¼ÅäÖóÉÊä³ö GpioMuxRegs.GPAQUAL.all=0x0000; // ½ûÖ¹ÊäÈëÏÞÖÆ
GpioMuxRegs.GPBMUX.all=0x0000; //°ÑGPIOB¶¼ÅäÖóÉÊý×ÓIO¿Ú GpioMuxRegs.GPBDIR.all=0xFFFF; // °ÑGPIOB¶¼ÅäÖóÉÊä³ö GpioMuxRegs.GPBQUAL.all=0x0000; // ½ûÖ¹ÊäÈëÏÞÖÆ
EDIS; }
EDIS;
25
±ÏÒµÉè¼Æ£¨ÂÛÎÄ£©
4.3.3 ADÄ£¿éµÄÉèÖÃ
F2812µÄÄ£-Êýת»»Æ÷£¨ADC£©ÊÇÒ»¸ö12λ·Ö±æÂÊ´øÁ÷Ë®Ï߽ṹµÄÄ£Êý
ת»»Æ÷£¬ÆäÖеÄÄ£Äâµçѹ°üÀ¨Ç°¶ËÄ£Äâ¶à·¸´ÓÃÆ÷£¨MUX£©¡¢²ÉÑù±£³Öµç·£¨S/H£©¡¢Ò»¸öÄ£Êýת»»Äںˡ¢²Î¿¼µçѹµç·ÒÔ¼°ÆäËûÄ£Äâµç·£»Êý×ֵ緲¿·Ö°üÀ¨¿É±à³ÌÅÅÐòÆ÷¡¢×ª»»½á¹û¼Ä´æÆ÷¡¢ÓëÄ£Äâµç·µÄ½Ó¿Úµç·¡¢ÓëоƬÍâÉè×ÜÏߵĽӿڵȡ£ËüÓÐ16¸ö²ÉÑùͨµÀ£¬¿ÉÒÔÅäÖóÉÁ½¸ö¶ÀÁ¢µÄ8ͨµÀ£¬Ò²¿ÉÁª¼¶³ÉÒ»¸ö16ͨµÀÄ£¿é¡£
²ÉÑùÈýÏàµçÁ÷ÈýÏàµçѹҪÓõ½6¸ö²ÉÑùͨµÀ£¬²ÉÑùÅÅÐòģʽÉèÖÃΪµ¥ÅÅ
Ðò²¢ÐвÉÑù£¬ÈôͨµÀA0¡¢A1¡¢A2·Ö±ð²ÉÑùA¡¢B¡¢CÈýÏàµçѹ£¬Í¨µÀB0¡¢B1¡¢B2·Ö±ð²ÉÑùA¡¢B¡¢CÈýÏàµçÁ÷£¬Ôò²ÉÑùºóµÄ½á¹û´æ´¢Î»ÖõĶÔÓ¦¹ØϵÈçÏ£º
ͼ4-3
void InitAdc(void)
{
unsigned int i;
AdcRegs.ADCTRL1.bit.RESET=1; //¸´Î» AdcRegs.ADCTRL1.bit.RESET=0; AdcRegs.ADCTRL1.bit.SUSMOD=3; //·ÂÕæ
AdcRegs.ADCTRL1.bit.ACQ_PS=0; //²ÉÑù±£³Ö´°¿Ú·ÖƵ AdcRegs.ADCTRL1.bit.CPS=0; // ²»·ÖƵ
26