Close

ESP32 & MicroPython 4-bit chopper

A project log for Retrex Audio

Experimentation in AY-3-8910 / AY-3-8912 sound synthesis

xbeauxBeau 01/25/2020 at 08:240 Comments

Converting setup to run on ESP32 rather than off of Arduino. Did some bit bang poking with an external clock and got it to make a sound. Hacked up some code to initialize and use ESP32 GPIO 22 for clock (Also tried 18 with hardware SPI, different challenges).

There's a issue with PWM using 10-bit duty resolution and limiting the frequency to just of 78Khz. This should be able to go up to 40Mhz with 1-bit resolution duty, but gonna track that down later.


Here's what generators a "chopper" noise.

Utilizing the WiFi is totally optional, configured so that I can update main.py using WebREPL.

from time import sleep, sleep_ms, sleep_us
from machine import Pin, PWM
import network

print("AY-3-8910 teal 00:10")

#bork break
sleep(1)

sta = network.WLAN(network.STA_IF)
sta.active(True)

sta.connect('SSID', 'PASSWORD')

print("WiFi Started")

#      dir 1
#INACT  0  0
#LATCH  1  1
#WRITE  1  0
#READ   0  1
bdir = Pin(17, Pin.OUT, value=0)
bc1 = Pin(16, Pin.OUT, value=0)

da0 = Pin(32, Pin.OUT, value=0)
da1 = Pin(33, Pin.OUT, value=0)
da2 = Pin(25, Pin.OUT, value=0)
da3 = Pin(26, Pin.OUT, value=0)

clock = PWM(Pin(22), 78000)

def inact():
  bdir.off()
  bc1.off()
  sleep_ms(1)

def latch():
  bdir.on()
  bc1.on()
  sleep_ms(1)

def write():
  bdir.on()
  bc1.off()
  sleep_ms(1)

def read():
  bdir.off()
  bc.on()
  sleep_ms(1)

print("Initializing 'A'")

#Enable Register 8 (A Level)
latch()
da0.off()
da1.off()
da2.off()
da3.on()
inact()

#Write A Level
write()
da0.on()
da1.on()
da2.on()
da3.on()
inact()

#Enable Register 1 (A Frequency)
latch()
da0.on()
da1.off()
da2.off()
da3.off()
inact()

#Write A Frequency
write()
da0.off()
da1.off()
da2.off()
da3.on()
inact()

print("b0001")

Discussions