Audio sweep oscillator with the 8051

It is ridiculously easy to implement a sweep oscillator in the analogue domain (at least for part of the audio spectrum). If you already have a microcontroller board, on the other hand, you might as well try this project.

A sweep time of about one second has been chosen: Much longer and it will be difficult to observe the trace on an oscilloscope (or photograph). A much shorter sweep cannot give satisfactory coverage of the lowest audible frequencies. Normally, the sweep is required to spend the same amount of time in every octave. There are 12 different frequencies from about 18 Hz to about 20KHz, though the waveform quality at the highest frequencies is poor.

Unless the code becomes much longer, I could not think of a faster way to index 256 different memory locations, though I have only programmed the 8051 for a few days. (Sine waveform quality at the highest frequencies is determined by the speed of the main loop). This was about 400Hz, for a 0.5 MIPS device. Higher frequencies are obtained by using subsampling, while lower frequencies are easily produced by oversampling.

      mov dptr, #0
      mov r0,   #table
more: mov a,r0
      movc a,@a+dptr ; read table item
      mov P1,a
      mov a,dpl
      add a,r2 ; subsampling step
      mov dpl,a
      jnz more ;  loop for all samples requested
     

There are many cheap devices which will convert a million samples a second at 8 bits, but since the project was built while at the countryside, the converter was made from an R-2R resistor ladder. Many microcontrollers include a DAC, of course, but I am not assuming you have one of those.

Digital to analogue converter

Twelve different frequencies are inadequate to test a filter such as the twin T, but steep filters are of questionable value in high quality audio. For testing purposes, a simple bandpass filter was used:

Bandpass filter

There is a synchronising output provided at P3.2, but my old oscilloscope does not seem to be able to get triggered when the time base is set at one second. Ergo, the program was slightly modified and the time base waveform was actually used to trigger the 8051 board, after considerable attenuation:

Time base signal attenuator

Here is the source code and hex file for this project. Another program (and the corresponding hex file) produce 96 different frequencies, but a different amount of time is spent in every octave, so this is mainly intended as an effect.

Here is the oscilloscope response contrasted to Spice results (precision capacitors have not been used):

 Filter response to sweep

For my own code: Valid XHTML 1.0!

1