PIC16F917 weak pull-ups during SLEEP  - Page 1
Forum section: electronics / general

author: Miti
author_rank: Super Contributor
timestamp: July 29, 2025, 02:43:14 pm
content: Hi,I have a project with the aforementioned mcu that goes to sleep after a long press on RB0/INT. It wakes up perfectly after another long press. In sleep it only take about 625nA.However, if I leave it in sleep for long time, half a day, a day, it either take an extra long press to wake up or it doesn’t wake up at all.I’m using the internal weak pull up on RB0 and I cannot find anywhere that it is disabled during sleep. Chatgpt however insists that it is disabled and asks me to add an external pull up, which is ok, I have provision on the board, but I cannot find any reference to the RPU status during sleep.So, are the pull-ups active or inactive during sleep? That is the question…Thanks,Miti

author: jpanhalt
author_rank: Super Contributor
timestamp: July 30, 2025, 11:05:42 am
content: Sleep should not affect the OPTION_REG (attachment), but resets do. Are you sure it is not going through a reset during a long sleep? A temporary external WPU would help troubleshoot.

author: mikeselectricstuff
author_rank: Super Contributor
timestamp: July 30, 2025, 11:40:10 am
content: If the pullup wasn't active, it would (maybe) wake prematurely due to pin floating, not fail to wake.You can easily test pullups by measuting current to ground.The issue is proibably with the code you're using to measure the length of the "long" press. It will wake immediately on the falling edge, then it's down to you to measure the low time and decide whether to wake or not.

author: jpanhalt
author_rank: Super Contributor
timestamp: July 30, 2025, 01:18:22 pm
content: It's confusing. I confirmed with Grok3 that AI says WPU's on that series of PIC are disabled during sleep to save power, but the reference give, "4.2.3," doesn't exist. Ports are in sections 3.x.x . Here's what that a part of that sectio says about IOC:QuoteI realize the IOC pins are RB4..RB7, not RBO/INT as Miti is using. Does that imply the state of the other PORTB pins is unknown during sleep but becomes known upon wake-up? Second, why does a long press work with a short sleep but not a long sleep? Explaining that is why I wondered whether the chip goes through a reset for some other reason (noise on MCLR??), which would turn off the WPU's.EDIT: Can you put a voltmeter on the pin before sleep and see how it behaves after going to sleep?

author: Miti
author_rank: Super Contributor
timestamp: July 30, 2025, 03:52:09 pm
content: Quote from: mikeselectricstuff on July 30, 2025, 11:40:10 amTrue, but then why does it happen only when it sleeps for awhile? It works as intended after I insert the batteries.

author: mikeselectricstuff
author_rank: Super Contributor
timestamp: July 30, 2025, 03:53:05 pm
content: Quote from: Miti on July 30, 2025, 03:52:09 pmFloating pin?

author: Miti
author_rank: Super Contributor
timestamp: July 30, 2025, 03:57:38 pm
content: Quote from: jpanhalt on July 30, 2025, 01:18:22 pmI will monitor the voltage an will measure the current to ground and come back.

author: Miti
author_rank: Super Contributor
timestamp: July 31, 2025, 01:44:35 pm
content: Yes, AI seems to be right. The measurement suggests that the WPU on RB0/INT is disabled in sleep. I get about 220uA when active, but it goes to below 30nA as soon as it goes to sleep. The supply voltage is 5V active and about 2.5V in sleep. I’ll check the code again but I don’t think I’m touching the relevant registers.

author: jpanhalt
author_rank: Super Contributor
timestamp: July 31, 2025, 02:00:25 pm
content: What a mystery, and that's the INT pin. I wonder whether IOC are kept high as implied? I doubt it is worth our time to find out.Thanks for figuring it out.

author: mikeselectricstuff
author_rank: Super Contributor
timestamp: July 31, 2025, 02:09:37 pm
content: Can't see any mention of pullups being disabled in sleep - it does seem the LCD controller can controll the pullups, so if this is enabled, maybe that's doing something ?there is a "LCD enabled in sleep" bit in LCDCON which defaults to on, but I'd assume this would not have any affect if the LCDC is off.or maybe just the LCDSE bits regardless of LCD ON state?

author: Miti
author_rank: Super Contributor
timestamp: July 31, 2025, 02:47:07 pm
content: LCD is configured to be inactive in sleep. RB0 is configured as I/O anyway since it’s connected to the power button so it shouldn’t matter.

author: jpanhalt
author_rank: Super Contributor
timestamp: July 31, 2025, 02:58:06 pm
content: I found it, 16.5 Power-Down Mode (Sleep):QuoteThat could have been more obvious.

author: mikeselectricstuff
author_rank: Super Contributor
timestamp: July 31, 2025, 03:51:04 pm
content: Quote from: jpanhalt on July 31, 2025, 02:58:06 pmExcept that says nothing about pullup behaviour in sleep, just that inputs need to not float.it also saysQuoteWhich would imply that they are not disabled.I can't see any logical reason to automatically disable pullups in sleep as the user code could do it manually if it was required.Returning to the original post, I thing something else is going on - lack of pullup would NOT cause it to fail to wake, more likely the opposite - waking prematurely.

author: jpanhalt
author_rank: Super Contributor
timestamp: July 31, 2025, 04:20:23 pm
content: I presume Miti has an external PU on MCLR, but if he doesn't, it could cause a reset.Quote from: MitiWhat's it powered with if the batteries are removed? Or, when it fails to wake are the batteries being removed to cause a POR?EDIT: Or the code waits for a button release

author: Miti
author_rank: Super Contributor
timestamp: July 31, 2025, 05:10:04 pm
content: Quote from: mikeselectricstuff on July 31, 2025, 03:51:04 pmThe voltage on RB0/INT is close to Vcc in sleep. There still is a very weak pull up even though the official pull-ups seem to be disabled. I haven’t seen it turning on by itself.

author: Miti
author_rank: Super Contributor
timestamp: July 31, 2025, 05:20:45 pm
content: Quote from: jpanhalt on July 31, 2025, 04:20:23 pm10K to Vcc and 100nF to GND.Quote from: jpanhalt on July 31, 2025, 04:20:23 pmThe only power source is two AAA batteries with a booster to 5V when active and passing through when in sleep.What I meant was that it works fine after a power cycle, after removing and re-inserting the batteries, and it goes haywire after long sleep.After the button is pressed, the code counts a number of 100mS cycles as long as the button stays pressed, then waits for the button release and another 100mS debounce to go from sleep to full on or from on to sleep.

author: jpanhalt
author_rank: Super Contributor
timestamp: July 31, 2025, 07:49:14 pm
content: At this point, to see whether it is code or chip, bodge a WPU of 10k to 22K (I use 22k for my keyboard reads), and see if the problem exists.Other than a floating pin or reset (related to code), I am stumped. John

author: Miti
author_rank: Super Contributor
timestamp: August 03, 2025, 05:34:17 pm
content: Ok, I've added pull up on RB0/INT and it didn't help. Then I played with all the combination of oscillator selection, internal/external MCLR, power on timer, and what not. It only got worse to the point where it would only wake up half of the time. I then asked Chatgpt again and it suggested adding a NOP(); after SLEEP();And what do ya know, I couldn't make it fail after that. It says it is suggested somewhere, in a Microchip application note.

author: jpanhalt
author_rank: Super Contributor
timestamp: August 03, 2025, 05:57:10 pm
content: Congratulations. Glad that worked, and the mystery of why it only affected long sleep remains. At least it's a solution.Sort of reminiscent of the problem Microchip had with GIE in a few (3) early 16Cxx chips. There is still a problem with the simulator I use and breakpoints not stopping.

author: NorthGuy
author_rank: Super Contributor
timestamp: August 04, 2025, 12:53:40 am
content: Quote from: Miti on July 31, 2025, 01:44:35 pmWhat is that you're measuring?Just connect 500k or 1M external pull down and measure the voltage while it is sleeping. You'll immediately know if the pull-up is there or not. It will be more reliable than all the AI in the world.

author: Miti
author_rank: Super Contributor
timestamp: August 04, 2025, 12:03:04 pm
content: Quote from: NorthGuy on August 04, 2025, 12:53:40 amI measure the current from the pin to the GND. It is basically Vcc > Pull_up resistor > Meter series to GND. I think it is very reliable.

author: Miti
author_rank: Super Contributor
timestamp: August 04, 2025, 12:16:30 pm
content: Quote from: jpanhalt on August 03, 2025, 05:57:10 pmI think I understand that too now. I use TPS61222 as a voltage booster and it is disabled when it goes to sleep. That IC has a pass through diode so the output voltage is input voltage minus the forward voltage drop in a Shottky diode, about 300mV. In sleep the current is so low, that the capacitors in the booster take few minutes to decay from 5V to the OFF voltage of the booster. My batteries were a bit low so I think that after a long sleep the voltage decayed close to the 2V minimum limit of the PIC. When I press the power button, the first thing is to start the booster, but the inrush current further drops the voltage on the batteries and that killed the PIC. Playing short term was ok because the caps supplied the start-up voltage.Why it got worse after I added the external pulls up? Because the power button press discharged the caps faster, before there was no pull-ups in sleep.

author: Kean
author_rank: Unknown
timestamp: August 06, 2025, 04:24:00 pm
content: Quote from: Miti on August 04, 2025, 12:16:30 pmMaybe you could add a small P-Ch FET with gate to the button, which enables the boost IC when the button is pressed.

author: Miti
author_rank: Super Contributor
timestamp: August 08, 2025, 01:56:30 am
content: Quote from: Kean on August 06, 2025, 04:24:00 pmThat is a good idea but I don't think that's my only issue. I get some random hiccups even with brand new batteries. The more I play with this PIC16F917, the more I think it has some issues coming out of sleep, at least at lower voltages. I have another project with PIC16F946 + LCD, but that is supplied from a Li-Po battery, LDO to 3.3V, no issues whatsoever.The current project has an interesting story behind it. In 2019, before Covid, we used to travel more, I bought a luggage scale. When I tested its accuracy, I realized it is crap, so I started exploring the possibility to find its calibration menu, and I think I found it. However, I did not have a reference weight, so I removed and re-installed the batteries, before it completed the calibration. It was all good, nothing visible happened, but I didn't stop there.The second time I entered what I thought was the calibration menu, it died. I don't know for sure if I bricked it or it died of an unfortunate... coincidence, but I contacted the seller and they send me a replacement.Now I had an idea, I couldn't just throw the brick, what if I make a board for it? And that's what this is, a luggage scale that I have full control, I can calibrate, add functions, etc.I made the board and started the software in 2019, I found it recently abandoned in a box and I had to finalize it. Schematic and few pictures below.