Author Topic: Surprising USB and P4 PWM interraction  (Read 2839 times)

bboyes

  • Newbie
  • *
  • Posts: 7
Surprising USB and P4 PWM interraction
« on: February 10, 2013, 12:33:22 pm »
I just got my Kickstarter package on Friday and have put together the RGB shield as a place to start writing some code. I'm looking at using the sparks as local lighting controllers, so that's another reason to start with the RGB LED. On the shield I cut the trace and soldered to enable P4 (with PWM) to drive the blue LED channel. My sample program is eventually going to mix all possible RGB colors, etc.


So far so good, but I notice that since P4 is shared with USB (according to the RGB shield page), the blue channel flickers when programming via the uploader.


Also it seems that when I analogWrite(4,0) a zero to P4, the PC detects that as a USB event. I hear the USB disconnect tone, then later when driving another color I get the USB reconnect tone, and after a few cycles of this I get the Windows 7 message"USB device not recognized".


This USB disconnect/reconnect still happens with the DigiSpark IDE closed. If I don't write a true PWM 0 to the P4 pin the USB doesn't get upset: 0x01 is enough to keep it quiet. It seems the analog zero is needed to alert the PC's USB that I am up to no good.


Any way around this? Can I cause the USB port any physical damage (I would think not) or will it just be annoyed at me?


Bluebie

  • Sr. Member
  • ****
  • Posts: 486
Re: Surprising USB and P4 PWM interraction
« Reply #1 on: February 10, 2013, 07:57:32 pm »
The main way around it is to power the digispark using a different power supply - a usb phone charger works well, or you can hook up something between 7 and about 30 volts to the VIN and GND connection points.


PWMing the USB port wont cause hardware damage in your computer, but it will upset your computer, and you might find it affects the performance of your computer or even might cause system crashes if the USB drivers get too confused.