Using 'blink without delay' sketch to improve 100khz PWM signal

using the code I made that would look like what I need is not good, since I will be using more code later on and can not have a delay pausing the rest of the code.(100khz will be always on)

#include <util/delay.h>
void setup()
{
  pinMode(PD3, OUTPUT);
}

void loop()
{
  digitalWrite(PD3, HIGH);
  _delay_us(0.55);
  digitalWrite(PD3, LOW);
  _delay_us(0.55);
 
}

i have not seen this been done and wondered if that would even be the right path to take to make this code without a delay. Keeping in mind my very short "_delay_us(0.55); " line of code

Why don't you just use one of the timer libraries like Timer1 and use the timer for PWM so you don't have to worry about what to do in the main loop?

Any timer done in code has to account for any other instructions executed in the loop. If you want a steady output you should definitely use one of the hardware timers.

16,000,000 clock cycles per second * 0.00001 seconds = 160 clocks per cycle

Do you need varying duty cycle (PWM) or just a square wave?

sergy3:
just a square wave,
so all i would be doing is use play with the built in timers rather what i am doing? to achieve that 100khz pulse?

Once you set up the timer, the 100 kHz square wave will come out the pin an will continue until your sketch tells it to stop or you turn off the power.
The first step is to pick a timer. I will assume you are using an Arduino UNO. Since you are counting to less than 256 you can use Timer2 (the 8-bit timer). Timer0 is used for the millis() timer and should generally not be changed. Timer1 is a 16-bit timer that can count up to 65535. Several common libraries use Timer1 (like Servo, IRremote, and tone()) so if you can use Timer2 you should use it first.
There are a couple of ways to make a square wave: Toggle the output every 80 counts OR set the period of a PWM output to 160 counts and set the duty-cycle to 50% (80 cycles). The first one is easier.
Get a copy of the ATmega328P datasheet and read about Timer2. You will see that the two main registers to set are TCCR2A and TCCR2B (Timer/Counter Control Registers). Start by setting them both to 0:

  TCCR2A = 0;
  TCCR2B = 0;

Now look at the Waveform Generation Mode table for Timer2. You want the CTC mode (Mode 2). Since all of the TCCR bits have been set to 0 you only need to set one bit: WGM21 (Bit 1 of the WGM field of Timer2). Look at the TCCR registers and you will see that WGM21 is in TCCR2A.

  TCCR2A |= (1 << WGM21);

To tell the timer how high to count before cycling back to 0 you set the ‘TOP’ value. The WGM table says to put the value in the OCR2A register for CTC mode.

  OCR2A = 79;  // There are 80 counts, 0 to 79

To tell the counter how fast to count you set the Clock Select bits. We want it to count full speed (16 MHz) so we just have to turn on CS20. You’ll find it in the TCCR2B register:

  TCCR2B |= (1 << CS20);

The clock is off and running!
Now you want to tell the clock hardware to toggle an output pin each time the count hits TOP. You can use Pin 11 (OC2A) or Pin 3 (OC2B). Let’s assume Pin 3: OC2B. To tell the hardware to toggle, set the bits COM2B1 to 0 and COM2B0 to 1. Since we already set all the bits to 0 you only have to set COM2B0 which is in TCCR2A:

  TCCR2A |= (1 << COM2B0);

That’s all you need. Put it all in setup() and put nothing in loop() and your 100 kHz signal will come out of Pin 3 whenever your sketch is running.

void setup()
{
  // Clear the  Timer/Counter Control Registers for Timer 2
  TCCR2A = 0;
  TCCR2B = 0;


  // Set Waveform Generation Mode (WGM) 2 == "CTC"
  // Output Compare Register 2A (OCR2A) holds TOP
  TCCR2A |= (1 << WGM21);


  // Set TOP to 79 to get 80 ticks (5 microseconds) per half cycle.
  // That's 10 microseconds per cycle or 100 kHz.
  OCR2A = 79;


  // Set Compare Output Mode for pin OC2B to toggle 
  // at TOP to get a square wave
  TCCR2A |= (1 << COM2B0);


  // Clock Select == 1 (prescale == 1 == 16 MHz)
  // This starts the clock running.
  TCCR2B |= (1 << CS20);


  // You should now have 100 kHz coming out of pin OC2B == UNO Pin 3
}


void loop() {}

digitalWrite() is far too slow to produce a 100kHz output while other things are going on. (as are many other Arduino functions.) Maximum frequency without doing anything else at all is about 110kHz (See Maximum pin toggle speed - Frequently-Asked Questions - Arduino Forum)

(using a hardware timer is a much better idea!)