Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
11 years, 3 months ago.
Is there a glitch-free way to specify the initial state for DigitalOut?
Is there a glitch-free way to specify the initial state for DigitalOut?
This code sequence makes pulse.
#include "mbed.h" DigitalOut csel(p8); int main() { csel = 1; ... }
Prior to specifying a pin as DigitalOut, the pin is an input with 10K ohms pullup to +2.3V (a logic '1' for 3.3V). When DigitalOut is specified, the default logic state '0' appears at the pin. The logic '0' output lasts until it is set to logic '1' in main().
I need a way to specify the pin as output without making a pulse.
4 Answers
11 years, 3 months ago.
I checked digitalinout, but that will apply a weak pull-down. So if you got a pull-up also you can use that, set it as high, and then as output.
If pull-up is not an option you will get to either manual coding it to do that (not extremely hard to do, you can for example edit the fastIO library, that also by default does wrong behavior for you, but it shouldn't be too hard to edit that), or use this one: http://mbed.org/users/AjK/code/SimpleIOMacros/file/cb1f38aaae0a/IOMacros.h. Aditional advantage that it is also very fast ;). (And of course also has some disadvantages).
11 years, 3 months ago.
Hi Dan, maybe the PortOut class that lets you write to the GPIO can serve you:
https://mbed.org/handbook/PortOut
Greetings
11 years, 3 months ago.
I suppose you're missing the point...
The simple answer is: No, there is no glitch free (!) solution.
See Section 9.2.1 of LPC17xx User manual: • All I/Os default to input with pullup after reset.
The register defining the mode of the pullups/-downs is PINMODE (See section 8.4 of LPC17xx User manual). PINMODE is reset to 0b00 for each pin on hardware reset, which means "Pin has an on-chip pull-up resistor enabled". Thus, for at least the duration between reset and execution of code which sets PINMODE to 0b10 (Pin has neither pull-up nor pull-down resistor enabled), the pullup will be enabled.
Thus, no software in the world will prevent the pin from becoming high on reset.
In your case this is an error by design. The only solution to this would be to use an external driver with the ability to switch off the output completely, so you can turn on the output by enabling this driver. Alternatively you may use negative logic, i.e. an inverter on the pin (resulting in the desired low on reset) and driving the pin inverted (remember to set output to 1 before enabling!).
In case you must use the IO directly, consider using a stronger pulldown to override the weak pullup.
For the pin configuration I found the following note from NXP in a german forum:
The pull-ups are not resistors, but current sources. Their behavior is quite non-linear, as shown in the attached document (which is for LPC2300, but the effect is the same). As you can see, the pull-ups cannot deliver current above 2.3V. Even the load of a multi-meter brings the pin down to 2.1V.
We specify the pull-ups as an effective resistor which would give the same short-circuit current when then pin were grounded. Since the current source delivers typically 50 µA (at least on all chips I've seen so far), the effective resistor would be 3.3V/50µA = 66 kOhm.
Thus, considering the pin can drive 4mA, you can select an appropriate pulldown.
11 years, 3 months ago.
Thank you all for these answers. It is as I suspected. The default state of the pins is input with weak pullup. The default output state is logic '0'. When initializing the pin as output using DigitalOut(), the pin starts at logic '1' as an input with pullup. When the DigitalOut function executes, the pin goes to logic '0' as it becomes an active output with the default logic '0'. After DigitalOut() defines the pin, it can be set to logic '1'. This takes about 40uSec with NXP-LPC1768. To use the library as it is, the glitch-free alternative is to initialize the pin to logic '0', and use a logic inverter chip and a pulldown resistor that overcomes the internal pullup. I will try writing directly to the chip registers without using DigitalOut().
It would be useful to have an optional second arg for DigitalOut() that specifies the initial logic state for the pin.
The initial state of the chip is '1' with a weak pullup. The initial state of DigitalOut() is '0'. As the chip powers up an output pin goes from weak pullup '1' to a firmly driven '0' as DigitalOut enables the pin drive. After that, the pin can be initialized in main(). It seems like DigitalOut() ought allow a spec for the initial logic level before the pin drive is enabled.
posted by 27 Sep 2013