CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Way to unload usb_init to save power on PIC24F before sleep?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Rubin



Joined: 12 Aug 2021
Posts: 6

View user's profile Send private message

Way to unload usb_init to save power on PIC24F before sleep?
PostPosted: Thu Aug 12, 2021 7:36 am     Reply with quote

Hello all,

I'm developing for a PIC24FJ256GB106. My goal is to optimize power draw during sleep mode, which I've done as much as possible by implementing several tricks such as disabling any parasitic draw, using an external VCORE supply, etc.

The last item which is drawing considerable power is the USB subsystem. Once I call usb_init_cs(), there is additional draw even during sleep. Is there an elegant way to turn this off before sleep? I don't see any mention in CCS docs about that, though I'm sure if I poked around with registers I could do it... I'm just to sure how the PICC USB library would like that.

Any suggestions?

Thank you
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Thu Aug 12, 2021 10:35 am     Reply with quote

Which of the wiring methods are you using for the sense connection?.
This affects what is powered from it.
Problem is that CS itself does not draw much power, but will result in the
code polling the select line, and trying to start the USB peripheral.
You should call usb_set_configured(0); to stop the USB peripheral when
you are in the low power mode. Then when you wake up re-enable this.
Rubin



Joined: 12 Aug 2021
Posts: 6

View user's profile Send private message

PostPosted: Thu Aug 12, 2021 11:32 am     Reply with quote

Thank you for your response.

I had Vbus pulled down (no USB device connected), and Vusb connected to Vdd. You made me think about that one so I disconnected Vusb temporarily and that brought my current draw down by an order of magnitude. When I'm on battery backup (for RTC), I will now not provide power to Vusb.

The usb_set_configured option was new to me, so I'll use that before sleep.

Much appreciated.
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Thu Aug 12, 2021 12:09 pm     Reply with quote

Look at the 'bus power only' wiring for Vusb. This way the USB is only
powered when the USB is connected.
Otherwise you are using a lot of power to run the USB drivers... Sad
Rubin



Joined: 12 Aug 2021
Posts: 6

View user's profile Send private message

PostPosted: Thu Aug 12, 2021 12:20 pm     Reply with quote

I had a look at "bus power only" and had it set up that way, but the biggest issue is calling usb_init... this is what I get:

Test 1
usb_init_cs(), sleep mode, Vbus = 0, Vusb = Vdd (Shown as "bus power only")
==> Draw is 0.096 mA

Test 2
usb_init_cs(), sleep mode, Vbus = 0, Vusb = 0 (Just a test to eliminate USB power)
==> Draw is 0.015 mA

Test 3
sleep mode, Vbus = 0, Vusb = 0 or Vdd (Not actually calling usb_init)
==> Draw is 0.005 mA


When I call usb_set_configured(0); it does not seem to make any difference.

Any other ideas?
Rubin



Joined: 12 Aug 2021
Posts: 6

View user's profile Send private message

PostPosted: Thu Aug 12, 2021 12:32 pm     Reply with quote

I should add - my goal is to reach the 0.005 ma (5 uA) draw... but somehow reach that after having run usb_init_cs previously. Essentially I'd like to "un-load" anything that it did. The usb_set_configured(0) doesn't seem to reach that level again.

My "work around" idea is to reset the CPU and not do usb_init_cs... but then it clears RAM, some of which I still need to hold on to while sleeping. So, not ideal.
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Fri Aug 13, 2021 6:04 am     Reply with quote

OK.

When you have Vusb powered (test 1), this automatically powers the USB
transceivers. So, of course it draws extra power.

Sorry to not have made myself clear. To disable the USB, needs:
usb_set_configured(0);
usb_detach();

The set_configured 'turns off' the presence of the USB device in the
configuration. You then need to call detach, to have it physically switched
off.
Rubin



Joined: 12 Aug 2021
Posts: 6

View user's profile Send private message

PostPosted: Fri Aug 13, 2021 8:59 am     Reply with quote

I added the usb_detach(); but no difference.

I tried a few things also just as an experiment, such as manually setting register bits:

OTGEN = 0;
DPPULUP = 0;
DMPULUP = 0;
USBEN = 0;
USBPWR = 0;

but still the Test 2 current does not change, can't drop down to the level of Test 3.

I'm at a loss right now as to what else usb_init_cs() is enabling that I can't seem to turn off.
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Sun Aug 15, 2021 1:34 am     Reply with quote

Given you have tried effectively turning the USB hardware 'off', and the
problem remains, I have to query whether your power save mode is
stopping the interrupts. Remember the chip will wake for any enabled
interrupt if it triggers. This could result in massive extra power draw.
If interrupts are setup for the USB, then usb_init_cs, will enable the USB
interrupt.
jeremiah



Joined: 20 Jul 2010
Posts: 1314

View user's profile Send private message

PostPosted: Sun Aug 15, 2021 6:27 pm     Reply with quote

You can also look at the PMD registers on the PIC24 and manually power disable stuff before you go to sleep (which is different than just turning off a specific control register enable). I found I had to do that for ADC on some of my PIC24s as they had an errata that made them not actually turn off with the control register EN set to 0, so I had to brute force it with the PMD registers.

Just be aware that setting a PMD bit for a peripheral might mean that you need to fully re-setup that peripheral when you turn it back on later.
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Mon Aug 16, 2021 1:45 am     Reply with quote

Yes.
The point about PMD, is it disables the clock to the module. Modules remain
clocked, even if disabled. Modules in general, wake from boot, with their
clocks disabled. The clock is enabled when the module is enabled. Once this
is done, disabling the module still leaves this clocking happening. Result
extra power.
Setting the PMD bit for the module concerned turns this clock off. However
it also makes all the registers for the module revert to their 'power on' state,
so the module then needs to be reprogrammed before it can be used.
Rubin



Joined: 12 Aug 2021
Posts: 6

View user's profile Send private message

SOLVED Way to unload usb_init to save power on PIC24F before
PostPosted: Mon Aug 16, 2021 7:21 am     Reply with quote

Thank you Ttelmah and jeremiah for helping me solve this mystery. The existence of Module Disable (MD) bits are mentioned in the datasheet but not specifically defined anywhere, so was difficult for me to grasp.

Now knowing of their existence, I managed to find them in the "CCS C Complier" editor UI, View -> Registers.

Added this to my code before sleeping - and IT WORKED!

Code:
#BIT USB1MD=getenv("BIT:USB1MD")
USB1MD=TRUE


Current draw went down town 0.005mA, which was my target.

Thanks again, and I hope this helps someone else while trying to reach very low power usage.

I have not yet gone through the exercise of re-initializing USB from scratch after sleep, but I'm sure there'll be a way to do that.
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Mon Aug 16, 2021 7:59 am     Reply with quote

Now your fun bit is turning it back on again.

When this is set, the peripheral is completely powered down. Loses all
it's settings. On waking, you need to clear the bit, and then reprogram
all the registers in the peripheral. Probably if you clear it, and then call
usb_init again, it ought to reset these (provided you have used
usb_set_configured(0);
usb_detach();
To switch it off beforehand.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group