import pigpio
import time
start=time.time()
#setting up the IO
pi=pigpio.pi()
pi.hardware_clock(4,6400) #Setting GPIO4 as 6.4kHz clock
pi.set_mode(17,pigpio.INPUT)#GPIO17 as input
pi.set_mode(27,pigpio.INPUT)#GPIO27 as input
pi.set_mode(22,pigpio.INPUT)#GPIO22 as input
pi.set_mode(10,pigpio.INPUT)#GPIO10 as input
pi.set_mode(9,pigpio.INPUT)#GPIO9 as input
pi.set_mode(11,pigpio.INPUT)#GPIO11 as input
pi.set_mode(5,pigpio.INPUT)#GPIO5 as input
pi.set_mode(6,pigpio.INPUT)#GPIO6 as input
count=0
def readUnoOutput(gpio, level, tick):
global count
global start
if count==0:
start=time.time()
count=count+1
if count==128:
end=time.time()
timepersample= (end-start)/128
samplerate= 1/timepersample
print (end-start)
print samplerate
#Set up GPIO callback
cb1=pi.callback(4, pigpio.RISING_EDGE, readUnoOutput)
大家好,
我使用pigpio库在6.4kHz的GPIO 4上产生时钟信号,然后在回调函数中使用该时钟脉冲,该函数应在每个上升沿调用该计数器,我们称之为样本。所以通过我的计算6400/128 = 50并且采样率应该是6400.我得到28058.似乎很简单无法弄明白。
谢谢