close
(這個標題好難想啊,一直想不到適當的標題)
這次要介紹的是CPU在digitalWrite(HIGH)<->digitalWrite(LOW)雙向切換所需要的時間,參賽選手有Due、Intel Galileo Gen2、Mega ADK、Micro,Nano。
作法是把某個Pin的電位由高拉到低,再由低拉到高,反覆進行,藉此來量測CPU的排程情況以及OUTPUT電位的切換時間,提供給寫程式的人參考。
程式碼(下載)
void setup() { pinMode(12,OUTPUT); pinMode(11,OUTPUT); digitalWrite(12,LOW); digitalWrite(12,LOW); digitalWrite(12,LOW); digitalWrite(12,LOW); digitalWrite(12,LOW); digitalWrite(12,LOW); digitalWrite(12,LOW); digitalWrite(12,LOW); digitalWrite(12,LOW); digitalWrite(12,LOW); digitalWrite(12,HIGH); //1 digitalWrite(12,LOW); digitalWrite(12,HIGH); //2 digitalWrite(12,LOW); digitalWrite(12,HIGH); //3 digitalWrite(12,LOW); digitalWrite(12,HIGH); //4 digitalWrite(12,LOW); digitalWrite(12,HIGH); //5 digitalWrite(12,LOW); digitalWrite(12,HIGH); //2_1 digitalWrite(11,HIGH); //2_1 digitalWrite(12,LOW); digitalWrite(11,LOW); digitalWrite(12,HIGH); //2_2 digitalWrite(11,HIGH); //2_2 digitalWrite(12,LOW); digitalWrite(11,LOW); digitalWrite(12,HIGH); //2_3 digitalWrite(11,HIGH); //2_3 digitalWrite(12,LOW); digitalWrite(11,LOW); digitalWrite(12,HIGH); //2_4 digitalWrite(11,HIGH); //2_4 digitalWrite(12,LOW); digitalWrite(11,LOW); digitalWrite(12,HIGH); //2_5 digitalWrite(11,HIGH); //2_5 digitalWrite(12,LOW); digitalWrite(11,LOW); } // the loop routine runs over and over again forever: void loop() { }
其實一開始的pin 12也不用 digitalWrite(12,LOW);這麼多次啦,寫的時候不曉得在想什麼。
接著用邏輯分析儀來量看看結果,這次分別對DUE,Intel Galileo Gen2,MEGA ADK,Nano & Mirco作量測
結果請看下一篇文章。
全站熱搜