AVR capacitive issue? - Page 1
Forum section: electronics / beginners

author: juma98
author_rank: Contributor
timestamp: May 27, 2023, 09:54:14 am
content: Hello everyone,I'm working on a custom board with an atmega32u4 on it, that controls and reads data from an ADC. The ADC is used in one-shot mode, which is triggered by using a dedicated pin. I use a timer on the MCU to create the periodic start signal. If the interval is greater than 1500 ms everything works fine.If I reduce it below that though, it doesn't. Probing the pin with an oscilloscope makes it works again. I've tried pushing the pin with a plastic spudger, but that doesn't affect it. So it's not a dodgy solder joint. It also works if I touch the pin with my tweezers while touching the "GND" rail with my other hand. So it seems like it starts working if I capacitively couple the pin to GND.Has anyone of you experienced a similar issue before? Soldering on a capacitor, that basically acts like a low pass, doesn't feel like a smart move if I want crisp edges. Any advice?

author: brucehoult
author_rank: Super Contributor
timestamp: May 27, 2023, 10:01:05 am
content: Which pin, the trigger or the analogue in?

author: Manul
author_rank: Super Contributor
timestamp: May 27, 2023, 10:36:04 am
content: It must be incorrectly configured output. What you likely need is a push - pull output. So whenever it's high or low it should remain low impedance. Your symtoms clearly show that the output becomes floating.So it could be that your output pin is either statically misconfigured, or something changes it's configuration dynamically. Maybe after each trigger pulse is done it goes into floating (input) mode.Another possibility is a damaged output stage (but unlikely).

author: juma98
author_rank: Contributor
timestamp: May 27, 2023, 11:52:18 am
content: Quote from: brucehoult on May 27, 2023, 10:01:05 amThe digital output which I toggle to start conversions.Quote from: Manul on May 27, 2023, 10:36:04 amI've checked my code and the only time I touch the DDR register, I configure it as an output. The only supported output mode is push-pull.

author: Manul
author_rank: Super Contributor
timestamp: May 27, 2023, 12:07:38 pm
content: Quote from: juma98 on May 27, 2023, 11:52:18 amSo how does it look on a scope? Do you have both edges clean and sharp? It should rise and fall in the order of 10's of nanosecods. Does it have anything funny going on between the two trigger pulses?Try to repeat scoping with 1. 10k pullup 2. 10k pulldown added.

author: juma98
author_rank: Contributor
timestamp: May 27, 2023, 12:23:17 pm
content: Quote from: Manul on May 27, 2023, 12:07:38 pmThe signal looks as expected, fast rising edge, no ringing and also no glitches in between. A weak 470k pull down resistor also fixes it. If it is floating, why is it only showing an effect for the "faster" signals?

author: juma98
author_rank: Contributor
timestamp: May 27, 2023, 12:26:54 pm
content: I'll dumb the program down as far as possible to make sure it's not my software that's causing it.

author: Manul
author_rank: Super Contributor
timestamp: May 27, 2023, 12:34:06 pm
content: Quote from: juma98 on May 27, 2023, 12:23:17 pmIs falling edge aproximatelly same as rising edge?Does anything change on a scope picture if you add 10k pullup or 10k pulldown? Or stays exactly same? I'm asking not about your device start working or stop working, but the signal view on a scope.

author: brucehoult
author_rank: Super Contributor
timestamp: May 27, 2023, 12:38:22 pm
content: Quote from: juma98 on May 27, 2023, 12:23:17 pm1500 ms is not exactly fast! One pulse in 1.5 seconds...

author: Manul
author_rank: Super Contributor
timestamp: May 27, 2023, 12:43:02 pm
content: Quote from: juma98 on May 27, 2023, 12:23:17 pmIt may mean that the signal slowly drifts because of random parasitic leakages. If it does not have enough time to drift, it still stays at correct logic level and does not cause problem. I've seen such things, so this is what I'm suggesting. I might be wrong though.

author: juma98
author_rank: Contributor
timestamp: May 27, 2023, 12:47:18 pm
content: Quote from: brucehoult on May 27, 2023, 12:38:22 pmI know, I mean faster compared to the 1.5s, because that's where it starts to become a problem.

author: juma98
author_rank: Contributor
timestamp: May 27, 2023, 01:00:59 pm
content: Quote from: Manul on May 27, 2023, 12:34:06 pmI've measured it again and the falling edge is almost 400 times slower than the rising edge. (rising ~1.5us) The 10k pull-down drops the amplitude from 5V to around 1.5V.I've also configured another pin to toggle, it has a rise and fall time of ~100ns with the pull-down not affecting anything. So either the output stage is damaged or there's something funky going on with the start input of the ADC.

author: Manul
author_rank: Super Contributor
timestamp: May 27, 2023, 01:10:22 pm
content: Quote from: juma98 on May 27, 2023, 01:00:59 pmThat's a lesson learned for you - always check both edges in detail.If signal levels are good without pulldown, but with 10k it drops so drastically, then something is really wrong with the output. 10k resistor is not a big load.I would try to set that output high and low through simple static write to PORT and check how it reacts to pulldown and pullup. Output should drive 10k resistor easily without significant change to output level. If no - it must be damaged then.

author: Manul
author_rank: Super Contributor
timestamp: May 27, 2023, 01:18:46 pm
content: I think I know exactly what is the problem. On AVR if you don't set the port pin as output, writing to that pin instead activates internal pullup resistor.That will explain everything. Also a divider of 10k pulldown together with internal pullup will likely give around 1.5V level. So.

author: juma98
author_rank: Contributor
timestamp: May 27, 2023, 02:47:00 pm
content: Quote from: Manul on May 27, 2023, 01:18:46 pmYeah, my dumbed-down version of the program behaves as expected, "driving" the 10k load with no problem. Thanks a lot for your help. Now the debugging fun begins.

author: juma98
author_rank: Contributor
timestamp: May 27, 2023, 05:11:37 pm
content: I found it.I initially set the pin as an output, but in literally the next line I turned it back into an input because I forgot the ~ in DDRB &= ~(ADC_DRDY);Thanks again for the help guys.

author: Manul
author_rank: Super Contributor
timestamp: May 27, 2023, 05:56:53 pm
content: Quote from: juma98 on May 27, 2023, 05:11:37 pmYeah, when pin is configured as input, writing "1" enables internal pullup, writing "0" disables it. So it has some capability to actually "drive" something. Except that it drives only high and very weak (through internal pullup). And it can't drive low at all, just floats and drifts. By mere concidence, it worked for you at very slow speeds. It's funny actually.Some memories came back to me. I used that to implement capacitive touch sensing on AVR back in old days. I was setting pin to output, drive it low, then set it to input, enabled internal pullup and polled the state of the register to see how many MCU cycles it takes to rise. Worked really well.