Close

Mystery of the 3/4 plug

A project log for Knobbox: Modal USB knob

Control volume, brightness, temperature, and more with a single knob.

sprospro 11/14/2015 at 09:494 Comments

I'm trying to debug the ATTiny85 version and I've found how to make it work 100% of the time, but it's a weird ritual and I'm not sure why it works.

If I plug in the USB cable 3/4 of the way, it connects perfectly. If I plug it in all the way, the USB device fails to enumerate.

My research so far tells me the most likely cause is a calibration failure. But given the scenario above, what could cause it to miscalibrate only when fully plugged in?

Discussions

Stefan Lochbrunner wrote 11/14/2015 at 20:23 point

I've had some trouble with enumeration with VUSB in #Pro Trinket USB Keyboard as well. Have you tried commenting out the 'Optional Hardware Config' section (only affects 2 lines) in usbconfig.h? See usbdrv.h, around line 307, for a description of what commenting out those lines does.

  Are you sure? yes | no

spro wrote 11/14/2015 at 20:59 point

Interesting, looks like those were already commented out - though I am calling usbDeviceConnect and usbDeviceDisconnect. Are they meaningless if D- is pulled up directly?

I'm starting to have some success by simply increasing the startup delay (time between the initial disconnect and reconnect) from ~300ms to ~600ms. Still looks like calibration is likely to go awry when fully plugged in, but it's making it through more often...

  Are you sure? yes | no

Stefan Lochbrunner wrote 11/15/2015 at 01:43 point

They are not meaningless. Instead of handlingthe pull-up another 'function' is called to force D- low. The connect and disconnect 'functions' are in usbdrv.h just above line 307, take a look.

From that board layout it looks like you're using a 10k pull-up on D-, right? I think the reference calls for a 1.5k resistor and some even suggest using an even lower value (like 1.2k). Another thing I noticed in that 'schematic' is that you're powering the ATtiny from USB meaning 5V and also have its outputs connected to the data lines. USB spec is only 3.3V on the data lines as far as I know. Therefore you could either add those zener diodes or drop the supply voltage of the MCU.

  Are you sure? yes | no

spro wrote 11/15/2015 at 10:31 point

I did a few trials with better resistor values and a voltage regulator, but was seeing the same problem. Eventually I started picking at the code line by line, and found (nearly by accident) that it would work with one extra 50ms delay before calling sei() and starting the main loop.

It would probably make more sense looking at the code (note to self) but I think enabling interrupts too early was causing oscillator calibration to fail by triggering a pin change interrupt (for reading the rotary encoder) and... interrupting it.

This doesn't really explain the mystery of the 3/4 plug, except maybe that the last 1/4 of pluggedness added enough extra noise to trigger that interrupt. But it's working now, every time!

  Are you sure? yes | no