Electronics 板


LINE

最近在用dspic30F4011控制簡單的buck和boost converter 但是對dspic不太熟析 所以上網找了一些資料 其中找到了用dspic30F4011 寫PI控制buck converter 所以我就拿來實作看看不過有些問題 以下是網路上找到的程式 #include <p30F4011.h> #include <dsp.h> _FOSC(CSW_FSCM_OFF & XT_PLL16); // Failsafe clock off, Internal FRC with 16xPLL oscillator _FWDT(WDT_OFF); // Wathcdog timer disabled _FBORPOR(PBOR_OFF & MCLR_EN); // Brown-out reset disabled, MCLR reset enabled _FGS(CODE_PROT_OFF); // Code protect disabled #define PWM_Period 0x0257 // PTPER = (Fcy / Fpwm) - 1 #define PWM_Duty_Max 0x0438 // PWM Duty 最大值, 0.9 #define PWM_Duty_Min 0x0078 // PWM Duty 最小值, 0.1 #define PWM_Duty_Ref 0x012C // PWM Duty 參考準位, 0.25 #define Vref 0x018E // Vdd=3.4V 時的 Vref = 2.5V // 宣告PID 資料結構 tPID fooPID; fractional abcCoefficient[3] __attribute__ ((section (".xbss, bss, xmemory"))); fractional controlHistory[3] __attribute__ ((section (".ybss, bss, ymemory"))); fractional kCoeffs[] = {0,0,0}; // 宣告函數 void Init_PWM(void) ; void Init_ADC(void) ; void Set_PWM_Duty(void) ; void Compensator(void); // 宣告全域變數 unsigned int PWM_Duty ; int main(void) { Init_PWM() ; // 初始化PWM Init_ADC() ; // 初始化ADC ADCON1bits.ADON = 1 ; // 啟動ADC PTCONbits.PTEN = 1 ; // 啟動PWM fooPID.abcCoefficients = &abcCoefficient[0] ; // Set up pointer to derived coefficients fooPID.controlHistory = &controlHistory[0] ; // Set up pointer to controller history samples PIDInit(&fooPID) ; // Clear the controller history and the controller output kCoeffs[0] = Q15(0.5) ; // KP kCoeffs[1] = Q15(0.000) ; // KI kCoeffs[2] = Q15(0.0) ; // KD PIDCoeffCalc(&kCoeffs[0], &fooPID) ; // Derive the a,b, & c coefficients from the Kp, Ki & Kd fooPID.controlReference = Vref << 5 ; // 初始化參考電壓Vref 的值 while(1) { ADCON1bits.SAMP = 1 ; // start sampling while (ADCON1bits.SAMP) ; // Sample done? while (!ADCON1bits.DONE) ; // conversion done? Compensator() ; } } void Init_PWM(void) { PTCON = 0x0000 ; // Stop in Idle off, 1:1 Postscale and Prescale, Free Running Mode PTPER = PWM_Period ; // PTPER = Fcy / Fpwm - 1 PWMCON1 = 0x0110 ; // PWM1 independent, PWM1H Enable PWMCON2 = 0x0000 ; OVDCON = 0xFF00 ; // Output on PWMxx I/O pin is controlled by the PWM generator PDC1 = 0x0257 ; // Duty: (PDCx/2) / (PTPER+1) } void Init_ADC(void) { ADPCFG = 0xFFFE ; // AN0 Analog ADCON1 = 0x0000 ; // FORM: Integer ADCON1bits.SSRC = 0b111 ; // Auto convert ADCON2 = 0x0000 ; // VrefH=AVdd, VrefL=AVss, Do not scan, Converts CH0, Always MUXA ADCON3bits.SAMC = 16 ; // ADC SAMPLE TIME = 16 Tad ADCON3bits.ADRC = 0 ; // Use system clock ADCON3bits.ADCS = 4 ; // Conversion clock = 4 Tcy ADCSSL = 0x0000 ; // ADC scan no channel ADCHS = 0x0000 ; ADCHSbits.CH0NA = 0 ; // Channal 0 negative input is Vref- ADCHSbits.CH0SA = 0 ; // Channal 0 positive input is AN0 } void Set_PWM_Duty(void) { if(PWM_Duty > PWM_Duty_Max) PDC1 = PWM_Duty_Max ; else if(PWM_Duty < PWM_Duty_Min) PDC1 = PWM_Duty_Min ; else PDC1 = PWM_Duty ; } //取樣迴授訊號與補償器設計 void Compensator(void) { fooPID.measuredOutput = ADCBUF0 << 5 ; // Set PID measured input PID(&fooPID); // Call the PID controller using the new measured input if(fooPID.controlOutput > (0x7FFF - PWM_Duty_Ref)) // 處理可能造成的溢位 PWM_Duty = 0x7FFF; else if( (fooPID.controlOutput + PWM_Duty_Ref) < 0 ) PWM_Duty = 0x0000; else PWM_Duty = fooPID.controlOutput + PWM_Duty_Ref; Set_PWM_Duty(); // 限制Duty 最大值與最小值 } 1.因為看不太懂程式,所以我實作是這樣做的 假設buck情形時輸入60V輸出30V,輸出電壓經過分壓假設是3V ,我就先把3V拉進去dspic裡看輸出PWM的duty是不是0.5,有點像在湊答案= = 如果不是我就改他的Vref的值,這邊有點怪怪的Vref的值好像沒有一定的比例 所以一定要try很多次才能找到 這邊不太清楚為什麼... 2.找到了以後我就輸入60V,得到了30V的輸出電壓,我試著把輸入電壓變大或變小 但是輸出電壓沒有辦法追到我的命令,會跟著變大變小.所以說我就試著改 kCoeffs[0] = Q15(0.5) ; // KP kCoeffs[1] = Q15(0.000) ; // KI kCoeffs[2] = Q15(0.0) ; // KD 這三行裡Q15括號裡的值 但是示波器量出來的波形更怪 離我的命令值更遠 有時後電感還會發出淒厲的叫聲? 3.我另外還有想說把開關切換頻率降低,應此我改了 #define PWM_Period 0x0257 // PTPER = (Fcy / Fpwm) - 1 這行,但是改完以後,一開始輸出PWM的duty(燒錄晶片後 開始RUN的時候 不經過回授) 原本是0.9但是隨著我改變PWM_Period 的值PWM的DUTY也會跟著變...感覺怪怪的? 有沒有高手可以解決我的疑問 感恩~~~ --



※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 134.208.1.23







like.gif 您可能會有興趣的文章
icon.png[問題/行為] 貓晚上進房間會不會有憋尿問題
icon.pngRe: [閒聊] 選了錯誤的女孩成為魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一張
icon.png[心得] EMS高領長版毛衣.墨小樓MC1002
icon.png[分享] 丹龍隔熱紙GE55+33+22
icon.png[問題] 清洗洗衣機
icon.png[尋物] 窗台下的空間
icon.png[閒聊] 双極の女神1 木魔爵
icon.png[售車] 新竹 1997 march 1297cc 白色 四門
icon.png[討論] 能從照片感受到攝影者心情嗎
icon.png[狂賀] 賀賀賀賀 賀!島村卯月!總選舉NO.1
icon.png[難過] 羨慕白皮膚的女生
icon.png閱讀文章
icon.png[黑特]
icon.png[問題] SBK S1安裝於安全帽位置
icon.png[分享] 舊woo100絕版開箱!!
icon.pngRe: [無言] 關於小包衛生紙
icon.png[開箱] E5-2683V3 RX480Strix 快睿C1 簡單測試
icon.png[心得] 蒼の海賊龍 地獄 執行者16PT
icon.png[售車] 1999年Virage iO 1.8EXi
icon.png[心得] 挑戰33 LV10 獅子座pt solo
icon.png[閒聊] 手把手教你不被桶之新手主購教學
icon.png[分享] Civic Type R 量產版官方照無預警流出
icon.png[售車] Golf 4 2.0 銀色 自排
icon.png[出售] Graco提籃汽座(有底座)2000元誠可議
icon.png[問題] 請問補牙材質掉了還能再補嗎?(台中半年內
icon.png[問題] 44th 單曲 生寫竟然都給重複的啊啊!
icon.png[心得] 華南紅卡/icash 核卡
icon.png[問題] 拔牙矯正這樣正常嗎
icon.png[贈送] 老莫高業 初業 102年版
icon.png[情報] 三大行動支付 本季掀戰火
icon.png[寶寶] 博客來Amos水蠟筆5/1特價五折
icon.pngRe: [心得] 新鮮人一些面試分享
icon.png[心得] 蒼の海賊龍 地獄 麒麟25PT
icon.pngRe: [閒聊] (君の名は。雷慎入) 君名二創漫畫翻譯
icon.pngRe: [閒聊] OGN中場影片:失蹤人口局 (英文字幕)
icon.png[問題] 台灣大哥大4G訊號差
icon.png[出售] [全國]全新千尋侘草LED燈, 水草

請輸入看板名稱,例如:WOW 或 站內搜尋

TOP