Voltage overshoot on digital pins seen on Mega2560

I have noticed 1V overshoot and 1V undershoot on digital pins on a MEGA2560. The O-scope (Tek TDS3012 100MHz) verifies that the 5V is solid (no glitches or changes at the time the digital outputs go to 6V on a high transition and -1V on a low transition. The recovery time to 5V or GND, 0V on these outputs is on the order of 100us. This is seen with nothing connected to the MEGA except USB and the O-scope. The digital pins exercised are 42, 43, 44.

I am concerned that these voltage excursions will generate mischief with the peripherals they drive that specify minimum undershoot on their input pins, usually -.3V max.

The code used is:

// Arduino SPI PINS FOR ADC (The streaming data transfer pins are controlled by PORT commands)
int ADC_SDIN  = 44;    // MISO ADC Bit Bang SPI   
int ADC_SCLK  = 43;    // sck  ADC Bit Bang SPI  
int ADC_CSB   = 42;    // ss   ADC Bit Bang SPI 
int x;
int OSC_ENB   = 22;    // Enable the 12MHz oscillator
unsigned long NumBytes = 120000;
unsigned long k;
byte i = 0; byte j = 0;

// WM8737L REGISTERS FOR STEREO OPERATION  // Next generation will be to pass variables based on a desired feature menu (sot switches.)
unsigned int ADC_control[] = //    reg      reg 
                             //  address   value
                             //    7bit     9bit   // page 30; 3-wire serial control
   { 0x0C3,   //  0 Left_PGA     0000000 011000011 / 0 = update LR simutaneous / 11000011 = 0dB volume /
     0x2C3,   //  1 Right_PGA    0000001 011000011 / 0 = update LR simutaneous / 11000011 = 0dB volume / 
     0x45F,   //  2 Audio_path_L 0000010 001011111 / 00 = Linput1 / 10 = 28dB mic boost / 1 = mic enabled / 1 = mic zero cross / 1 = PGA zero cross / 11 = zero time out 2048/fs
     0x65F,   //  3 Audio_path_R 0000011 001011111 / 00 = Rinput1 / 10 = 28dB mic boost / 1 = mic enabled / 1 = mic zero cross / 1 = PGA zero cross / 11 = zero time out 2048/fs
     0x800,   //  4 3D_Enhance   0000100 000000000 / bit 0 = 0 => disable 3D enhance
     0xA04,   //  5 ADC_control  0000101 000000100 / 00 = stereo / 00 = no inversion  / 0 = present offset maintained  / 0 / 1 = low power ADC   / 0 = not mono mix L=L R=R / 0 = enable HP filter  
     0xE01,   //  6 Audio_Format 0000111 000000001 / 0 / 0 = ADC-DAT pin 9 active / 0 = Slave / 0 / 0 = LR normal polarity / 00 = 16 bits / 01 = left justified (LSB immediately after LRCLK transition)
     0x1039,  //  7 Clocking     0001000 000111001 / 0 / 0 = auto detect off / 0 = no divide by 2 /  11100 = divide MCLK by 500 / 1 = USB mode  // 24kHz sampling = 41.7uS periods
     0x1203,  //  8 Mic_Preamp   0001001 000000011 / 00000 / 0 = no bypass R / 0 = no bypass L / 11 = both channel have 100% bias
     0x1403,  //  9 Misc_bias    0001010 000000011 / 00000 / 00 = 75k VMID / 1 1 = enabled DC bias to both inputs 
     0x161D,  // 10 Noise_gate   0001011 000011101 / 0000  / 111 = -30dB noise level that PGA is prevented from ramping up / 0 / 1 = noise gate enabled THIS is ALC only
     0x1800,  // 11 ALC1         0001100 000000000 / MSB = 00 = ALC off
     0x1A00,  // 12 ALC2         0001101 000000000 / ALC off
     0x1C00,  // 13 ALC3         0001110 000000000 / ALC off
     0x1FFF   // 14 Reset        0001111 111111111 / default = ?, all zeros will reset all settings to their defaults, so load all ones.
   };
unsigned int Power_Up   = 0xDFD ;   //  0000110 111111101 / power up VMID = 75K, VREF, AI, PGAL, PGAR, ADCL, ADCR / 01 = mic bias = 0.75 x AVdd = 2.5V for Vdd = 3.3V
unsigned int Power_Down = 0xC00;    //  0000110 000000000 / power all components off


void setup()  
  {   
   Serial.begin(9600);  Serial.println ("Hello World");
   pinMode(ADC_SDIN, OUTPUT);  // ADC BIT BANG SPI pin modes
   pinMode(ADC_SCLK, OUTPUT);
   pinMode(ADC_CSB , OUTPUT);
   pinMode(OSC_ENB , OUTPUT);
   DDRA = (DDRA | B00001101);   // DDRx = Define Direction Register Contol
   DDRC = (DDRC | B11111110);   // Asigning a 1 to a bit declears that this pin is an output
   PORTA |= B00000100;          // Set pin 24 OSC_LE High // causes Q to remain high
   PORTC = B00001000;           // SET CEA HIGH
   digitalWrite(OSC_ENB, LOW);  // Start with the 12MHz oscillator off
   delay (2000);                // During compile, ADC_SCLK pin goes high for a secocnd with a low pulse in the middle. There is no decernable reason why. Port 44 is assigned 
   digitalWrite(ADC_SCLK, LOW);   delayMicroseconds(100);  // as a PWM by Arduino and has the option as ATMEL OSC. Possibley it takes time to clear these assignments?
   digitalWrite(ADC_CSB, HIGH);   
  }
  

void loop() 
 { 
 
   //  ADC power up
    for (i = 0; i < 16; i++)
	{	
             digitalWrite(ADC_SCLK, LOW);                 // toggle clock low
             if ((Power_Up & 0x8000) == 0x8000)	          // check if MSB is high 
                   {
                    digitalWrite(ADC_SDIN, HIGH);         // if yes, set to hi
                    //Serial.print ("1 ");
                   } 
             else
                   {
                    digitalWrite(ADC_SDIN, LOW);         // if not, set to low
                    //Serial.print ("0 ");
                   }  
             Power_Up = (Power_Up << 1);                  // shift 1 place for next bit 
             digitalWrite(ADC_SCLK, HIGH);                // toggle clock high to capture current bit 
         }
            digitalWrite(ADC_SDIN, LOW); 
            digitalWrite(ADC_CSB,  LOW);
            digitalWrite(ADC_SCLK, LOW);          // Latch register update
            digitalWrite(ADC_CSB,  HIGH);
            delayMicroseconds(120); 
            //Serial.println ();
   while (1);
}

Moderator edit:
</mark> <mark>[code]</mark> <mark>

</mark> <mark>[/code]</mark> <mark>
tags added.

Are you having trouble uploading your sketch to your board?

I have noticed 1V overshoot and 1V undershoot on digital pins on a MEGA2560.

I suspect it's just an artifact of your scope/scope probe. Have you properly performed any probe compensation adjustment. Sans some external circuitry wired to an output pin, there is just no mechanism to explain a real +1 and -1 vdc 'overshoot' for a AVR chip.
At least that is my opinion, others may disagree.

Yes, it is my new scope probe's compensation. I thought all was well, however it took this ADC_SDIN particular lower duty cycle waveforms to really amplify the overshoot effect. Thanks Retrolefty for the quick reply.

The other comment form Coding Badly was " Are you having trouble uploading your sketch to your board?" Well, this is a stripped down version of the program to illustrate my most distorted waveforms, and the code loads to the board, but recently uploading a second time gets into a "avrdude: stk500v2_getsync(): timeout" error. This error state is only fixed with a USB power cycle*, but only for one upload. Is there an obvious reason for this? I will try a reboot of my MAC. (OS 10.7.5).

  • I had a history of the USB port getting lost, just disappears from the Tools -> Serial Port pulldown. That was cured with a powered USB extender strip that I allowed power down of the USB port to the Arduino before disconnecting it and power up after connecting. Macs don't seem to have a convenient desktop USB disconnect function like Windows.

The normal high impedance probes (1M or 10M at x10) that come with
oscilloscopes aren't great for logic signals (though they work, even when
properly compensated they show artifacts (overshoot and ringing) on the
edges due to the earth clip loop having significant inductance.

The best probe for a logic signal is a low impedance probe, with very short wires
to connect to the circuit (to reduce the inductance). These show a much more
accurate waveform. However they cannot be used in general circuits due to the
low impedance.

There are also very expensive 'active probes' available that have built in fet based amps that can work well in analyzing digital signals.

Why did you define your MISO pin as an output ?

thanks for scope probe tips. I could use a logic analyzer - some day.

As for the timeout issue, it seems to be gone after reboot and re-establishing the serial port.

Regarding the MISO as output, this Wolfson audio ADC needs to have many registers loaded to define its personality and this is one way communication on what is called a either I2C or SPI depending on mode serial port. It is not standard SPI, so I bit bang the register address/data. There are other dedicated pins that are used for controlling the serial ADC output data.

OK to close post.