# mPy - demo high freq generation on esp32s2
# Provided by Anthony Vogelaar, Perth Scotland
# rev 0.10  2024-07-04  initial release

from	machine import Pin, freq; 		freq(240000000)
from	esp32	import RMT
import	time

# ========================= Tests ===========================

# highest frequency in burst (80 MHz --> 40 MHz square wave = 25 nSec)
def test1():
#    pattern = [1, 0]*8
#    pattern = [0, 0, 1, 0]
    pattern = [0, 0] + [1, 0]*8
    rmt = RMT(0, pin=Pin(16), clock_div=1)
    while True:
        for i in range(1000):
            rmt.write_pulses(1, pattern)
            time.sleep_ms(1)
        print('*', end='')


# highest frequency in loop (2.6 MHz square wave
def test2():
    pattern = [1, 0] * 63					# maximum 127 pulses per loop
    rmt = RMT(0, pin=Pin(16), clock_div=1)
    rmt.loop(True)
    rmt.write_pulses(15, pattern)			# minimum pattern length foor loop 12.5 x 15 x 126 = 23.7 uSec
    while True:
        print('*', end='')
        time.sleep(1)

# ============================ Main ===========================

test2()

# ============================= End ===========================
