Strange behaviors with microcontroller digital inputs - Page 1
Forum section: electronics / beginners

author: tyguy2
author_rank: Unknown
timestamp: September 22, 2019, 04:10:38 am
content: Hello all,I've embedded a SAMD21G (Basis for the Arduino Zero) into a PCB I've been designing. I've been using pins PA19 and PA18 (Arduino pins 12 and 10 respectively) to act as inputs for 2 different signals entering the device. The first is connected to a reed switch with an external 4.7k ohm pull up resistor with the reed switch connected to ground. The second is connected to a LDO's output to detect if a device external to the PCB has been powered on (schematics attached). This is attached to a 4.7k ohm pull down resistor. The issue I'm having is that after a few hours of operation, the micro begins to not accurately detect if these sources are high or low. Checking with a multimeter, I've noticed the voltages at the inputs are 1.53-ish volts for the reed switch and 1.23-ish volts for the LDO, rather than the standard 0v or 3.3v. Does anyone know what could be causing this and how I'd fix it?Thanks

author: Kasper
author_rank: Frequent Contributor
timestamp: September 22, 2019, 05:31:28 am
content: Is your 3.3V source still at 3.3V when the problem occurs?

author: tyguy2
author_rank: Unknown
timestamp: September 22, 2019, 05:40:37 am
content: Yes, it remains at 3.3v

author: EEEnthusiast
author_rank: Frequent Contributor
timestamp: September 22, 2019, 06:10:38 am
content: The LDO output going to 1.23 is surprising and it looks like the reference voltage of the LDO. Is there something which gets heated on the board? Also check the VIO supply of the microcontroller. Check if it is floating or some soldering issue. This is mostly coming from a power issue.

author: Twoflower
author_rank: Frequent Contributor
timestamp: September 22, 2019, 09:03:19 am
content: Can you read back the IO-config of the controller of the pins in question? Just in case you're actually chasing a SW issue that by accident re-configures your input pin. But from the datasheet the pull-down would be too weak (about 40k) for the voltage you see.

author: Psi
author_rank: Super Contributor
timestamp: September 22, 2019, 10:38:29 am
content: Quote from: tyguy2 on September 22, 2019, 04:10:38 amWild stab in the dark, check if this is happening at exactly the same time after power on (down to the second or near abouts).If so i would suspect something related to the tick counter/timer overflowing and causing weirdness to occur.Especially if you are using the tick count for things and comparing with previous tick counts (or some arduino library is)etc.. If the previous tick count is 65520 but suddenly the current tick count is now zero some code may never be called.(Unless you have specifically added code to handle this situation )Yes i know this doesn't explain the 1.53V but checking if the bug is happening at exactly the same time is still useful to know.

author: MosherIV
author_rank: Super Contributor
timestamp: September 22, 2019, 10:41:06 am
content: I not even sure how the detect circuit works to begin with.The micro gpio is only able to detect voltage.The LDO is a voltage regulator.So, the circuit should only detect if the LDO is on or not.

author: Nominal Animal
author_rank: Super Contributor
timestamp: September 22, 2019, 12:50:12 pm
content: Are you absolutely sure the two resistors are 4.7kΩ and not say 470Ω? Measure them, to be sure.

author: Kasper
author_rank: Frequent Contributor
timestamp: September 23, 2019, 05:52:46 am
content: When your DMM says 1.5V, it could mean it is quickly switching between 0 and 3V. If you have access to an oscilloscope that could be helpful to see if it is actually 1.5V or something else is happening. For example your MCU could be setting pin to output low and then changing it to input and repeating. If you dont have a scope, test it with the simpliest code you can just to be more confident it is doing what you expect.

author: mikerj
author_rank: Super Contributor
timestamp: September 23, 2019, 12:01:54 pm
content: Quote from: Kasper on September 23, 2019, 05:52:46 amQuite possibly the LDO oscillating due to too too low a capacitance or too high an ESR on the output cap. This is the opposite of most conventional LDO's and caught me out on a different part when the MLCC capacitance dropped below the minimum required due to voltage derating.

author: Kasper
author_rank: Frequent Contributor
timestamp: September 23, 2019, 02:41:47 pm
content: Quote from: mikerj on September 23, 2019, 12:01:54 pmThat does seem like a possibility but the op says the supply is 3.3V when the problem is occuring so assuming that is true, I think it is something else.

author: Nominal Animal
author_rank: Super Contributor
timestamp: September 23, 2019, 02:49:40 pm
content: The reason I suggested that maybe the resistors were much smaller than believed, is that having higher current (7 mA if 470 Ω, 70 mA if 47 Ω) should work fine for a while, but later on, generate "odd" effects due to point heat on the microcontroller chip, especially if internal pull-ups/downs were also enabled.

author: tyguy2
author_rank: Unknown
timestamp: September 23, 2019, 06:27:04 pm
content: Quote from: Kasper on September 23, 2019, 05:52:46 amApologies for the late reply! I checked with an true RMS multimeter in AC mode, got 3.3v, so something internal to the micro is causing this. It happens on both pins, so I can assume it's not something external to the circuitry, so I'm move inclined to believe there's an error in my code. That raises an entire other bag of worms though. I'm just using Arduino to program this, and I'm just calling digitalRead on pins that have been set to pinMode(INPUT). Any ideas? I am utilizing the DAC built into the chip, but I feel like that wouldn't effect the digital I/O?

author: Kasper
author_rank: Frequent Contributor
timestamp: September 23, 2019, 07:55:23 pm
content: Good idea using AC measurement to check this. So now it seems pretty clear something is pulling those lines down repetitively.If you want to be even more sure the MCU is the problem, take the MCU out of the circuit, replace it with resistors similar to what you expect the MCU to have internally and see what happens.To test the MCU:Make new code for troubleshooting.Do nothing except set your inputs as needed and if you can, use serial monitor to increment a variable every second or so.My guess is something happens after a while that causes your MCU to start rebooting constantly and the pin states change during the reboot. Displaying a count through serial monitor will tell you if it has rebooted or not. Note that your counter variable will eventually overflow, possibly making it look like a reboot but if it only happens at a power of 2 then that should be obvious it was just an overflow.

author: mikerj
author_rank: Super Contributor
timestamp: September 23, 2019, 07:58:37 pm
content: Quote from: Kasper on September 23, 2019, 02:41:47 pmThe schematic shows a direct connection between the micro's GPIO pin and the output of the LDO, with no series resistors. If the voltage on the micro pin is 1.23v but the voltage at the LDO is 3.3, then there must be a bad connection between them.

author: tyguy2
author_rank: Unknown
timestamp: September 23, 2019, 11:38:44 pm
content: Quote from: Kasper on September 23, 2019, 07:55:23 pmMy code currently has variables that exist only in RAM, and I'm guessing constant resets would wipe those from memory and reset them to their initial values, but I'm observing nothing like that.Quote from: mikerj on September 23, 2019, 07:58:37 pmIf that were true, then we wouldn't see the same effect on the reed switch. Additionally, as I said in the previous post, I'm getting 3.3v AC RMS on the inputs, which means something is definitely wrong with the micro, not the voltages going into the micro.

author: mikerj
author_rank: Super Contributor
timestamp: September 24, 2019, 01:11:21 pm
content: Quote from: tyguy2 on September 23, 2019, 11:38:44 pmSorry, I must be missing something here. Just to confirm, you are measuring 3.3v AC RMS on the micro GPIO pins, including the one directly connected to the output of an LDO where you are getting 3.3v DC? Are you using the same ground reference when measuring the micro GPIO pins and the LDO output?

author: Nominal Animal
author_rank: Super Contributor
timestamp: September 24, 2019, 02:39:41 pm
content: I'd wager a beer that the problem is that internal pull-ups or pull-downs are enabled for those pins, and the resistors resistance is smaller than intended.