發表文章

  4. (10pts) Please answer the following questions (in simple): a) What's the name of ARM-based micro-controller we used in our class? [Answer in the WORD file] (Gives the platform name) (1pts) b) How to return datas from micro-controller to PC? (Gives the name of comm. interface) (1pts) c) From (b), which software tool we used in PC for comm.? (Gives the name of tool) (1pts) d) How to define pin A0 as a analog input object named analN? (Gives the code of declare in single line) (1pts) e) From (d), how to get the values from that pin and puts into varrible named ana_val? (Simply write down the code in single line) (Ipts) f) From (e), please answer the range of the analog reading. (Gives the range with min. ~ max.) (Ipts) g) Please list four different kinds of components we used in exp. lab. (In Chinese) (4pts)
 void setup() {     Serial.begin(9600);     int oddSum = 0;     int evenSum = 0;     for(int i = 10; i <= 300; i++)     {         if(i % 2 == 1)             oddSum += i;     }     for(int i = 40; i <= 220; i++)     {         if(i % 2 == 0)             evenSum += i;     }     Serial.print("Odd Sum = ");     Serial.println(oddSum);     Serial.print("Even Sum = ");     Serial.println(evenSum); } void loop() { }
 #include <HardwareSerial.h> HardwareSerial MySerial(PA3, PA2); void setup() {   MySerial.begin(9600);   pinMode(PA_0, INPUT);    MySerial.println("可變電阻測試開始..."); } void loop() {   // 讀取可變電阻的數值   int potValue = analogRead(PA_0);   float voltage = (potValue * 3.3) / 1023.0;   // 將數值印出來   MySerial.print("電壓值: ");   MySerial.print(voltage, 2);   MySerial.println(" V");   delay(1000); }
 #include <HardwareSerial.h> // 宣告名為 MySerial 的硬體序列埠 (RX=PA3, TX=PA2) HardwareSerial MySerial(PA3, PA2); void setup() {   MySerial.begin(9600);         // 初始化序列埠通訊   pinMode(PA_8, INPUT);    pinMode(PA_1, INPUT);    MySerial.println("TCRT5000 測試開始..."); } void loop() {   // 1. 讀取類比數值 (0 ~ 1023)   // 反射愈強(物體愈近或顏色愈白),電壓愈低,數值愈小   int aValue = analogRead(PA_1);   // 2. 讀取數位狀態 (0 或 1)   int dValue = digitalRead(PA_8);   // 將結果印出來   MySerial.print("類比數值 (A0): ");   MySerial.print(aValue);   MySerial.print(" | 數位狀態 (D0): ");   MySerial.println(dValue);   delay(1000); }
 Please download 2 files from this shared folder: https://365nchu-my.sharepoint.com/:f:/g/personal/g110064759_365_nchu_edu_tw/IgDqrDItFYfoRJagmuT-bgMsAZJQNbDZgig4cZ9i5bLlPOY?e=Qf5cnY
 clc; clear; close all; %% ===== G1(s) ===== num1 = [1 5 4]; den1 = [1 6 11 6]; G1 = tf(num1, den1); disp('G1(s) = '); G1 %% G1 controllable canonical form Ac1 = [0 1 0;        0 0 1;       -6 -11 -6]; Bc1 = [0; 0; 1]; Cc1 = [4 5 1]; Dc1 = 0; sys1_c = ss(Ac1,Bc1,Cc1,Dc1); disp('G1 controllable canonical form:'); sys1_c disp('Transfer function from controllable form:'); tf(sys1_c) rank_ctrb_G1c = rank(ctrb(Ac1,Bc1)) rank_obsv_G1c = rank(obsv(Ac1,Cc1)) %% G1 observable canonical form Ao1 = [0 0 -6;        1 0 -11;        0 1 -6]; Bo1 = [4; 5; 1]; Co1 = [0 0 1]; Do1 = 0; sys1_o = ss(Ao1,Bo1,Co1,Do1); disp('G1 observable canonical form:'); sys1_o disp('Transfer function from observable form:'); tf(sys1_o) rank_ctrb_G1o = rank(ctrb(Ao1,Bo1)) rank_obsv_G1o = rank(obsv(Ao1,Co1)) %% ===== G2(s) ===== num2 = [1 3]; den2 = [1 2 5]; G2 = tf(num2, den2); disp('G2(s) = '); G2 %% G2 controllable canonical form Ac2 = [0 1;...
 clc; clear; close all; % 定義 s s = tf('s'); % Transfer function G = 400 / ((s+1)*(s^2 + 4*s + 400)); %% 1️⃣ 畫 Bode Plot + Margin figure; margin(G);   % 直接給你 GM, PM, Wcg, Wcp grid on; %% 2️⃣ 抓出所有數據 [GM, PM, Wcg, Wcp] = margin(G); fprintf('Gain Margin (GM) = %.4f\n', GM); fprintf('Phase Margin (PM) = %.4f deg\n', PM); fprintf('Gain crossover frequency (Wcg) = %.4f rad/s\n', Wcg); fprintf('Phase crossover frequency (Wcp) = %.4f rad/s\n', Wcp); %% 3️⃣ Bandwidth bw = bandwidth(G); fprintf('Bandwidth (BW) = %.4f rad/s\n', bw); %% 4️⃣ Resonance Peak & Frequency [mag, phase, w] = bode(G); mag = squeeze(mag); [Mr, idx] = max(mag); wr = w(idx); fprintf('Resonance Peak (Mr) = %.4f\n', Mr); fprintf('Resonance Frequency (wr) = %.4f rad/s\n', wr); %% 5️⃣ Polar Plot figure; nyquist(G);   % 或用 polarplot (Nyquist更常用) grid on; title('Nyquist Plot');