![]() |
|
Tài trợ cho PIC Vietnam |
dsPIC - Bộ điều khiển tín hiệu số 16-bit Theo dự kiến của Microchip, vào khoảng năm 2011 dsPIC sẽ có doanh số lớn hơn PIC |
|
Ðiều Chỉnh | Xếp Bài |
![]() |
#12 |
Đệ tử 6 túi
Tham gia ngày: Apr 2006
Bài gửi: 125
: |
bác nên dùng luôn thư viện PID của C30 nó có viết sãn hàm PID cho bác rồi mà
bác có thể tham khảo code sau: khai báo biến cho hàm PID Code:
tPID fooPID; fractional abcCoefficient[3] __attribute__ ((section (".xbss, bss, xmemory"))); fractional controlHistory[3] __attribute__ ((section (".ybss, bss, ymemory"))); fractional kCoeffs[] = {0,0,0}; Code:
void PID_Init(void){ 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 controler history and the controller output */ kCoeffs[0] = Q15(0.1); // Kp kCoeffs[1] = Q15(0.07); // Ki kCoeffs[2] = Q15(0.00); // Kd PIDCoeffCalc(&kCoeffs[0], &fooPID); /*Derive the a,b, & c coefficients from the Kp, Ki & Kd */ fooPID.controlReference = Q15(1) ; /*Set the Reference Input for your controller */ fooPID.measuredOutput = Q15(0) ; } Code:
fooPID.measuredOutput = Q15(v_calculate(data)/(float)80); PID(&fooPID); duty = (unsigned int)(Fract2Float(fooPID.controlOutput) * PTPER *2); |
![]() |
![]() |
|
|