I have a frequency divider program that almost works. I'm trying to measure an incoming pulse, and divide the frequency by a designated value "divider" then output the new frequency.
I said it almost works because it seems like the instructions in the loop is causing a delay which is making the output signal unable to have a 50% duty cycle. I've tried lengthening and shortening the calculations done in the loop, and I'm pretty sure thats the issue.
Can someone please help me account for this delay? Also, if I were to modify this in the future by using an Arduino Micro, how would this delay differ?
Because you are using the delayMicroseconds() function there will be no variability there. There remainder of the instructions will be faster/slower depending on the clock speed, 8Mhz vs 16Mhz.
I hate to say this, as I don't know how much experience you have plus the general feeling on this forum, but I would suggest looking into the interrupts. Pin interrupt for detecting the edges of the pulse and the timer interrupt for changing the state of the output pin. If you want to get fancier, then another timer interrupt for timing the incoming pulse. A word of caution, the timer setpoints will vary with (or you will need to vary/compensate for) the different clock speeds (8MHz vs 16MHz); which is different than the (blocking) delay functions you are currently using.
A hardware frequency divider is better. For example, a [u]Type-T flip-flop[/u] toggles the output-state on every falling-edge on the input. That cuts the frequency exactly in half and puts-out a square wave. And, there are frequency-divider/counter chips which work similarly.
You may use a Timer/Counter (Timer1 is likely the best option). You may set it to be clocked from an external source and generate the divided frequency on an Output Compare pin.
For another example doing something similar look at AC phase cutting code. It uses interrupts to detect the zero crossing, and then sets timer interrupts to produce an output pulse.
Interrupts are a good use for this, also much higher resolution than the delayMicroseconds() function can offer: you can go down to 62.5 ns resolution (single clock pulse on a 16 MHz Arduino).