Author Topic: Powering up the device from USB Micro B socket  (Read 5281 times)

ggruk

  • Member
  • ***
  • Posts: 4
Powering up the device from USB Micro B socket
« on: April 17, 2021, 02:20:00 pm »
Hi Jan & other experts on the forum

I am developing a special Energy Meter to monitor Electricity Consumption is Power Distribution Circuits.
Am using PIC32MM0256GPM064 as the MCU that comes with free USB OTG module.
This is the first time I am trying to use USB.
Have read both books of Jan and I think I am beginning to understand various aspects of implementing USB OTG.

The objectives are:
1. Save data in the meter to a Pen drive.  I feel I understand how to do this as Micro A plug will be inserted into the OTG socket.  I need to detect it, then Power up VBUS by my meter and then do whatever is needed to send data to the Pen Drive.
2. Control the Meter for Calibration & Testing by a PC or Laptop acting as a host and the Meter acting as a device.  This also seems getting clearer: Micro B plug will be inserted into the OTG socket.  USB ID pin will be 'High'. Power will be supplied by the PC / Laptop or the Meter will be self powered from the supply voltage input to it.
3. Power up the Meter by a source of Power (PC / Laptop or even a Power Bank): This is needed to power up the meter when its input voltage supply is OFF. Then use the Display Screen and Push Buttons on the meter to view various data stored in the Meter.

I need to finalise all the hardware first and soon.

My question is mainly for Objective 3:
When a Power Bank is connected with Micro B plug into the OTG socket:
Sure, I can derive a 3.3V Vdd  for the Meter by using an LDO 5V to 3.3V.
However, how can I detect that what is plugged in is only a Power Source and NOT a Host?
The USB ID pin on Micro B plug would be HIGH, but so it would be when a PC/Laptop as an active host is plugged in.
How can I differentiate between the above two conditions when a Micro B plug is inserted.

Jan's books are great!


 

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Powering up the device from USB Micro B socket
« Reply #1 on: April 17, 2021, 05:04:36 pm »
If connecting to a power source alone using the micro-B, the device wouldn't receive any communications so wouldn't think it was connected to a host.

I'm glad to hear you've found my books useful!

ggruk

  • Member
  • ***
  • Posts: 4
Re: Powering up the device from USB Micro B socket
« Reply #2 on: April 18, 2021, 03:58:20 am »
Hi Jan

Thanks.  I also thought so.
However, I was thinking that when Micro B plug is inserted into the OTG A-B socket, I need to detect this event immediately by the MCU and decide if it was a host or only a Power Supply.
If I don't detect the plugging in of the Micro B plug and make an immediate decision on if it is a host or not:
(a) I can power up an LDO from the 5V input to derive 3.3V and supply it to the Vdd of the meter through Orring diodes with the 3.3v developed from the internal power supply.  Then the Meter would be powered by whichever is present.  that it not an issue and I don't need to take any action.
(b) However, if it is a Host - how do I detect it is so and send a response to the host? Presumably, I need to do this by detecting an input communication signal from the Host?  Hope this would become clear to me once I understand more about the communication traffic protocols between the Host and Device.

Any comments or suggestions from you are most welcome.
Regards

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Powering up the device from USB Micro B socket
« Reply #3 on: April 19, 2021, 10:32:31 am »
Whichever is attached, the device will receive power, correct? If it's a host, the device will also receive enumeration requests.

ggruk

  • Member
  • ***
  • Posts: 4
Re: Powering up the device from USB Micro B socket
« Reply #4 on: April 19, 2021, 01:46:24 pm »
Hi Jan

Yes, if it is a host, it will power up the Meter (device / slave).
However, if a flash drive is attached, the power will need to be supplied by the Meter (Host).  In that case, should the Meter not initiate the enumeration request? Since I think the flash drive itself cannot initiate any request (I assume).
but I think I shall know more once I study your books further and understand the whole process of enumeration etc and who should send the first command, host or device.

In addition, I have a problem in the Meter powering up VBUS when acting as a host.
I cannot supply more than 100mA current since the power supply in the Meter is small size due to very compact size of the Meter.
I tested some Pen drives that I have collected over the years by inserting them into a Windows PC and measuring the current drawn by using Device Manager and examining the Power Tab of the properites of the USB Generic hub.
Most, except on Data Traveler 8GB flash drive showed 200 or more mA. The Data Traveler one showed 100mA but similar other Data Traveler flash drives, including a 1GB once show more current.
I don't know if this method of measuring power (really load on the USB port is correct or not.  It may be just reading this data from the file read from the flash drive and displaying that value.
I have ordered a device that measures the voltage and current drawn by a device.  Hope this will help.

I have also asked a question to Kingston and San Disk if they can supply a USB 2.0 flash drive that would draw 100ma or less, like an HID device.
Kingston have replied NO.  San Disk have not yet replied.

In the mean time I got an idea:
What if I attached an 'externally powered' flash drive to the OTG port by using A plug?
I believe there are Y type OTG cables and other combination cable where on cable supplies power and the other supplies Data.
I could then supply power to the VBUS line from say a Power Pack used for charging the mobile phone and connect the D+, D- lines to the OTG socket on the Meter.
This way, VBUS and GND will always have power supplied by the Power pack. I then don't have to power up the VBUS line from the Meter.
In this case, the power from the Power pack will power up and 'wake up' the Meter when voltage input to it is absent.
I was thinking of doing this to power up the Meter in such cases to enable the user to read the data in the Meter on the screen.

However, if I use this solution of plugging in externally powered flash drive, then there should be no need for the Meter to supply power.
In fact then in case of any of the three ways, VBUS line will be powered up by:
External Power pack, Powered Flash drive or a host (PC, Laptop or a mobile phone).
My meter would not need more than 50mA.  So, even an OTG port on a mobile can address it as a device.
Then, I do not have to add ckt to convert 3.3V bus in the Meter to 5V for USB port.
Just add an LDO to convert VbUS 5V to 3.3V to drive Vdd of the Meter ckt through ORRING diodes.

What is your opinion on the above solution?
Also is it possible if I do the data transfer at Low Speed, would this reduce the current drawn by the USB Pen drive.
the problem is that there are so many makes of Pen drives and their characteristics (and quality) vary quite a lot.
No manufacturer seems to indicate correctly what current it would require: Idle, Read and Write.

Regards

bpaddock

  • Frequent Contributor
  • ****
  • Posts: 66
Re: Powering up the device from USB Micro B socket
« Reply #5 on: April 20, 2021, 08:12:37 am »
Write will always take more current than anything else.
USB and low power more often than not don't go together.

In general the larger the capacity of the USB stick the more current it will take.

I don't trust what I get from Windows as far as current readings.

Pick up a KW203 USB power meter for about $15.
There are some fancier versions of it that will do power logging as well.

Find a simple two or four port hub that you can supply with your device to power the USB stick.
Those are far easier to find off the shelf (pre shortage issues) than funky split cables.

Lots of shortages are starting to happen for any kind of Chip and their downstream devices.
No one is expecting it to get any better any time soon.  Maybe in 2023 or 2024.
Taiwan makes 2/3rd of the worlds chips and they are in a severe drought,
and making chips takes water.  Plus the world political Theater involving Taiwan,
which is also about the Chips, to add to the shortage drama.





ggruk

  • Member
  • ***
  • Posts: 4
Re: Powering up the device from USB Micro B socket
« Reply #6 on: April 20, 2021, 02:35:40 pm »
Hi Jan

I have already ordered a USB Meter a couple of days ago.  Am getting it in a couple of days.
Have also ordered some cables.
Shall do some experimentation and post the results.

My preference is to power the USB flash drive from the Power Pack, if I can do it with a Y cable.
Then, I do not have to build a 3.3 to 5V converter in my meter.

Renate

  • Frequent Contributor
  • ****
  • Posts: 97
Re: Powering up the device from USB Micro B socket
« Reply #7 on: April 27, 2021, 12:34:04 pm »
Just a random data point...
This is an 8 GB flash drive I had hanging around.
This shows insertion.
The mostly flat section is reads, which is the same as idle.
The bumpy section is copying over a large file.