problem with small delay

Hello,

A short summary to the project.
There are two power supplies (input 220VAC output 12VDC) and just one is responsible to supply the device. The arduino read some values like voltage input, current output and voltage output and apply some alarms.
I need to ensure just one power supply is running. There is one electronic circuit to verify the synchronization between power supplies. If the synchronization is checked the power A is turn OFF and power B is turn ON immediately. If the synchronization is not checked I need to apply a delay between turn off and turn on supplies.

I need to apply a small delay between two commands like this:
const int o_CARGA_A = 2; // turn on supply A
const int o_CARGA_B = 3; // turn on supply B
Setup{
pinMode(o_CARGA_A, OUTPUT);
pinMode(o_CARGA_B, OUTPUT);
}
Loop{
if (some conditions){
digitalWrite(o_CARGA_A, LOW);
//here i need to apply 16 micro seconds delay
digitalWrite(o_CARGA_B, HIGH);
}
}
The full code program is attached.
I’ve try to use delay function, but it resulted in a big delay. I used millis function and it doesn’t apply any delay. I used delayMicrosenconds and the result is worst than delay function (2 seconds)
Sorry for my weak English, I’m Brazilian.
Tank you,
Giliardi

giliardi_1.8.ino (21.8 KB)

giliardi81: I used delayMicrosenconds and the result is worst than delay function (2 seconds)

Which line of your program is that on?

...R

Right. delay() is for milliseconds. You want delayMicroseconds().

jaholmes: Right. delay() is for milliseconds. You want delayMicroseconds().

The OP said he already tried that :)

...R

The OP said he already tried that

No, the OP said he tried delayMicrosenconds(). 8)

Robin2: The OP said he already tried that :)

...R

And we're just supposed to guess at its location and argument?

Robin2: The OP said he already tried that :)

...R

Ah. Stopped reading at "I tried to use delay function..."

But a two-second delay from calling delayMicroseconds()? The mystery deepens...

giliardi81: I need a millisecond delay.

And this...

delay(1);

...doesn't work?

It won't be exact, but it should be awfully close.

giliardi81:
between 16 and 25ms

I see. Not “a” as in “one” :slight_smile: My bad. And what are you measuring when you do “delay(16)”? Certainly that should fall between 16 and 25ms. How exactly are you measuring the delay, and what Arduino board are you using?

giliardi81: between 435 and 453

This is the code between those lines (inclusive)

   } else { //não esta sincronizado
      // se a seleção esta em CA e o status de VA esta OK e é primeiro evento
      tempoCorrenteComutacao = millis(); //tempo do processador
      if (SELECAO == "CA" && SVA && !TRIP_B && S_FALHA_ENTRADAS == false) {
        ativaSaida_B(false);
        if ((tempoCorrenteComutacao - tempoAnteriorComutacao) > delay_comutacao) {  //se tempoCorrente - anterior for superior ao tempo de delay
          tempoAnteriorComutacao = tempoCorrenteComutacao;          
          TRIP_B = true;
          TRIP_A = false;
          ativaSaida_A(true);
        }
      }
      if (SELECAO == "CB" && SVB && !TRIP_A && S_FALHA_ENTRADAS == false) {
        ativaSaida_A(false);
        if ((tempoCorrenteComutacao - tempoAnteriorComutacao) > delay_comutacao) {  //se tempoCorrente - anterior for superior ao tempo de delay
          tempoAnteriorComutacao = tempoCorrenteComutacao;
          TRIP_A = true;
          TRIP_B = false;
          ativaSaida_B(true);

and I don't see either delay() or delayMicroseconds() within it.

Also I did ask you which line, not which nineteen lines.

...R