Replies: 2 comments
-
Hi Everyone! But I will also show you how RMT can be used for controlled generation of high-accuracy pulses. For this you need the following commands: rmt = esp32.RMT(0, pin=Pin(5), clock_div=div1) rmt is an RMT instance, div1 can be changed from 2 to 255 and div2 from 2 to 32767, rmt.loop loops the sequence (1,0) The frequencies that can be obtained are in the formula: f = 80000000/2/div1/div2 i.e. for the given ranges div1 and div2 from 20000000Hz to 9.5Hz. Signal stability results from the stability of the internal clock. The signal is symmetrically rectangular. rmt.write_pulses(div2,(0,0)) of course, resuming the generator requires the command: rmt.write_pulses(div2, (1,0)) To quickly change the frequency, just use the command: rmt.write_pulses(div2_new, (1,0)) If the clock_div value is changed (div1), first three commands must be repeated again. I hope this information will be useful to someone eljot |
Beta Was this translation helpful? Give feedback.
-
If you want to control the number of pulses you can pass a list to |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Try, with success, to use RMT as stable, but regulated generator to drive step engine (using drv8255) with frequency in range tens to hundreds pulses per second. The example code is as follow:
r = esp32.RMT(0, pin=Pin(2), clock_div=224)
r.loop(True)
r.write_pulses(2267, (1,0))
this generates symmetric pulses (1,0) with frequency 8e6/224/2267 and frequency can be modify for example by change div.
The question is how to control count of done pulses?
Of course pin 2 can be connected by short for example to pin 4 and setup interrupt handler on pin 4 as follow:
def handle_interrupt(pin):
global count
count = count +1
print (count)
if count .........
cl = Pin(4, Pin.IN)
cl.irq(trigger=Pin.IRQ_RISING, handler=handle_interrupt)
in this case exists full control over done pulses count but one port is wasted just for pulse counting.
I've tried to make Pin interrupt on the same port as rmt:
cl = Pin(2, Pin.IN)
cl.irq(trigger=Pin.IRQ_RISING, handler=handle_interrupt)
but if such declaration exist before rmt definition then rmt overwrite pin interrupt and pin interrupt doesn't work or when exist after rmt definition then rmt doesn't work.
UPython rmt description doesn't mention about interrupts handling for RMT but rather warning:
"Warning
The current MicroPython RMT implementation lacks some features, most notably receiving pulses. RMT should be considered a beta feature and the interface may change in the future."
but maybe exist way to workaround it more elegantly?
eljots
Beta Was this translation helpful? Give feedback.
All reactions