PIC Vietnam

Go Back   PIC Vietnam > Microchip PIC > dsPIC - Bộ điều khiển tín hiệu số 16-bit

Tài trợ cho PIC Vietnam
Trang chủ Đăng Kí Hỏi/Ðáp Thành Viên Lịch Bài Trong Ngày Vi điều khiển

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
Prev Previous Post   Next Post Next
Old 03-03-2009, 07:33 PM   #12
mtuankct
Đệ 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};
khởi tạo cho PID
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) ;  
}
sau đó dùng một timer để tạo ra chu kỳ gọi hàm PID, tính toán lại giá trị đo sau đó gọi hàm PID để xử lý
Code:
	fooPID.measuredOutput = Q15(v_calculate(data)/(float)80);
	PID(&fooPID);
	duty = (unsigned int)(Fract2Float(fooPID.controlOutput) * PTPER *2);
mtuankct vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn
 


Quyền Sử Dụng Ở Diễn Ðàn
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is Mở
Smilies đang Mở
[IMG] đang Mở
HTML đang Tắt

Chuyển đến


Múi giờ GMT. Hiện tại là 04:17 PM.


Được sáng lập bởi Đoàn Hiệp
Powered by vBulletin®
Page copy protected against web site content infringement by Copyscape
Copyright © PIC Vietnam