# Generating square wave using NXP LPC1768?

I have the following exercise here: Using any digital output pin, write a program which outputs a square wave, by switching the output repeatedly between Logic 1 and 0. Use wait( ) functions to give a frequency of 100 Hz (i.e., a period of 10 ms). View the output on an oscilloscope. Measure the voltage values for Logic 0 and 1. How do they relate to Fig. 3.1? Does the square wave frequency agree with your programmed value?

My problem is that I don't have an oscilloscope. Without it, this exercise is sort of impossible for me but I am guessing that indeed my frequency will be higher than expected.

I am thinking that it will be higher due to the output timing being dependant on the internal clock.

Am I right in thinking this? If not, what sort of frequency would I get and why?

• where is link to figure? – Tony Stewart Sunnyskyguy EE75 Jan 23 '19 at 16:41
• At 100 Hz you can use a computer soundcard, there may well be distortion but you could see frequence, duty cycle and jitter (for example if any interrupts periodically fire at a slow rate) – Chris Stratton Jan 23 '19 at 17:09

The comment of "Chris Stratton" is good for a simple measuring, and for learning

For the theoretically approach there are some basic you need to know about software: A while loop takes time (even the following empty one).

while(1){

}


this means that the following code will take more time then 10ms

while(1){
io_up;
wait(5ms);
io_down;
wait(5ms);
}


Further you need to know that the relation between frequency and time is

frequency=1/time
time=1/frequency


Which makes that more time is a lower frequency and vice versa.

At last i want to add that the use of a wait statement in embedded software is a vary bad practice. It makes it impossible to do multiple things simultaneously in a microprocessor. For timing critical software one should use interrupts, for non critical software one should use time-flags and and state-machines. So to create a stable signal of 100hz in a LPC1768 one should use the timer-matching-compare unit of the processor