"""
https://wokwi.com/projects/402030690974832641
"""
import time
from machine import ADC, Pin, freq
# # Set the clock frequency to 250 MHz
# freq(250_000_000)
# Initialize the ADC (ADC0 is connected to GPIO26)
adc_0 = ADC(Pin(26))
adc_1 = ADC(Pin(27))
# Set GPIO2 and GPIO3 as outputs for input multiplexers
mux_a = Pin(2, Pin.OUT)
mux_b = Pin(3, Pin.OUT)
def time_adc_read(num_reads=1_000):
t0 = time.ticks_us() # Get the start time in microseconds
for _ in range(num_reads):
adc_0.read_u16() # Perform ADC read
t1 = time.ticks_us() # Get the end time in microseconds
dt = time.ticks_diff(t1, t0) # Calculate the elapsed time
time_per_read = dt / num_reads
return time_per_read
def set_input_channel(channel):
if channel == 0:
mux_a.off()
mux_b.off()
elif channel == 1:
mux_a.on()
mux_b.off()
elif channel == 2:
mux_a.off()
mux_b.on()
else:
mux_a.on()
mux_b.on()
def read_adcs():
adc_value_0 = adc_0.read_u16()
adc_value_1 = adc_1.read_u16()
voltage_0 = adc_value_0 * 3.3 / 65535
voltage_1 = adc_value_1 * 3.3 / 65535
print("ADC Voltages: {:.2f} {:.2f}".format(voltage_0, voltage_1))
def check_dacs():
print()
print()
for channel in range(3):
set_input_channel(channel)
time.sleep(0.2)
read_adcs()
print()
time.sleep(1)
while True:
# print(f'Time: {time_adc_read()} µs')
check_dacs()
Loading
cd74hc4067
cd74hc4067
Loading
cd74hc4067
cd74hc4067