Slow transition on digital pin 5

Hello!

I am using pins 4, 5 and 6 of a arduino pro mini (3.2V 8MHz) to select the channel of a 8 channel multiplexer (74HC4051).

While the transitions from high to low on pins 4 and 6 lasts less than 2 us, it occurs very slowly on pin 5 (more than 400 us). I get the same result with another arduino pro mini.

As you can see in the image I've sent, it seems like there is a capacitive effect only in this pin (5, yellow in the image).

Have anyone any idea of the why of this?

Hey christhian_h

Do you mind Sharing the Code and schematic you are using..??

Hello!

there's nothing special in the conection, but i've sent the schematic. The 3 selected lines are these conections.

The function that sets the pins are below:

void selecionarCanal ( int canal)
{
switch (canal){
case 7:
PORTD |= _BV(PD4);
PORTD |= _BV(PD5);
PORTD |= _BV(PD6);
break;

case 6:
PORTD &= ~_BV(PD4);
PORTD |= _BV(PD5);
PORTD |= _BV(PD6);
break;

case 5:
PORTD |= _BV(PD4);
PORTD &= ~_BV(PD5);
PORTD |= _BV(PD6);
break;

case 4:
PORTD &= ~_BV(PD4);
PORTD &= ~_BV(PD5);
PORTD |= _BV(PD6);
break;

case 3:
PORTD |= _BV(PD4);
PORTD |= _BV(PD5);
PORTD &= ~_BV(PD6);
break;

case 2:
PORTD &= ~_BV(PD4);
PORTD |= _BV(PD5);
PORTD &= ~_BV(PD6);
break;

case 1:
PORTD |= _BV(PD4);
PORTD &= ~_BV(PD5);
PORTD &= ~_BV(PD6);
break;

case 0:
PORTD &= ~_BV(PD4);
PORTD &= ~_BV(PD5);
PORTD &= ~_BV(PD6);
break;
}
}

Thanks for the attention!!

You probably forgot to set the pin as an output.

If you had done what we asked and posted your code (NOT A SNIPPET) we wouldn't need to guess. And use code tags too!

DrAzzy:
You probably forgot to set the pin as an output.

If you had done what we asked and posted your code (NOT A SNIPPET) we wouldn't need to guess. And use code tags too!

Sorry friend, it's my first time looking for help in forums.

Pin 5 is set as an output Initially, but i've noted that (for an unknow reason) I'm setting it like an input after in the code.

So thank you very much!

here is the complete code:

//Receptor 500kHz
/*pinagem 
 *      2 - dados digitais.
 *      3 - 
 *      4 - S0 (pino 10 - seletor de canal do multiplexador)
 *      5 - S1 (pino 11 - seletor de canal do multiplexador)
 *      6 - S2 (pino 12 - seletor de canal do multiplexador)
 *      9 - definição de região atingida canal 1
 *      10 - definição de região atingida canal 1
 * 
 * 
*/

volatile int i=0;
volatile int j=0;
volatile int regiao;
boolean dadosRx[20]={0};
volatile int tempo[20]={0};
float tref = 0;
unsigned int ajusteIndice = 0;
volatile int ataque=0;


void setup()
{
  //determinando o modo de operação dos pinos digitais
  pinMode(2, INPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(9, INPUT);
  pinMode(10, INPUT);
  
  Serial.begin(9600);
  
  cli();//parando interrupções.
  TCCR1A = 0;
  TCCR1B = 0;
  TCNT1  = 0;
  // set compare match register for 1MHz increments
  OCR1A = 1050;// = (16*10^6) / (10"6*8) - 1 (must be <65536)
  TIMSK1 = 0; 

   //set timer2 interrupt at 10kHz
  TCCR2A = 0;// set entire TCCR2A register to 0
  TCCR2B = 0;// same for TCCR2B
  // set compare match register for 10khz increments
  OCR2A = 199;// = (16*10^6) / (10000*8) - 1 (must be <256)
  TIMSK2 = 0;
  
  sei();//permitindo interrupções.
  pinMode(5, INPUT);
  attachInterrupt(0, leituraInicial, RISING);
  selecionarCanal(0);
}

void loop(){
  if(ataque==1){   
    detachInterrupt(0);
    decodManchester();
    mensagem();
    for(int a=0; a<=i; a++){
      Serial.print(tempo[a]);
      Serial.print(" ");
    }
    for(int a=0; a<18; a++){
      tempo[a]=0;
    }
    ataque = 0;
    i=0;
    Serial.println(" ");
    delay(2);
    attachInterrupt(0, leituraInicial, RISING);
  }
}


void leituraInicial()
{
  
  attachInterrupt(0, leitura, FALLING);
  selecionarCanal(j);
  
  cli();//parando interrupções.
  
  TCCR1B |= (1 << WGM12);  // turn on CTC mode 
  TCCR1B |= (1 << CS11);   // prescale 2
  TIMSK1 |= (1 << OCIE1A); // habilita interrupção
  TCNT1  = 0;              //initialize counter value to 0

  
  TCCR2A |= (1 << WGM21);   // turn on CTC mode  
  TCCR2B |= (1 << CS21);    // Set CS21 bit for 8 prescaler  
  TIMSK2 |= (1 << OCIE2A);  // enable timer compare interrupt  
  TCNT2  = 0;               //initialize counter value to 0
  
  sei();
}

void leitura()
{
  tempo[i] = TCNT1/2;
  i++;
}

ISR(TIMER1_COMPA_vect)
{
  cli();//parando interrupções.
  TCCR1A = 0;
  TCCR1B = 0;
  TCNT1  = 0;
  TIMSK1 = 0; 

  j = 0;
    //desabilitando interrupções do timer2
    TCCR2A = 0;
    TCCR2B = 0;
    TCNT2  = 0;
    TIMSK2 = 0;
    selecionarCanal(0);

    
  sei();
  ataque=1;
}

ISR(TIMER2_COMPA_vect)
{
 if(digitalRead(9)){
    regiao = j;

    j = 0;
    //desabilitando interrupções do timer2
    TCCR2A = 0;
    TCCR2B = 0;
    TCNT2  = 0;
    TIMSK2 = 0;
  }
  else if (digitalRead(10)){
    regiao = j + 8;

    j = 0;
    //desabilitando interrupções do timer2
    TCCR2A = 0;
    TCCR2B = 0;
    TCNT2  = 0;
    TIMSK2 = 0;
  }
  j++;
  selecionarCanal(j);
}

void decodManchester()
{
  tref = 12;
    dadosRx[0]=true;
    for(int a=1; a<18; a++){
      if(float(tempo[a]-tempo[a-1])>0.75*tref && float(tempo[a]-tempo[a-1])<1.24*tref){
        dadosRx[a+ajusteIndice] = dadosRx[a-1+ajusteIndice];
      }
      if(float(tempo[a]-tempo[a-1])>1.25*tref && float(tempo[a]-tempo[a-1])<1.79*tref){
        if(dadosRx[a-1+ajusteIndice]==true)dadosRx[a+ajusteIndice] = false;
        else{
          dadosRx[a+ajusteIndice] = false;
          dadosRx[a+1+ajusteIndice] = true;
          ajusteIndice++;
        }
      }
      if(float(tempo[a]-tempo[a-1])>1.8*tref){
        dadosRx[a+ajusteIndice] = !dadosRx[a-1+ajusteIndice];
        dadosRx[a+1+ajusteIndice] = dadosRx[a-1+ajusteIndice];
        ajusteIndice++;
      }      
    }
    ajusteIndice=0;
}

void mensagem()
{ 
  for(int a =0; a<18; a++){
    Serial.print(dadosRx[a]);
    dadosRx[a]=0;
  }
  Serial.print("    Regiao: ");
  Serial.print(regiao);
  Serial.print("    ");
}

void selecionarCanal ( int canal)
{
  switch (canal){
    case 7:
      PORTD |= _BV(PD4);
      PORTD |= _BV(PD5);
      PORTD |= _BV(PD6);
      break;
      
     case 6:
      PORTD &= ~_BV(PD4);
      PORTD |= _BV(PD5);
      PORTD |= _BV(PD6);
      break;

     case 5:
      PORTD |= _BV(PD4);
      PORTD &= ~_BV(PD5);
      PORTD |= _BV(PD6);
      break;

     case 4:
      PORTD &= ~_BV(PD4);
      PORTD &= ~_BV(PD5);
      PORTD |= _BV(PD6);
      break;

     case 3:
      PORTD |= _BV(PD4);
      PORTD |= _BV(PD5);
      PORTD &= ~_BV(PD6);
      break;
      
     case 2:
      PORTD &= ~_BV(PD4);
      PORTD |= _BV(PD5);
      PORTD &= ~_BV(PD6);
      break;

     case 1:
      PORTD |= _BV(PD4);
      PORTD &= ~_BV(PD5);
      PORTD &= ~_BV(PD6);
      break;

     case 0:
      PORTD &= ~_BV(PD4);
      PORTD &= ~_BV(PD5);
      PORTD &= ~_BV(PD6);
      break;
  }
}

Why don't you try pulling down the Pin 5..?

Google about Pull Down Resistors to learn more...

Regards

SDA