Phaseshift for ultrasoundlevitation

Hello,

for my studies i want to levitate objects with ultrasound. Thats not the problem, since there are enough tutorials for this in the web.

What i need is a phaseshift that can be done with a potentiometer. So that i can turn it modify where my stable areas are.

If i am not wrong it needs to phaseshift one 45° forward (for e.g.) and the other side 45° backwards.

This is the base projekt i am using:

An this is my code rigt now:

byte TP = 0b10101010; //jeder 2. Port bekommt das umgekehrte Signal

void setup()
{
 DDRC = 0b11111111; //Alle Analogports als Ausgang definieren
 
  // Timer 1 initialisieren
  noInterrupts();           // Interrupts deaktivieren
  TCCR1A = 0;
  TCCR1B = 0;
  TCNT1  = 0;

  OCR1A = 200;              // Compare Match Register setzen (16MHz / 200 = 80kHz Rechteck -> 40kHz Vollwelle )
  TCCR1B |= (1 << WGM12);   // CTC mode
  TCCR1B |= (1 << CS10);    // Prescaler auf 1 ==> kein prescalling
  TIMSK1 |= (1 << OCIE1A);  // Compare Timer Interrupt einschalten
  interrupts();             // Interrupts aktivieren
}

ISR(TIMER1_COMPA_vect)          
{
  PORTC = TP; // Den Wert TP an die Ausgange senden
  TP = ~TP;   // TP invertieren für den nächsten durchlauf
}

void loop(){
  // hier bleibt  nichts zu tun übrig:-(
}

some help would be quite nice, since this is my first projekt with an arduino.

greeting Marcel

The code simply produces an oscillating signal on an output pin, beginning at some arbitrary time.

A phase shift is defined with reference to some initial time, or some other oscillator. What will be the reference?

jremington:
The code simply produces an oscillating signal on an output pin, beginning at some arbitrary time.

A phase shift is defined with reference to some initial time, or some other oscillator. What will be the reference?

And with no reference, all you get is frequency change, which may be what you really need for your project.

Paul

Masland:
If i am not wrong it needs to phaseshift one 45° forward (for e.g.) and the other side 45° backwards.

You'll need two timer counters to do this, set them up synchronized in frequency and you can
set the phase by updating both count registers in quick succession.