Square Wave Generator

This little project is already done! The source code is here. You'll need QForth to run it. See my main page to get it.

The theory of operation is simple: Turn annunciator 2 on, wait a bit, turn it off, wait a bit more, and check to see if a key has been hit.

The checking a key bit has to be done quickly, so the entire square wave generation is done in a small section of machine code compiled into the Forth dictionary. The assembly code is:

     LDA #0
     STA $C010  ; clear the keyboard strobe
LOOP LDA $C05D  ; turn AN2 off
     LDA $300   ; get the delay from Forth
     JSR $FCA8  ; call monitor WAIT
     LDA C05C   ; turn AN2 on
     LDA $300   ; WAIT again
     JSR $FCA8  ; (about 0.5*(26+27*A+5*A^2) usec)
     LDA $C000  ; check keyboard
     BPL LOOP   ; branch if no key
     LDA #0     ; clear the strobe so we don't
     STA C010   ; have the key hanging around
     RTS        ; all done, back to Forth
Since the routine calls the standard monitor WAIT routine at 0xFCA8 it works on an Apple IIgs regardless of the IIgs' clock rate.

The output frequency is an estimate since I don't have a frequency counter or true oscilloscope. Instead, I used my old Mac 7300 and an equally old "oscilloscope" program to display the square wave and then estimated the period from the screen. It will be good enough for my VLF testing, I'm sure.

Naturally, this program requires a real Apple II.


Last update: 03-Jul-2009
Back