top of page
  • Writer's pictureRAJ SHARMA

Arduino 6.255KHZ Output, 180 DEGREE PHASE PULSE ( Dual Phase)


Arduino Code


Arduino 6.255KHZ Output, 180 DEGREE PHASE PULSE
.zip
Download ZIP • 812B

// Generating Two 180° Out of Phase 6.255 kHz Square

// Waves with dead time on Timer1 of an

// Arduino UNO (Pins 9 and 10)

// Written January 23rd, 2023 by John Wasser


// frequency = 16MHz / (2 * prescaleFactor * (TOP + 1))

// Correction, because Phase Correct PWM is used:

// frequency = 16MHz / (2 * prescaleFactor * TOP)

const unsigned TOP = 1280;

// frequency = 16MHz / (2 * 1 * 160)

// frequency = 16MHz / 320

// frequency = 50,000


void setup()

{

Serial.begin(115200);

delay(200);


digitalWrite(9, LOW);

pinMode(9, OUTPUT);

digitalWrite(10, LOW);

pinMode(10, OUTPUT);


// Stop Timer/Counter1

TCCR1A = 0; // Timer/Counter1 Control Register A

TCCR1B = 0; // Timer/Counter1 Control Register B

TIMSK1 = 0; // Timer/Counter1 Interrupt Mask Register


// Set Timer/Counter1 to Waveform Generation Mode 8:

// Phase and Frequency correct PWM with TOP set by ICR1

TCCR1B |= _BV(WGM13); // WGM=8

TCCR1A |= _BV(COM1A1); // Normal PWM on Pin 9

TCCR1A |= _BV(COM1B1) | _BV(COM1B0); // Inverted PWM on Pin 10


ICR1 = TOP;

// Difference between OCR1A and OCR1B is Dead Time

OCR1A = (TOP / 2) - 1;

OCR1B = (TOP / 2) + 1;


// Start timer by setting the clock-select bits to non-zero

TCCR1B |= _BV(CS10); // prescale = 1

}


void loop() {}



10 views0 comments

Recent Posts

See All

1 Minute and 10Minute Timer , Arduino Code

Ten Minute Code const int switch_on = 5, output = 9; int offtime = 1, off_timer_start = 0; void setup() { pinMode(switch_on, INPUT); pinMode(output, OUTPUT); } void loop() { int x = ((millis() / 10000

Comments


bottom of page