Microchip PIC WPUx Setting [SOLVED] - Page 1
Forum section: electronics / general

author: jpanhalt
author_rank: Super Contributor
timestamp: January 22, 2025, 12:11:30 pm
content: I have not usually worried too much about start-up sequencing specifically with respect to the 16F series. WPU's on inputs can be enabled for all ports or set by individual port pins (WPUx registers in Bank4 usually) in the configuration bits. I usually opt for the latter. However, the default for WPUx registers in 0xFF (i.e., enabled). All ports are set to input until changed to output by TRIS (1 = input, 0 = output). Thus, at power up and all resets the pins are high (VCC).The input device I am using is a Mitutoyo linear encoder. Its active element runs at 1.5V and the REQ signal is open drain. That is, the 1.5V output from the sensor is pulled low by the MCU OD output pin. (Main power is VCC or 5V in this case.) Thus, for just a moment during boot, the REQ pin is exposed to a weak pull-up of 5V. Microchip in mum on exactly what the WPU resistance is, but it presumably is on the order of 50k, so available current is limited to 100 uA. I usually start the oscillator first, then go through the rest of the register settings.Is that momentary exposure to 5V from the MCU on a 1.5V output pin (Mitutoyo does not give a voltage tolerance for it) for a few milliseconds a concern? Can either WPU or TRIS be set prior to getting the oscillator working?NB: I have been working with this device for about 18 months and have not killed an encoder yet, but last week, I had a silly error in code that made things stall for a few seconds. No damage has been detected. The question is mostly theoretical, it seems, but I would like others' input as there might be a situation when it matters. Replacement encoders are quite expensive.

author: MarkF
author_rank: Super Contributor
timestamp: January 22, 2025, 02:17:01 pm
content: You don't say which PIC you are using.However, I don't believe weak pull-ups are enabled at startup.I see that the WPU bits are high (turned on) at start for each port.But the global WPUEN bit of the OPTION_REG register is high (all weak pull-ups disabled).

author: jpanhalt
author_rank: Super Contributor
timestamp: January 22, 2025, 03:40:16 pm
content: I am using the 16F1783 and 16F1829. I'm a victim of just copying and pasting from other code and not reviewing the datasheet each time. I am not sure it makes a difference given the current, but it is an easy change. It's not quite my dumbest mistake of the year, though. That was last week, but I am too embarrassed to describe it in detail.I wonder, though, whether that short exposure makes a difference?

author: MarkF
author_rank: Super Contributor
timestamp: January 22, 2025, 04:11:50 pm
content: What exposure?The PIC pins basic power-up in a high impedance state.Unless you are turning on pull-ups, all the pins start-up and stay as inputs.

author: jpanhalt
author_rank: Super Contributor
timestamp: January 22, 2025, 05:42:24 pm
content: The encoder supply from the PIC board provides 5V and 1.5V. Both start immediately. Encoder outputs for serial data and clock are OC (TTL?) with weak pull-ups at the reader input to ~5V,* but the request line is 1.5V, which is pulled low by the MCU to initiate a read.I had not left pullups disabled in the OPTION_REQ, as usual and as needed for other parts of the code (e.g., keyboard read). That allows the pins to be individually enabled, but the default in the port registers is enabled. That left the MCU REQ pin with pull-up enabled connected to the REQ line of the encoder for the short time it took me to make it an OD output. I could watch it on a scope go from 5V to 1.5V as I stepped through the code. I don't think damage was done yet. The fix is obvious (i.e., do the pull-ups after setting the OD output), and next time, I'll pay a little more attention to what I am copying and pasting.*Mitutoyo gives a suggested circuit for reading that includes a 22k pullup and 220 pF RC filter. It mentions something about not using CMOS, but it's unclear and doesn't seem to make a difference. The factory reader from the 90's had the same input circuit but used an LC filter instead, and it uses an MC74HC14 CMOS inverter before an Intel MCU. I just went with what the datasheet provided and haven't decided whether to use an inverter or non-inverted buffer..