Qt Py 2040 doesn't wake on power-up?

For Adafruit customers who seek help with microcontrollers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
pjforde1978
 
Posts: 21
Joined: Thu Oct 30, 2014 12:48 am

Qt Py 2040 doesn't wake on power-up?

Post by pjforde1978 »

I have an Arduino sketch working well on my 2040, and the finish line is in sight. Of course, I just noticed/realized that when I disconnect and reconnect power, my project appears to be frozen until I press the reset button; then it works as expected.

This only seems to happen on power-up; resetting and flashing new code both work as expected. I can see that I2C devices have power, but don't appear to be receiving any data. (eg. no 7-segment display)

Unfortunately, this is tricky to debug as the serial interface doesn't come up and my PC doesn't see it while it's in this state. I can press boot+reset to put it into bootloader mode, and I can reset it, but nothing I can think to try just makes it wake up without human interference.

Is there some gotcha I might be missing?

User avatar
mikeysklar
 
Posts: 13824
Joined: Mon Aug 01, 2016 8:10 pm

Re: Qt Py 2040 doesn't wake on power-up?

Post by mikeysklar »

Have you tried any delay code in the early setup() period to give the sensors / output devices a chance to be detected before going right into reading them?

You could also leave a serial console connected and print out some messages to see where the code is getting stuck on boots that fail to come all the way up.

I don't think it will come down to this, but there are ways to invoke software resets on the RP2040.
  • __NVIC_SystemReset()
  • watchdog_reboot()
  • reset_usb_boot()

User avatar
pjforde1978
 
Posts: 21
Joined: Thu Oct 30, 2014 12:48 am

Re: Qt Py 2040 doesn't wake on power-up?

Post by pjforde1978 »

Thank you for this suggestion. I did add a delay(100) to the top of my setup function and I was just about to reply that you'd solved the mystery minutes after you posted... but I tested a bit more and realized that I had a Heisenbug on my hands, and the startup delay was not fixing the problem.

Well, it took a week of troubleshooting for me to accidentally realize what's happening: my 2040 only fails to boot properly when the MIDI-capable pedal I'm connected to is powered up when I turn the power on. wut!?

My project has a stock MIDI out; UART TX to Tip, 5V RAW to a 220 ohm resistor to Ring, ground to Sleeve. Since the 2040 runs on 3.3v logic, I use the 5v RAW pin to provide the required voltage on the MIDI jack.

What I figured out an hour ago is that if the MIDI cable is disconnected or the pedal is off, the 2040 powers up as expected. This is weird, since that 5v is literally just being used to illuminate an LED inside of the octocoupler of whatever device you're connected to. I suppose that the 10' cable itself introduces some impedence, but the whole point of an octocoupler is that it's electrically isolated from the host circuit.

If I had to advance a hypothesis, there's enough of a power draw spike at the moment the board gets power that if you're also trying to send power to an LED at the end of a 10' cable, there's apparently not enough juice left to power the 2040. Is that a reasonable conclusion?

So, now I'm looking for potential solutions. The first idea I had was that I could use a GPIO pin to control a relay that would engage the MIDI circuit after the 2040 has booted. This seems over-engineered, but it would work.

The second idea is fuzzy AF and I'd need someone more experienced to comment; I've seen a lot of circuits where the designer puts a capacitor between the current source and ground in parallel to "clean up". I am relatively new to this and don't have a grizzled mentor nearby so I apologize for how loose that cannon sounds.

I'm confident that there's probably a standard way to address power draw spikes with a basic jellybean component, and I'm hoping someone with a few rodeos under their belts can put me out of my misery (with my sincere thanks).

User avatar
adafruit_support_mike
 
Posts: 67391
Joined: Thu Feb 11, 2010 2:51 pm

Re: Qt Py 2040 doesn't wake on power-up?

Post by adafruit_support_mike »

Honestly, that's the kind of thing you need to measure. There are all sorts of possible issues (parasitic capacitance of the cable drawing inrush current, parasitic inductance causing voltage spikes, etc), and the best option is to eliminate the guesswork. Two minutes of data collection is worth more than a week of speculation.

Your idea of isolating the line through a relay is good, but you can get better results with less power.

Try adding a 74AHCT125 buffer between the RP2040 and the optocoupler:

https://www.adafruit.com/product/1787

The '125 is what's known as a 'line driver': it's specifically designed to provide enough current to overpower the parasitics in long runs of cable. It also uses much less power than a relay, switches faster, and will last much longer than a mechanical relay.

The '125's input impedance is somewhere in the 15M range, which won't load the RP2040. You can also put the '125 close (within 3" to 6") to the RP2040 to minimize the effects of cable parasitics.

If you find yourself needing more current than a single '125 output can provide, you can connect channels in parallel without causing any problems. The mosfets that control the output are purely resistive, so connecting them in parallel is just fine.

User avatar
pjforde1978
 
Posts: 21
Joined: Thu Oct 30, 2014 12:48 am

Re: Qt Py 2040 doesn't wake on power-up?

Post by pjforde1978 »

Thanks Mike, that helped a lot - although, possibly not in the precise way you expected.

I had an instance of "this feels way too hard" and started searching for references to how other folks dealt with MIDI in a 3.3V circuit. Well, today was the day I learned that they updated the MIDI spec with guidance for 3.3, accomplished by swapping out to lower ohm resistors. Every tutorial and article I saw, all of the popular YouTube videos on the topic (including Collin's Lab!) all talk about MIDI as a 5V protocol. This really does feel like one of those things they could mention in a lot more places, but I digress.

I reworked my project so that my MIDI was running at 3.3V. While simplifying my circuit was a big win, it did not magically solve my boot issue as I'd quietly hoped.

I was stumped again, until tonight my circuit was disconnected from power and I happened to notice the slight flicker of my I2C devices power lights. Eureka! I know what's happening: ghosts.

In addition to ghosts, the guitar pedal I'm plugged into (a Meris Enzo) follows an increasingly common convention: it supports expression pedals OR MIDI devices via the same TRS jack. It tests the impedence to decide whether the thing plugged in is a potentiometer or a MIDI signal. With the power on my project off, the pedal decides that I am an expression pedal and sends ~2.2V, expecting that I (a potentiometer) will complete the circuit and attenuate some of the voltage.

I love a good mystery! But I love solving them even more. So, now I know why this voltage is showing up and messing with the boot process of my 2040, and I need to fix it.

My hunch is that I need to insert a diode between the Ring of the TRS cable and the resistor that usually brings current to the Ring. That is, I need for current to flow in only one direction - into the TRS.

That leaves me with a new question: what kind of diode? I have been doing my best to read "how to choose a diode" articles but they all have a certain "this could only make sense to people who already understand this topic" density that is hard to crack. I've listened to Limor talk about bridging RAW pins and using a Schottky diode to make sure you don't accidentally fry your USB host. That's kind of what I need to do here, except for MIDI.

Utmel's handy "15 factors to help decide on a diode" article is a solid example of the "you're probably already an expert" phenomena. Digikey has just slightly less than 17,500 Shottky diodes available. Can we narrow this down?

User avatar
pjforde1978
 
Posts: 21
Joined: Thu Oct 30, 2014 12:48 am

Re: Qt Py 2040 doesn't wake on power-up?

Post by pjforde1978 »

I went back to Collin's Lab from 13 years ago, and went with his recommendation: 1N4001. Luckily, I have a few on hand.

Having the diode in place between the TRS Ring and the 33ohm resistor completely solves the issue. No unwanted ghost current in my circuit when plugged into random pedals. No weird, glitchy behaviour when powering up.

Thanks Mike and Mike (two Mikes? same Mike?) you have been 10/10 helpful. I've learned a ton figuring this issue out.

User avatar
mikeysklar
 
Posts: 13824
Joined: Mon Aug 01, 2016 8:10 pm

Re: Qt Py 2040 doesn't wake on power-up?

Post by mikeysklar »

Nice find with the diode fix. Thank you for the followup.

FYI : Two different Mikes.

User avatar
adafruit_support_mike
 
Posts: 67391
Joined: Thu Feb 11, 2010 2:51 pm

Re: Qt Py 2040 doesn't wake on power-up?

Post by adafruit_support_mike »

mikeysklar wrote: Thu Apr 06, 2023 2:33 pm FYI : Two different Mikes.
Yep.. he's the good-looking one. ;-)

User avatar
mikeysklar
 
Posts: 13824
Joined: Mon Aug 01, 2016 8:10 pm

Re: Qt Py 2040 doesn't wake on power-up?

Post by mikeysklar »

Yep.. he's the good-looking one. ;-)
He's the smart one who replies quickly.

Locked
Please be positive and constructive with your questions and comments.

Return to “Microcontrollers”