Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Master clock #162

Merged
merged 64 commits into from
Oct 16, 2022
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
844af6e
Merge branch 'main' of https://github.com/gamecat69/EuroPiApps
anselln Jul 27, 2022
799ac02
initial master clock commit
anselln Jul 29, 2022
bcf1a56
removed import random
anselln Jul 29, 2022
9dd75e0
PW now set as a percentage within min and max limits
anselln Jul 30, 2022
cfebf48
ain can now control BPM
anselln Jul 31, 2022
b4747e7
updated description. divisions are now vars.
anselln Aug 1, 2022
2ee2dfa
Running by default. Added self.msDriftCompensation
anselln Aug 1, 2022
b2a6456
tweaked description
anselln Aug 1, 2022
d142931
reverted clock divisions to original vals
anselln Aug 1, 2022
79b7523
Lowered min BPM
anselln Aug 1, 2022
7be6970
added to menu. New UI.
Aug 2, 2022
3fb3095
added ain BPM control back in
Aug 3, 2022
7849f71
cleaned up lists, increased max division
Aug 3, 2022
a6290cb
updated screen2 UI
Aug 3, 2022
cd104a7
updated documentation
Aug 3, 2022
8fccc92
name change: calcSleepTime. Moved MAX_PULSE_WIDTH calc
Aug 3, 2022
ce64858
auto reset at max configured division
Aug 3, 2022
8de27c7
added random division (0)
Aug 3, 2022
a483100
updated docs
Aug 3, 2022
21c4aa8
added turingmachine back to menu
Aug 3, 2022
0bf4b75
Changed name of self.previousSelectedDivision
Aug 3, 2022
ac3d5f1
added import error handling
Aug 3, 2022
cfcb5d9
removed duplicate self.el.run_forever()
Aug 3, 2022
385ef33
updated UI down to 2 screens
Aug 4, 2022
3772faa
revert to last saved bpm and PW if no ain voltage
Aug 5, 2022
1774ca8
major. improved UI. streamlined outputDivisions using a list
Aug 5, 2022
8b9e89c
keep clock running when in config mode
Aug 5, 2022
ca89c26
Added msDriftCompensationConfigMode to config slowdown
Aug 5, 2022
477b94c
updated scrn2 function comment
Aug 5, 2022
d2b9c48
increase bpm k2 tolerance. update max bpm k2 value. optimize division…
Aug 5, 2022
4fd40e0
allow pw > 50%. Add asyncio catch
Aug 8, 2022
03c03db
updated known issues
Aug 8, 2022
2a84830
removed commented line
Aug 8, 2022
d5b1412
increased self.MIN_AIN_VOLTAGE to avoid issues with some EuroPis
anselln Aug 9, 2022
df0bb7a
updated note. Now resets at lcm not max division.
Aug 12, 2022
51e2198
update comment
Sep 13, 2022
9a8633e
minor mod to try and align with upstream..
anselln Oct 16, 2022
829aeb8
Merge branch 'master_clock' of https://github.com/gamecat69/EuroPiApp…
anselln Oct 16, 2022
10d4339
upstream sync attempt...2
anselln Oct 16, 2022
b617f20
Revert "Merge branch 'main' of https://github.com/gamecat69/EuroPiApps"
anselln Oct 16, 2022
67051b9
Revert "sync with upstream - hopefully!"
anselln Oct 16, 2022
78e1813
lcm and randint changes from rory to prevent divide by zero
anselln Oct 16, 2022
31098ec
merge from hell reprise
anselln Oct 16, 2022
c633027
more merge issues
anselln Oct 16, 2022
bd485ba
Re-add Turing Machine and import MasterClock
roryjamesallen Oct 16, 2022
81a01cd
Re-add SmoothRandomVoltages
roryjamesallen Oct 16, 2022
9b44332
:(
anselln Oct 16, 2022
aefd25e
:(
anselln Oct 16, 2022
bac5fe1
:(
anselln Oct 16, 2022
272eaba
:(
anselln Oct 16, 2022
4296db7
..
anselln Oct 16, 2022
66f573e
..
anselln Oct 16, 2022
db2e2de
loading screen
anselln Oct 16, 2022
97ac650
sync with upstream
anselln Oct 16, 2022
06d9577
upstream sync
anselln Oct 16, 2022
307d52f
upstream sync
anselln Oct 16, 2022
c71cc9a
upstream sync
anselln Oct 16, 2022
00ea21e
upstream sync
anselln Oct 16, 2022
09f3247
upstream sync
anselln Oct 16, 2022
06a9e36
upstream sync
anselln Oct 16, 2022
9f8212c
upstream sync
anselln Oct 16, 2022
1596ed2
upstream sync
anselln Oct 16, 2022
b8c3a82
added probapoly to menu
anselln Oct 16, 2022
83d594a
Merge branch 'main' into master_clock
roryjamesallen Oct 16, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions software/contrib/cvecorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def __init__(self):
#self.CvRecording = [] # CV recorder flags

# Load CV Recordings from a previously stored state on disk or initialize if blank
self.showLoadingScreen()
#self.showLoadingScreen()
self.loadState()

# Test routine, pick a random bank n times and save, then load the state
Expand Down Expand Up @@ -285,7 +285,7 @@ def saveState(self):
def loadState(self):

# For each bank, check if a state file exists, then load it
# If not, initialize the bank with zeros
# If not, initialize the bank with zeros then save it

# Potential issue......
# If for some reason the file open command fails, it will init each bank and wipe any previous recordings
Expand All @@ -306,7 +306,7 @@ def loadState(self):
fileName = f"saved_state_{self.__class__.__qualname__}_{b}.txt"

# Write the value to a the state file
maxRetries = 6
maxRetries = 2
attempts = 0
while attempts < maxRetries:

Expand All @@ -320,6 +320,7 @@ def loadState(self):
if self.initTest:
print(f"Loading previous state for bank: {str(b)}. Size: {len(jsonData)}")

self.showLoadingScreen(str(b))
if self.debugLogging:
self.writeToDebugLog(f"[loadState] [{attempts}] Loading previous state for bank: {str(b)}. Size: {len(jsonData)}")

Expand Down Expand Up @@ -347,14 +348,17 @@ def loadState(self):
self.CVR[b].append([])
for n in range (0, self.stepLength):
self.CVR[b][i].append(0)
# Save the state file for faster loading on next boot
self.bankToSave = b
self.saveState()

except Exception as e:
self.errorString = 'r'
self.errorString = 'x'
if self.debugLogging:
self.writeToDebugLog(f"[loadState] [{attempts}] Exception when attempting to open previous state file for bank {b}. {e}")

# Sleep and increment attempt counter
sleep_ms(500)
sleep_ms(50)
attempts += 1

# Currently not used, but keeping in this script for future use
Expand All @@ -379,8 +383,9 @@ def main(self):

# If I have been running, then stopped for longer than reset_timeout, reset the steps and clock_step to 0
if self.clockStep != 0 and ticks_diff(ticks_ms(), din.last_triggered()) > self.resetTimeout:
self.step = 0
self.clockStep = 0
if self.CvRecording[self.ActiveCvr] != 'true':
self.step = 0
self.clockStep = 0

def getCvBank(self):
# Read CV Bank selection from knob 1
Expand Down Expand Up @@ -428,14 +433,14 @@ def writeToDebugLog(self, msg):
except Exception as e:
print(f'[{attempts}] Error writing to debug log. {e}')

def showLoadingScreen(self):
def showLoadingScreen(self, bank):
# push the bytearray of the Rpi logo into a 32 x 32 framebuffer, then show on the screen

buffer = bytearray(b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00|?\x00\x01\x86@\x80\x01\x01\x80\x80\x01\x11\x88\x80\x01\x05\xa0\x80\x00\x83\xc1\x00\x00C\xe3\x00\x00~\xfc\x00\x00L'\x00\x00\x9c\x11\x00\x00\xbf\xfd\x00\x00\xe1\x87\x00\x01\xc1\x83\x80\x02A\x82@\x02A\x82@\x02\xc1\xc2@\x02\xf6>\xc0\x01\xfc=\x80\x01\x18\x18\x80\x01\x88\x10\x80\x00\x8c!\x00\x00\x87\xf1\x00\x00\x7f\xf6\x00\x008\x1c\x00\x00\x0c \x00\x00\x03\xc0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00")
fb = framebuf.FrameBuffer(buffer, 32, 32, framebuf.MONO_HLSB)
oled.fill(0)
#oled.blit(fb, 0,0)
oled.text('Loading...', 40, 12, 1)
oled.blit(fb, 0,0)
oled.text(f'Loading ({bank})...', 40, 12, 1)
oled.show()

def updateScreen(self):
Expand Down
70 changes: 70 additions & 0 deletions software/contrib/master_clock.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# EuroPi Master Clock and Clock Divider

'''
Master Clock
author: Nik Ansell (github.com/gamecat69)
date: 2022-08-02
labels: clock, divider

A master clock and clock divider. Each output sends a +5V trigger/gate at different divisions of the master clock, or randomly if condigured with a division of zero.
Pulse width (gate/trigger duration) is configurable up to a maximum of 50% of the pulse width of output 1.

All configuration (BPM, Pulse Width, output clock divisions) is automatically saved, then loaded when the module is restarted.

For wonky/more interesting clock patterns try these:
- Reset to step 1 using a gate into the digital input, or by using an odd value for the maximum division
- Vary BPM by sending CV into the analog input
- Set the division to zero for an output, this will cause the output to randomly go from high (+5V) to low (0V)

Demo video: TBC

digital_in: (optional) Reset step count on rising edge
analog_in: (optional) Adjust BPM

knob_1: Screen 2: Adjust BPM. Screen 3: Select output to edit
knob_2: Screen 2: Adjust Pulse width. Screen 3: Adjust division of selected output

button_1: Start / Stop
button_2: Short Press (<500ms): Cycle through screens. Long Press (>500ms): Enter config mode

Defaults:
output_1: clock / 1
output_2: clock / 2
output_3: clock / 4
output_4: clock / 8
output_5: clock / 16
output_6: clock / 32

Known Issues:
- If playback is restarted while screen 2 is in config mode, playback will be slightly irratic

# Getting started

Patch any module that uses gates/triggers to any output! By default the module will run at 100 BPM, using a 50% pulse width and send gates using the default divisions (1,2,4,8,16,32).

# Configuring / Playing around

Use button 2 (right button) to cycle through screens 1 - 3. A description of each screen is shown below.
Hold button 2 for 2 seconds to enter configuration mode when in screen 2 or 3.
Configuration mode will exit when changing screens to avoid accidentally changing any values on the next screen.
Also note that playback will stop when in config mode.
Each screen has a small indicator on the bottom right to show the screen you are on.

## Screen 1
- Top: Number of completed cycles since playback was last started, follewed by the current step in the cycle
- Bottom: Instruction to use B1 to toggle start/stop

## Screen 2
- BPM
- Pulse Width (PW) as a percentage of the output 1 division and also as milliseconds

Hold button 2 for 2 seconds to enter configuration mode, then use knob 1 (left) to adjust BPM and knob 2 (right) to adjust pulse width. To exit configuration mode, just press button 2 to move to the next screen.

## Screen 3:

This screen shows the configured clock division for each output.
To edit a clock division for an output:
- Use knob 1 to select the output you want to edit
- Press and hold button 2 for 2 seconds to enter configuration mode
- Use knob 2 to select the division you want that that output. Setting a division to zero will produce random fluctuations between 0V and +5V.
- Exit configuration mode by pressing button 2 to move to the next screen
Loading