- Changed the OUTPUT PIN to pin 21 for my headphone or an LED connected to this pin
This code now slows down the output as long as I do not deactivate the WLOG line.
EDIT: Effect only to be observed if program is manually started from EDITOR window. NO slow down if program is run from autostart and no editor connected.
Code: [Local Link Removed for Guests]
'Demo of morse code generation using the RMT module
MSG$ = "WELCOME TO ANNEX RDS 01234567890 The quick brown fox jumps over the lazy dog"
MSG$ = "R"
WLOG MSG$
' Use channel 0, GPIO pin 47, 255 divider, 1 buffer, idle 0, no loop 0, carrier enabled1, carrier freq 1000Hz
RMT.SETUP_TX 0, 21, 255,1 ,0, 0, 1, 1000
'80MHz / 255 = 3.1875uS / count
'1 dot = 20000 counts = 63.75 msec
'1 dash = 60000 counts = 191.25 msec
'the speed can be increased reducing the divider
data "A", "10", "B", "0111", "C", "0101", "D", "011", "E", "1", "F", "1101"
data "G", "001", "H", "1111", "I", "11", "J", "1000", "K", "010", "L", "1011"
data "M", "00", "N", "01", "O", "000", "P", "1001", "Q", "0010", "R", "101"
data "S", "111", "T", "0", "U", "110", "V", "1110", "W", "100", "X", "0110"
data "Y", "0100", "Z", "0011"
data "0", "00000", "1", "10000", "2", "11000", "3", "11100", "4", "11110"
data "5", "11111", "6", "01111", "7", "00111", "8", "00011", "9", "00001"
data " ", "/"
data "END", "END"
'read the table
morse$ = "" 'contains all the symbols in a text format A=01 ....B=.
do
read a$, b$
morse$ = morse$ + a$ + "=" + b$+ chr$(10)
loop until (a$ = "END")
' Define the sequence of pulses (max 64)
Dim pulses(64)
'compute the pulses polarity and duration in a single 32bits value
sub set_timing(w, p0, t0, p1, t1)
w = (p1 << 31) or (t1 << 16) or (p0 << 15) or t0
end sub
'set the duration of each part
dot=0 : dash = 0 : blank = 0 : space = 0
set_timing dot, 1, 10000, 1, 10000
set_timing dash, 1, 30000, 1, 30000
set_timing blank, 0, 10000, 0, 10000
set_timing space, 0, 30000, 0, 30000
' Function to set RMT item for '0' ,'1' 'S' or '/'
SUB SetRMTItem(index, bit$)
IF bit$ = "0" THEN
pulses(index) = dash : incr index
pulses(index) = blank: incr index
ELSEIF bit$ = "1" THEN
pulses(index) = dot : incr index
pulses(index) = blank: incr index
ELSEIF bit$ = "S" THEN ' (space between symbols)
pulses(index) = space : incr index
ELSE ' (/) space between words
pulses(index) = space : incr index
pulses(index) = space : incr index
pulses(index) = blank : incr index
ENDIF
END SUB
k = 0 'contains the total of pulses to be sent
for i = 1 to len(MSG$)
c$ = ucase$(MID$(MSG$, i, 1))
s$ = Word.GetParam$(morse$, c$)
FOR z = 1 TO LEN(s$)
SetRMTItem k, MID$(s$, z, 1)
NEXT z
SetRMTItem k, "S" ' separator between symbols
RMT.WRITE 0, k, pulses()
k = 0
next i
end