37 lines
758 B
Plaintext
37 lines
758 B
Plaintext
|
from micropython import const
|
||
|
from time import sleep_us
|
||
|
import machine
|
||
|
|
||
|
dac_sel = const(4026531844)
|
||
|
dac_arm = const(4026531852)
|
||
|
dac_fin = const(4026531848)
|
||
|
dac_from = const(4026531856)
|
||
|
dac_to = const(4026531860)
|
||
|
|
||
|
machine.mem8[dac_sel] = 1
|
||
|
|
||
|
def dac_comm(val):
|
||
|
machine.mem32[dac_to] = val
|
||
|
machine.mem8[dac_arm] = 1
|
||
|
while machine.mem8[dac_fin] == 0:
|
||
|
pass
|
||
|
machine.mem8[dac_arm] = 0
|
||
|
|
||
|
def dac_read(val):
|
||
|
dac_comm(1 << 23 | val)
|
||
|
dac_comm(0)
|
||
|
v = bin(machine.mem32[dac_from])
|
||
|
print(v, len(v) - 2)
|
||
|
|
||
|
# dac_comm(0b11010010001)
|
||
|
dac_comm(1 << 22 | 1 << 2)
|
||
|
dac_comm(1 << 21 | (1 << 1))
|
||
|
dac_read(1 << 21)
|
||
|
|
||
|
def dac_ramp_up(fromval,toval,step,ival):
|
||
|
assert step > 0
|
||
|
while fromval <= toval:
|
||
|
dac_comm(1 << 20 | fromval)
|
||
|
sleep_us(ival)
|
||
|
fromval = fromval + step
|