Join us in the search for Free Energy. Share your experiments and discoveries, post your build logs, and discuss.
We have a strict No-Troll policy. So you can post without fear of being ridiculed.

New Members- Check Your Spam Folder For Activation Link

Please read our Rules. Any problems or suggestions- Contact Us


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Isolated H-bridges Maintaining 90 degrees sync'd phases
#1
UPDATE--  After much testing- This Code Presented Below Did NOT work that great.  Changing frequency disrupted the phase shift.  I will leave it up in case someone wants to do something similar in the future. 


~~~~~~~~~~~~~~~~

These codes are for a Master and Slave Arduino.  Each Arduino has it's own H bridge and it's own NRF24L01 transceiver.

The aim is for the 2 outputs to be square wave AC that are phase shifted 90 degrees from each other WITHOUT sharing or bonding ground wires.  

Your IDE must have the RF24 library for this code.

MASTER CODE
H-bridge pins are 6/7 on this example
pins 2/3/4 are supplying constant 5V for my H-bridge needs

Code:
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>

RF24 radio(9, 10); // CE, CSN
const byte address[6] = "00001";
int h6 = 6; // H-bridge control pin 1
int h7 = 7; // H-bridge control pin 2

void setup() {
  Serial.begin(9600); // Initialize Serial communication
  pinMode(2, OUTPUT); // Keep pin 2 HIGH
  digitalWrite(2, HIGH);
  pinMode(3, OUTPUT); // Keep pin 3 HIGH
  digitalWrite(3, HIGH);
  pinMode(4, OUTPUT); // Keep pin 4 HIGH
  digitalWrite(4, HIGH);
  pinMode(h6, OUTPUT);
  pinMode(h7, OUTPUT);

  radio.begin();
  radio.openWritingPipe(address);
}

void loop() {
  // Set "Polarity 1" and send the command to the slave
  digitalWrite(h6, HIGH);
  digitalWrite(h7, LOW);
  Serial.println("Polarity 1");
  sendCommandToSlave("Polarity 1", sizeof("Polarity 1"));
  delay(10);

  // Set "Polarity 2" and send the command to the slave
  digitalWrite(h6, LOW);
  digitalWrite(h7, HIGH);
  Serial.println("Polarity 2");
  sendCommandToSlave("Polarity 2", sizeof("Polarity 2"));
  delay(10);
}

void sendCommandToSlave(const char* command, size_t size) {
  radio.write(command, size);
}


SLAVE CODE
H-bridge pins are 14/15 on this example
pins 18/19 are supplying constant 5V for my H-bridge needs

Code:
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>

RF24 radio(9, 10); // CE, CSN
const byte address[6] = "00001";
int h1 = 14; // H-bridge control pin 1
int h2 = 15; // H-bridge control pin 2

void setup() {
  // Ensure constant HIGH pins
  pinMode(18, OUTPUT);
  digitalWrite(18, HIGH);
  pinMode(19, OUTPUT);
  digitalWrite(19, HIGH);

  pinMode(h1, OUTPUT);
  pinMode(h2, OUTPUT);

  Serial.begin(9600); // Initialize Serial communication

  radio.begin();
  radio.openReadingPipe(0, address);
  radio.startListening();
}

void loop() {
  // Wireless communication handling
  if (radio.available()) {
    char command[15];
    radio.read(&command, sizeof(command));

    if (strncmp(command, "Polarity 1", 10) == 0) {
      // Process "Polarity 1" command
      Serial.println("Received Polarity 1");
      digitalWrite(h1, HIGH);
      digitalWrite(h2, LOW);
    } else if (strncmp(command, "Polarity 2", 10) == 0) {
      // Process "Polarity 2" command
      Serial.println("Received Polarity 2");
      digitalWrite(h1, LOW);
      digitalWrite(h2, HIGH);
    }
    // You can add more conditions for other commands if needed
  }
}
Reply
#2
Sweet ....

https://www.youtube.com/watch?v=Kfx2d4d-oko


EDIT for an addition of a hyper link to H bridge descriptions.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)