Running two concurrent threads

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
jickster
Posts: 629
Joined: Thu Sep 07, 2017 8:57 pm

Re: Running two concurrent threads

Post by jickster » Sat Mar 02, 2019 9:44 pm

If you only had enough time to fully finish executing the “compute the beat” code or “flash leds”, I think you would put priority on “compute the beat” because at least you could record that a beat happened.

Is my assumption correct?


Sent from my iPhone using Tapatalk Pro

hdsjulian
Posts: 31
Joined: Mon Dec 03, 2018 8:29 pm

Re: Running two concurrent threads

Post by hdsjulian » Sun Mar 03, 2019 12:27 pm

right. but even if i do it that way i can only sample 1000 times per second, right?

jickster
Posts: 629
Joined: Thu Sep 07, 2017 8:57 pm

Re: Running two concurrent threads

Post by jickster » Mon Mar 04, 2019 12:23 am

hdsjulian wrote:right. but even if i do it that way i can only sample 1000 times per second, right?
No.

One thing you have to understand is documentation is terribly incomplete.

The documentation says you can only do interrupts down to 1ms but the uPy source code shows you can do it much faster.

ports/esp32/machine_timer.c

It shows there’s a freq argument that you can use instead of the period argument.

There’s another issue: interrupt jitter.
You’re sampling audio so sampling exactly every X ms is critical.

Unfortunately the implementation of the timer isr does not call the uPy callback in the isr.
Instead, it uses mp_sched_schedule to schedule it to be executed “as soon as possible” which will introduce jitter.

What interface are you using to sample the microphone?



Sent from my iPhone using Tapatalk Pro

hdsjulian
Posts: 31
Joined: Mon Dec 03, 2018 8:29 pm

Re: Running two concurrent threads

Post by hdsjulian » Tue Mar 05, 2019 1:06 pm

true. but this won't keep me from only sampling 1000 inputs per second?

jickster
Posts: 629
Joined: Thu Sep 07, 2017 8:57 pm

Re: Running two concurrent threads

Post by jickster » Tue Mar 05, 2019 3:01 pm

hdsjulian wrote:true. but this won't keep me from only sampling 1000 inputs per second?
No


Sent from my iPhone using Tapatalk Pro

hdsjulian
Posts: 31
Joined: Mon Dec 03, 2018 8:29 pm

Re: Running two concurrent threads

Post by hdsjulian » Wed Mar 06, 2019 1:55 pm

sorry my second comment was useless. don't know how i double posted this

hdsjulian
Posts: 31
Joined: Mon Dec 03, 2018 8:29 pm

Re: Running two concurrent threads

Post by hdsjulian » Wed Mar 06, 2019 1:56 pm

using the ADC interface. it's a max4466 electret microphone

Post Reply