In [1]:
import magma as m
m.set_mantle_target('ice40')
In [2]:
from mantle import Counter, ULE
from loam.boards.icestick import IceStick
N = 8
def PWM(n):
return ULE(n)
icestick = IceStick()
icestick.Clock.on()
for i in range(8):
icestick.J1[i].input().on()
icestick.J3[0].output().on()
main = icestick.main()
counter = Counter(32)
sawtooth = counter.O[8:8+N]
# alternatively, reverse bits before feeding to comparitor
# sawtooth = array([counter.O[8+N-1-i] for i in range(N)])
pwm = PWM(N)
m.wire( pwm( sawtooth, main.J1 ), main.J3 )
m.EndDefine()
In [3]:
m.compile('build/pwm', main)
In [4]:
%%bash
cd build
cat pwm.pcf
yosys -q -p 'synth_ice40 -top main -blif pwm.blif' pwm.v
arachne-pnr -q -d 1k -o pwm.txt -p pwm.pcf pwm.blif
icepack pwm.txt pwm.bin
iceprog pwm.bin
We can wire up the GPIO pins to a logic analyzer to verify that our circuit produces the correct waveform.
In [ ]: