Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

I.

II.

C u trc matlab/simulink: 1. C u hnh simulink: -t o file m ph ng simulink. (xy d ng theo discrete, 0 h tr continous time) + type : fixed stepp +solver: discrete +sampling time (fixed step size ): 0.01 ( 10ms) + realtime workshop -> system target file ert.tlc (realtime workshop embedded coder) 2. Pht m C cho m hnh simulink: - Tool RTw build model (Ctrl B) - cc file simulink t o ra trong th m c : <tn mhnh ert rtw> + file ert-main.c : ch a ch ng trnh chnh. + file tnmhnh.c : file ch a m hnh simulink. + file tnmhnh_data.c : ch a cc thng s c a m hnh simulink. +t t c cc file.h. T o project cho keil: 1. T o project trong keil: - T o 1 project. - Copy cc file do matlab pht ra vo project. - T o thm ng d n t i cc file c a matlab (include) D:/matlab/extern/include; /similink/include; /rtw/c/src; rtw/c/libsrc; rtw/c/src/ext_mode/common; rtw/c/ect;

/toolbox/dspblks/include; /toolbox/vipblks/include;(xu ly anh va xu ly tin hieu so cho 2 dong cuoi) 2. S a l i file ert_main.c ; - Xa cc l nh printf, while. - G i hm rt_onestep(): // m hnh simulink. !ch : rt_onestep ch ch y 1 b c. *ch a c th i gian l y m u * ch a c th i gian k t thc - nhi m v c n lm: + t o 1 timer c chu k b ng chu k l y m u ( t o b ng ng t l t t nh t ) trong simulink.

+ g i hm rt_onestep() Tstop/Tsampling l n. while (1) //for (i=0;i<1000*sampling;i++) { while (!stick_flag); tick_flag =0; rt_OneStep(); } Timer_interrupt { Tick_flag=1; } 3. Vi t driver giao ti p: (c m bi n, ch p hnh v k t n i v i file c a simulink) PID s (STR)

You might also like