# How make a delay in square wave ?

Guys, i make a code about two square waves, and i need that one of them with a delay. Both have a same duty cycle, and this code is this:

#include <TimerOne.h>

void setup()
{
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
Timer1.initialize(10);
Timer1.pwm(9, 768);
Timer1.pwm(10,768);

}

So, i have two signals with 75% duty cycle, but starting in the same time. Anyone know how i can solve this?

Ps: Sorry for my bad english

I think this may be what you want. I can see 100KHZ on each pin, but don't have a scope and can't see the phasing. If I slow the frequency down I can see the 75% duty cycle.

``````//Square wave generator 100KHz
//two outputs 75% DutyCycle offset 270 degree
//Timer 1 PWM with ICR1 TOP end Mode 10

void setup() {

pinMode(9, OUTPUT); //output A
pinMode(10, OUTPUT); //output B

TCCR1A = 0; //clear timer registers
TCCR1B = 0;
TCNT1 = 0;
GTCCR |= 1 << PSRASY; //reset prescaler

//ICR1 and Prescaler sets frequency
//no prescaler .0625 us per count @ 16Mh
//160 counts x .0625 = 10 us = 100Khz

TCCR1B |= _BV(CS10); //no prescaler
ICR1 = 80;//PWM mode counts up and back down for 160 counts

OCR1A = 20; //Pin 9 match
//output A set rising/clear falling
//Rise at TCNT 20 upslope, High 120 counts, Fall at TCNT 20 downslope
//75% Duty Cycle Pulse centered on TCNT 80. High 120 Low 40
TCCR1A |= _BV(COM1A1) | _BV(COM1A0); //output A set rising/clear falling

OCR1B = 60; //Pin 10 match
//output B clear rising/set falling
//Fall at TCNT 60 upslope, Low 40, Rise at TCNT 60 downslope
//75% Duty Cycle Pulse centered on TCNT 0. High 120 Low 40
TCCR1A |= _BV(COM1B1); //output B clear rising/set falling

TCCR1B |= _BV(WGM13); //PWM mode with ICR1 Mode 10
TCCR1A |= _BV(WGM11); //WGM13:WGM10 set 1010

}
void loop () {}
``````