Phase shift between Pins

Same as this
Can we do with D2 and D8

We seem to be missing some basic information relating to your project. What are you attempting to make?

sorry
I needed a frequency counter at D2&D8

Can we able to make it

  1. You have not mentioned the controller you are going to use.

But from your link in post #8:

You can use input pins that are related to a timer.

if (D2 in table) {you can use it} else {not usable}
if (D8 in table) {you can use it} else {not usable}

  1. Why do you think pulseIn() is too slow for 20 kHz?

see here https://www.arduino.cc/reference/en/language/functions/advanced-io/pulsein/

Works on pulses from 10 microseconds to 3 minutes in length.

Pulse length 10 micros -> periode length 2 x pulse length -> 20 micros -> 50 kHz

You might have to use a Schmitt-Trigger IC depending on the unknown signal shape to generate clear digital signals ... see https://en.wikipedia.org/wiki/Schmitt_trigger

Because, I want to generate 30Hz as output after sensing the input frequency at 5,6,10&11

What type of wave is this 20KHz frequency?
AC sinusoid with zero cross?
AC sinusoid with DC level equal to peak?
Square wave?
Describe your needs and your project better.
20 KHz = 20,000 per second; 20 pulses per millisecond;
1 cycle every 50 uSeconds.

Hi all,
we need to provide dummy hall feedback at pins 5,6,10&11 with phase shift between them after we are getting a 10.82KHz frequency at pin 2& pin 8 from another microcontroller.
This 10.82KHz is a Square wave
pin-2 should active(5,6)
pin-8 should active(10,11)
should output should be a PWM (square-wave)

Can we generate this

Hi
Will I directly get the pulse after powering the arduino or should I need to pull down any one input put to get the ouptut pulse.

30Hz output when you detect 10.82KHz input?
-Yes

Do you need to modulate the frequency of the output based on the input? If not then it is even easier.
-No
constant output of 30Hz and 50% duty

Does the input have to be exactly 10.82KHz? What should happen if it is off?
-Yes
If it is off output should not be generated

It sounds like you are building a tester for a motor controller. Is that right? Did I guess it?
-yes

No, you can't

Why do you need it in that exact pins?

On power up all the Arduino's pins are set to be inputs. This lasts until the boot loader has finished looking to see if you want to upload code or just run what you have.

This means that pins destined to be outputs will in effect float and could very well trigger an output that requires a logic HIGH to run something. In those cases then a pull down resistor on that pin will prevent this from happening.

If a logic LOW is required to make something run then an external pull up resistor will prevent this from happening.

Okay
Any other way

Yeah,
I mean Should I have to ground any input after flashing the code and able to check the output

Are you need a detection in a both D2 and D8 pins or on any one from it?

I need both of them

This is not giving me the proper output
Able to see only varing frequency between 6-10Hz
Duty is 10-20%

// Working code with feedback of 10.82KHz.
// Working tested on 10/11/2023
int Freq = 0;
int Freq1 = 0;
int Freq2 = 0;

ISR(TIMER1_COMPA_vect){
  static int times = 0;
  times = (times + 1) & 3 ;
  if(Freq == 1){
  if(times == 0) { digitalWrite(5, HIGH);}
  if(times == 1) { digitalWrite(6, HIGH);}
  if(times == 2) { digitalWrite(5, LOW);}
  if(times == 3) { digitalWrite(6, LOW);}
  }
  if(Freq1 == 2 ){
  if(times == 0) { digitalWrite(10, HIGH);}
  if(times == 1) { digitalWrite(11, HIGH);}
  if(times == 2) { digitalWrite(10, LOW);}
  if(times == 3) { digitalWrite(11, LOW);}
  }
  if(Freq2 == 3 ){
  if(times == 0) { digitalWrite(5, LOW);}
  if(times == 1) { digitalWrite(6, LOW);}
  if(times == 2) { digitalWrite(10, LOW);}
  if(times == 3) { digitalWrite(11, LOW);}
  }
}

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(2,INPUT);
  pinMode(5,OUTPUT);
  pinMode(6,OUTPUT);
  pinMode(8,INPUT);
  pinMode(10,OUTPUT);
  pinMode(11,OUTPUT);
  
  cli();//stop interrupts
//set timer1 values
//set timer1 interrupt at 1Hz
  TCCR1A = 0;// set entire TCCR1A register to 0
  TCCR1B = 0;// same for TCCR1B
  TCNT1  = 0;//initialize counter value to 0
  // set compare match register for 120 Hz increments
  OCR1A = 128;
  // turn on CTC mode
  TCCR1B |= (1 << WGM12);
 // Set CS12 and CS10 bits for 1024 prescaler
  TCCR1B |= (1 << CS12) | (1 << CS10); 
  // enable timer compare interrupt
  TIMSK1 |= (1 << OCIE1A);
  sei();//allow interrupts 
}

void loop() {
  // put your main code here, to run repeatedly:
  Timer1();
  Timer2();

}
void Timer1(){
  // int PWM = pulseIn(2, HIGH);
  int PWM1 = pulseIn(2, LOW);
  int frequency1 = 500000 / (PWM1) ;
  Serial.println(frequency1);
  if((frequency1>4000)&&(frequency1<30000))
  {
    Freq = 1;
  }
  else{
    Freq2 = 3;
  }
}
void Timer2(){
  int PWM2 = pulseIn(8, HIGH);
  int PWM3 = pulseIn(8, LOW);
  int frequency2 = 500000 / (PWM2+PWM3) ;
  Serial.println(frequency2);
  if((frequency2>4000)&&(frequency2<30000))
  {
    Freq1 = 2;
  }
  else{
    Freq2 = 3;
  }
}

Will I able to generate 30HZ with 50% duty and Phase shift between two pins with input of 10.82KHz constant frequnecy with variable duty
pin-2(pin-5&pin-6 )with phase shift between them
pin-8(pin-10&pin-11 ) with phase shift between them

If it won't work out.
Can, I get ideas which make it to workout

You said it, and I said:-

That means the wave should run **unless ** these pins are grounded.

Maybe this is because you never posted the whole of your code so we could spot errors and omissions.

That code I posted has nothing to do with the range of frequencies, it only covered the ISR enabling and disabling the wave. The rest of the code you are keeping to yourself.

I can confirm that Mike's code is giving 30Hz outputs on pins D5,D6 and D10,D11.

Pin D2 enables D5,D6.


Similarly Pin D5 enables D10,D11.

we can take around9-12KHz