SAMD21 Strange I/O Pin Behaviour

I'm not sure if this is in the right forum section, so apologies if not.

Advanced warning I must be doing something very wrong for this to happen, so be prepared to despair.

We're building a small PCB with a few inputs and outputs, which was initially controlled by a 328p. The need then arised to do some more intense computation on the device, so it was decided to upgrade to the ATSAMD21G18A.

I am programming the chip by taking a hex file compiled by arduino, and using Atmel Studio to flash it to the chip using an atmel ICE and SWD. I have used a number of custom 'no bootloader' boards added to boards.txt, and all are exhibiting the same strange behavior described below.

To try to get programming working first, I am using the blink script, with the output of a pin going to the base of a 2N2222 transistor that is connecting power to ground via an LED and resistor. The chip itself is powered to 3.3V at all the appropriate pins with an adjustable power supply, with the recommended decoupling capacitors in place.

The strange behaviour is as follows: When pinmode is set to OUTPUT, nothing happens other than a very very faint glow of the LED. digitalwrite and analogwrite have no effect on the LED. Initially I just assumed the chip was not programming properly, and spent many hours troubleshooting the programming as such, however at one point I decided to change pinmode to INPUT instead, and was shocked to find the LED started blinking. This was with digitalwrite.

INPUT and INPUT_PULLUP have seemingly the same effect on an analog pin, with the LED blinking but only at a medium level of brightness. Considering the Transistor is sensitive enough to shine moderately brightly with just a finger on the wire, this is presumably due to lowered impedence in time with the digitalwrite. When moving to a digital pin and pinmode = INPUT (I haven't yet tried pullup), the same behavior is shown, however the LED shines brighter than on the analog pin. Metering the output from the pin, a voltage of 0.69V is measured each 'blink'.

I have tried using a few different methods of pin manipulation, but am yet to find something that works to get a correctly working output from the chip pins. If anyone could shine any light on the situation, or mention anything obvious that I'm ignoring that would be much appreciated!

Thanks very much.

The 2N2222 is a BJT NPN transistor, as such it's a current driven device.

Are you using a series resistor between the SAMD21 and the transistor's base?

The topic is discussed on the Arduino forum here: A couple of questions on the 2N2222 transistor - General Electronics - Arduino Forum.

Hi Martin, yes there's a resistor in there to stop the pin frying, sorry for missing that out!

Hi Andy,

Could it be that the SAMD21 is unable to source the current required by the transistor?

By default the SAMD21's pins can only source 2mA, the Atmega328P by contrast can supply up to around 20mA (40mA max).

It's possible however to increase the SAMD21's output driver strength to 7mA, by setting the appropriate DRVSTR bit in the pin configuration register (PINCFG).

Sadly this doesn't seem to be the issue; simply touching the wire going to the transistor base through a resistor is enough to light up the LED fully so there isn't anything coming through at all (I did try increasing the 'pin strength', but it sadly had no effect).

Thanks for the suggestion though!

TheAndyGraham:
simply touching the wire going to the transistor base through a resistor is enough to light up the LED fully

I'm a little surprised that that would be the case with a bipolar transistor.

Anyway, what readings do you get on the meter from the output pin with the transistor etc. disconnected?

TheAndyGraham:
however at one point I decided to change pinmode to INPUT instead, and was shocked to find the LED started blinking. This was with digitalwrite.
INPUT and INPUT_PULLUP have seemingly the same effect on an analog pin, with the LED blinking but only at a medium level of brightness.

In case you are not aware, if a pin is set to INPUT, then a digital write HIGH will enable the internal pull-up resistor, and a digital write LOW will disable it. Essentially the same functionality as available with pinMode() INPUT_PULLUP and INPUT.

arduarn:
I'm a little surprised that that would be the case with a bipolar transistor.

Anyway, what readings do you get on the meter from the output pin with the transistor etc. disconnected?

In case you are not aware, if a pin is set to INPUT, then a digital write HIGH will enable the internal pull-up resistor, and a digital write LOW will disable it. Essentially the same functionality as available with pinMode() INPUT_PULLUP and INPUT.

With everything disconnected, the pin voltage fluctuates between 0 and 2.5V at the correct rate

I feel a bit silly for not metering that before.

That said, when connecting up to either the transistor, or just a resistor + LED alone, the voltage sits stationary at 0.03V, and the current stationary at 0.002 mA (The default max current is 1000 times that yes?). This seems to therefore be a basic electronics error and I must have made a rookie mistake with my wiring, but the power is coming directly from a variable power supply at 3.3V... any suggestions on what it is?!

Post a schematic, including component values. A photo of a pen and paper drawing is fine.

Here you go!

Edit: VDDIN is also connected to +3.3V, I accidentally missed this on that schematic!

SOLVED: 10k resistor from chip to transistor was too small. Replacing it with a 300k resistor solved the issue.

I am confused though, as the supply voltage is 3.3V, and the maximum current is 2mA, surely that would make the resistance requirement just 1650 Ohms?

TheAndyGraham:
SOLVED: 10k resistor from chip to transistor was too small. Replacing it with a 300k resistor solved the issue.

I am confused though, as the supply voltage is 3.3V, and the maximum current is 2mA, surely that would make the resistance requirement just 1650 Ohms?

Hmm, interesting. You have verified the original resistor's value with the meter?

Thanks for the schematic, although it is still unclear to me what could be causing the symptoms as you describe them.
That said, I do notice that you have connected a 10k resistor to VDDANA instead of the recommended inductor (for filtering purposes); possibly not related to the issue, but cannot be good. If you don't have a suitable inductor to hand, then I would simply remove the resistor; you are also missing a capacitor as well.

The unconnected HIGH pin voltage of 2.5v seems a tad low if you are supplying the full 3.3v to the chip; I would have expected at least 2.64v (0.8*V DD) according to the datasheet.

PS: It's not solved until you understand why... :wink:

arduarn:
Hmm, interesting. You have verified the original resistor's value with the meter?

Yep have verified this.

arduarn:
That said, I do notice that you have connected a 10k resistor to VDDANA instead of the recommended inductor (for filtering purposes); possibly not related to the issue, but cannot be good. If you don't have a suitable inductor to hand, then I would simply remove the resistor; you are also missing a capacitor as well.

The capacitor I don't think would have much of any effect like this with a simple blink sketch? The resistor on the other hand could be a huge issue. With my wire placement it may be acting like a weird voltage divider causing the issue.

Sadly my soldering station has just bitten the dust, but I'll try removing the resistor once it's replaced/repaired and let you know!

arduarn:
PS: It's not solved until you understand why... :wink:

Yeah I guess I got a bit too excited when blink was actually working... wouldn't be an arduino user without that though ¯_(ツ)_/¯

TheAndyGraham:
I'll try removing the resistor once it's replaced/repaired and let you know!

This has fixed the issue. Voltage divider created with the odd resistor.

Thanks very much for helping fix this!

Interesting effect. Thanks for the follow up.