DSP28377S - ADC學習編程筆記編程
彭會鋒ide
2016-08-04 20:19:52函數
1 ADC類型致使的配置區別學習
F28377S的ADC類型是Type 4類型,個人理解是不一樣類型的ADC採樣方式是不同的:F28335ADC 採樣序列能夠配置爲順序採樣和同步採樣模式,而F28377S採樣序列能夠配置爲round-robin or burst模式,這兩種模式下面再講解。測試
2 ADC上電配置步驟spa
//Write ADC configurations and power up the ADC for both ADC A and ADC B void ConfigureADC(void) { EALLOW; //write configurations AdcaRegs.ADCCTL2.bit.PRESCALE = 6; //set ADCCLK divider to /4 //配置ADC時鐘,ADC時鐘有系統時鐘直接提供參考時鐘,計算的時候須要注意 AdcSetMode(ADC_ADCA, ADC_RESOLUTION_12BIT, ADC_SIGNALMODE_SINGLE); // 設置ADC的採樣分辨率爲12bit,單輸入模式(區別於差分模式) AdcbRegs.ADCCTL2.bit.PRESCALE = 6; //set ADCCLK divider to /4 AdcSetMode(ADC_ADCB, ADC_RESOLUTION_12BIT, ADC_SIGNALMODE_SINGLE); //Set pulse positions to late AdcaRegs.ADCCTL1.bit.INTPULSEPOS = 1; //設置ADC的中斷產生時機在轉換完成後產生中斷(Interrupt pulse generation occurs at the end of the conversion) AdcbRegs.ADCCTL1.bit.INTPULSEPOS = 1; //power up the ADC AdcaRegs.ADCCTL1.bit.ADCPWDNZ = 1; //給ADC上電,注意須要延時1ms左右等待上電完成
AdcbRegs.ADCCTL1.bit.ADCPWDNZ = 1; //delay for 1ms to allow ADC time to power up DELAY_US(1000); EDIS; }
3 ADC採樣通道、保持時間和觸發信號配置,這裏和中斷配置在一塊兒講了!code
AdcbRegs.ADCSOC7CTL.bit.CHSEL = 14; //SOC0 will convert internal connection B0 AdcbRegs.ADCSOC7CTL.bit.ACQPS = tempsensor_acqps; //sample window is 100 SYSCLK cycles AdcbRegs.ADCSOC7CTL.bit.TRIGSEL = 5; //trigger on ePWM1 SOCA/C,這裏根據須要進行配置
AdcaRegs.ADCINTSEL1N2.bit.INT1SEL = 7; //end of SOC0 will set INT1 flag (這裏通常配置爲最後一個優先級的SOC便可!注意要隨時修改,這裏栽跟頭了)(優先級放最後講解,能夠不用理解!) AdcaRegs.ADCINTSEL1N2.bit.INT1E = 1; //enable INT1 flag (若是不配置這裏,那麼ADC採樣完成後中斷flag不會置位,因此必須配置爲1) AdcaRegs.ADCINTFLGCLR.bit.ADCINT1 = 1; //make sure INT1 flag is cleared
在配置過程當中須要注意的是:blog
爲了進行測試,有時候會使用13 temp sensor作測試用(須要注意必須先初始化此溫度端口,而後在使用,不然ADC採樣會被卡在這個地方致使莫名其妙問題)文檔
//Initialize the temperature sensor
//Note: The argument needs to change if using a VREFHI voltage other than 3.0V
InitTempSensor(3.0); (這裏已經有現成的封裝函數可使用,直接調用便可!)(若是不初始化,會致使採樣沒法正常順序進行,切記切記!)同步
AdcaRegs.ADCSOC6CTL.bit.CHSEL = 13; //SOC0 will convert internal connection A13 AdcaRegs.ADCSOC6CTL.bit.ACQPS = tempsensor_acqps; //sample window is 100 SYSCLK cycles AdcaRegs.ADCSOC6CTL.bit.TRIGSEL = 5; //trigger on ePWM1 SOCA/C
4 epwm觸發配置
注意:epwm能夠配置爲在ZERO和PERIOD兩個時刻均可以觸發SOCA採樣信號,因此在逆變器中能夠連續採樣兩次,這個對於編程很重要,差點有栽跟頭了,因此必定要看官方文檔!
void ConfigureEPWM(void) { EALLOW; // Assumes ePWM clock is already enabled EPwm1Regs.ETSEL.bit.SOCAEN = 0; // Disable SOC on A group EPwm1Regs.ETSEL.bit.SOCASEL = 1; // Select SOC on up-count EPwm1Regs.ETPS.bit.SOCAPRD = ET_CTR_PRDZERO; // Generate pulse on 1st event(注意這裏EPWM能夠配置爲在ZERO 和 PERIOD時觸發ADC採樣,這和F28335不同!又差點栽跟頭了!) EPwm1Regs.CMPA.bit.CMPA = 0x0800; // Set compare A value to 2048 counts EPwm1Regs.TBPRD = 0x1000; // Set period to 4096 counts EPwm1Regs.TBCTL.bit.CTRMODE = 3; // freeze counter EDIS; }
最後還有關於EOC 轉換優先級 和 ADC採樣結構等內容,做爲了解性質,晚點補充,今天先到次爲止!