Comparators

Comparators are useful in many situations. In this example, we compare two sine waves of different frequencies and generate a pulse wave.

import zrna
z = zrna.api.Client()
z.connect()
z.clear()

sine_osc1 = z.OscillatorSine(
    oscillation_frequency=1,
    peak_amplitude=2
)

sine_osc2 = z.OscillatorSine(
    oscillation_frequency=2,
    peak_amplitude=2
)

c = z.Comparator()
c.compare_to = z.SECOND_INPUT

g = z.GainInv(gain=0.25)

for module in [sine_osc1, sine_osc2, c, g]:
    module.set_clock(z.CLOCK3)
    z.add(module)

audio_out = z.AudioOut()
z.add(audio_out)

sine_osc1.output.connect(c.noninverting)
sine_osc2.output.connect(c.inverting)

c.output.connect(g.input)
g.output.connect(audio_out.input)

z.set_divisor(z.CLOCK_SYS1, 4)
z.run()
Privacy

© 2024 Zrna Research