diff --git a/linux/ramp.mpy b/linux/ramp.mpy new file mode 100644 index 0000000..593eb79 --- /dev/null +++ b/linux/ramp.mpy @@ -0,0 +1,36 @@ +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 diff --git a/linux/test.mpy b/linux/test.mpy new file mode 100644 index 0000000..04390fc --- /dev/null +++ b/linux/test.mpy @@ -0,0 +1,41 @@ +from micropython import const +import machine +from time import sleep_us + +dac_sel = const(4026531844) +dac_arm = const(4026531852) +dac_fin = const(4026531848) +dac_from = const(4026531856) +dac_to = const(4026531860) + +adc_fin = const(4026531864) +adc_arm = const(4026531868) +adc_dat = const(4026531872) +adc_sel = const(4026531840) + +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) + +machine.mem8[adc_sel] = 1 +def adc_read(): + machine.mem8[adc_arm] = 1 + sleep_us(5) + machine.mem8[adc_arm] = 0 + return machine.mem32[adc_dat] diff --git a/linux/test_dac.py b/linux/test_dac.py deleted file mode 100644 index 43c0bab..0000000 --- a/linux/test_dac.py +++ /dev/null @@ -1,10 +0,0 @@ -import machine -from micropython import const - -dac_0_arm = Const(4026531852) -dac_0_finished = Const(4026531848) - -machine.mem8[dac_0_arm] = 1 -while machine.mem8[dac_0_finished] != 1: - pass -machine.mem8[dac_0_arm] = 0