Electronics > Microcontrollers
Microchip PIC WPUx Setting [SOLVED]
(1/1)
jpanhalt:
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.
MarkF:
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).
jpanhalt:
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?
MarkF:
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.
jpanhalt:
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..
Navigation
[0] Message Index
Go to full version