任務: 測試,讀1k點訊號的時間
任務: 測試,讀1k點訊號的時間
要旨:我要用1片esp-12f 來讀315M hz 無線電搖控器的訊號,先評估 mpy, arduino 的讀點速度
說明:
microPython程式, 讀訊號, 1次讀1K點/0.15 sec=6.7 khz
Arduino 程式, 讀訊號, 1次讀100K點 / 0.061 sec = 1639 khz
同一片esp-12F 板子, arduino 速度 / mpy 速度=1635/6.67=246倍
這也就是說,我要用arduino 來寫讀搖控器訊號,波形比較不會失真,解析度高。
另外,有1支mpy, 山寨arduino, 其速度1K/0.0265
sec=37.7 khz
同一片esp-12F 板子, arduino 速度 / mpy 速度=1635/37.74=43倍
E:\wsh\wsh_now\MPU32\ESP8266\ecv\nwsvr.py
cd e:
cd \micro*\espt*
esptool -p COM5 -b 460800 erase_flash
esptool -p COM5 -b 460800 write_flash 0x00000 esp8266-20191126-v1.11-603-gbc129f 1b8.bin -fm dout -fs 4MB
cd E:\wsh\wsh_now\MPU32\ESP8266\ecv
ampy -p COM5 ls
ampy -p COM5 put nwsvr.py
mpy 原碼,nwsvr.py
from machine import Pin
def ex1():
p0=Pin(0,Pin.OUT)
p2=Pin(2,Pin.IN,Pin.PULL_UP)
p0.value(0)
t=time.ticks_us()
k=0
iMax=1000
for i in range(iMax):
if(p2.value()) :
k|=(1<
t=time.ticks_us()-t
p0.value(1)
print(t)
return k
from machine import UART
uart = UART(0, 115200)
while 1:
ex1()
輸出結果:
149942
148767
149944
from machine import Pin
def ex1():
p0=Pin(0,Pin.OUT)
p2=Pin(2,Pin.IN,Pin.PULL_UP)
p0.value(0)
t=time.ticks_us()
iMax=1000
k=[0]*int(iMax/8)
for i in range(iMax/8):
m=0
for j in range(8):
m<<=1
if(p2.value()) :
m|=1
k[i]=m
t=time.ticks_us()-t
p0.value(1)
print(t)
return k
while 1:
ex1()
輸出結果:
26167
26347
26519
Arduino 程式
#define NwIn 0
#define LED 2
void setup() {
Serial.begin(115200);
pinMode(NwIn, INPUT);
pinMode(LED, OUTPUT);
}
#define uc unsigned char
#define NUM_MAX 100000
int ex1(){
uc k[NUM_MAX/8],m,j;
int i,iMax;
long int t0,t1,t;
digitalWrite(LED, LOW);
t0=millis();
for( i=0;i
t1=millis();
t=t1-t0;
digitalWrite(LED, HIGH);
Serial.print("i=");
Serial.print(i);
Serial.print(",t0 = ");
Serial.print(t0);
Serial.print(",t1 = ");
Serial.print(t1);
Serial.print(",t = ");
Serial.print(t);
Serial.print(" millis() = ");
Serial.print(millis());
Serial.println("");
return 0;
}
void loop() {
ex1();
}
輸出結果:
i=12500,t0 = 181579,t1 = 181640,t = 61
millis() = 181640
i=12500,t0 = 181640,t1 = 181701,t = 61
millis() = 181701
i=12500,t0 = 181701,t1 = 181762,t = 61
millis() = 181762
留言