Problem with rmt

Here we can discuss about the problem found
Monki
Posts: 79
Joined: Mon Feb 27, 2023 12:56 pm
Location: Berlin
Has thanked: 29 times
Been thanked: 18 times

Problem with rmt

Post by Monki »

Hello Francesco,
I have a problem with the new RMT functions. I took the example from the help file and inserted a pause followed by Rmt.end 0. But pulses are still being output. Have I made a mistake in my thinking or is this a bug?

Code: [Local Link Removed for Guests]

 ' RMT example: set a sequence of 3 pulses of 1ms, 2ms, 3ms with 20msec between
dim a(10,5)
a(0,0) = 1 : a(0,1) = 1000: a(0,2) = 0 : a(0,3) = 20000
a(1,0) = 1 : a(1,1) = 2000: a(1,2) = 0 : a(1,3) = 20000
a(2,0) = 1 : a(2,1) = 3000: a(2,2) = 0 : a(2,3) = 20000
a(3,0) = 0 : a(3,1) = 0   : a(3,2) = 0 : a(3,3) = 0

 
' channel, pin, clk_div, num_blocks, idle_level, loop_en, carrier_en, carrier_freq, carrier_duty_percent, carrier_level

RMT.Setup_TX 0, 47, 80, 1, 0, 1, 1, 38000, 33, 1
RMT.ENCODE 0, 3, a()
pause 5000
RMT.END 0
end
User avatar
cicciocb
Site Admin
Posts: 2781
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 592 times
Been thanked: 1990 times
Contact:

Re: Problem with rmt

Post by cicciocb »

I've just tested on an EP32-S3 (pin 47) and the pulses stops after 5 seconds.

This is what you was expecting as result?

If you want that the pulses are generated only once, you can just use
RMT.Setup_TX 0, 47
Monki
Posts: 79
Joined: Mon Feb 27, 2023 12:56 pm
Location: Berlin
Has thanked: 29 times
Been thanked: 18 times

Re: Problem with rmt

Post by Monki »

Hello Francesco,
I have just tested the test program on some modules.
M5 Atom Echo impulses still present after program stop
M5 Atom Lite impulses still present after program stop
M5 Atom S3 Lite OK, no impulses after program end
User avatar
cicciocb
Site Admin
Posts: 2781
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 592 times
Been thanked: 1990 times
Contact:

Re: Problem with rmt

Post by cicciocb »

[Local Link Removed for Guests] wrote: [Local Link Removed for Guests]Thu Sep 19, 2024 2:18 pm Hello Francesco,
I have just tested the test program on some modules.
M5 Atom Echo impulses still present after program stop
M5 Atom Lite impulses still present after program stop
M5 Atom S3 Lite OK, no impulses after program end
Ok thanks, I'll check it
User avatar
PeterN
Posts: 641
Joined: Mon Feb 08, 2021 7:56 pm
Location: Krefeld, Germany
Has thanked: 296 times
Been thanked: 357 times
Contact:

Re: Problem with rmt

Post by PeterN »

Hi Francesco,

I am using your Morse code prog for test purposes on an ESP32S and two M5 ATOM lite.
I just changed MSG$=“SOS” and the output pin to pin 21.

Then I see the same strange effect on the three systems:
Only the first start via Autorun or via Editor+RUN works and the SOS message is morsed.
But every further manual program run now behaves very strangely, as the ticks now seem to be at least 10 times longer. Morse character output is now extremely slow, almost as if the processor ticks have suddenly slowed down.
No chance to change this until a reset.

The three ESPs were flashed after an erase - several times ... but no change.

Am I alone with this effect?
Or is it simply a bit late and am I missing something?
User avatar
PeterN
Posts: 641
Joined: Mon Feb 08, 2021 7:56 pm
Location: Krefeld, Germany
Has thanked: 296 times
Been thanked: 357 times
Contact:

Re: Problem with rmt

Post by PeterN »

To make my previous post even stranger,
The reason for the “slowdown effect” seems to be my additional command line WLOG MSG$ before the RMT.SETUP

In the following code I did this changes to CiccioCB's sample code:
- shortened the message to MSG$ = "R"
- Changed the OUTPUT PIN to pin 21 for my headphone or an LED connected to this pin
- inserted the WLOG MSG$ to see the message text

This code now slows down the output as long as I do not deactivate the WLOG line.

Tested with ESP32S and ATOM_lite and V CAN 1.60.3 LFS
Can anyone reproduce that strange effect?

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
User avatar
cicciocb
Site Admin
Posts: 2781
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 592 times
Been thanked: 1990 times
Contact:

Re: Problem with rmt

Post by cicciocb »

I'll check.
User avatar
cicciocb
Site Admin
Posts: 2781
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 592 times
Been thanked: 1990 times
Contact:

Re: Problem with rmt

Post by cicciocb »

I'm not at home actually, I'll check in next days.
User avatar
PeterN
Posts: 641
Joined: Mon Feb 08, 2021 7:56 pm
Location: Krefeld, Germany
Has thanked: 296 times
Been thanked: 357 times
Contact:

Re: Problem with rmt

Post by PeterN »

Thanks for the feedback! No need to rush!

Just to give more hints:
Did I understand that correctly(?) : Only RMT.Encode and RMT.Write should start a transmission?
RMT.Setup seems to do the same, under conditions that are still somewhat unclear to me.

Thank you and have a nice rest of the weekend.
We'll now get on our bikes and enjoy the end of the summer
User avatar
cicciocb
Site Admin
Posts: 2781
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 592 times
Been thanked: 1990 times
Contact:

Re: Problem with rmt

Post by cicciocb »

[Local Link Removed for Guests] wrote: [Local Link Removed for Guests]Sun Sep 22, 2024 9:53 am Thanks for the feedback! No need to rush!

Just to give more hints:
Did I understand that correctly(?) : Only RMT.Encode and RMT.Write should start a transmission?
RMT.Setup seems to do the same, under conditions that are still somewhat unclear to me.

Thank you and have a nice rest of the weekend.
We'll now get on our bikes and enjoy the end of the summer
There are probably some side effects.
Post Reply