programmer >> Using Apple II for frequency generator

by aiiadict » Mon, 12 Jun 2006 02:02:40 GMT

Hello group,

I want to program a loop to generate varying frequencies from
1hz to 500khz, out the gameport. This is to test the resonant
frequency of a Tesla coil...

The tightest loop I can think of:

loop STA gameport
add JMP LOOP


to decrease frequency, have a BASIC program
insert a NOP, JMP LOOP at add....

loop STA gameport
add NOP
JMP LOOP

then move add up by one byte:

loop STA gameport
add NOP
JMP LOOP

using stock 6502 (1mhz) what is the highest
frequency I can generate? What is the formula
to convert the above codes output to Khz?

Rich



programmer >> Using Apple II for frequency generator

by Andy McFadden » Mon, 12 Jun 2006 02:11:42 GMT




STA absolute takes 4 cycles.
JMP absolute takes 3 cycles.

The 6502 operates at (I think) 1.024 MHz, yielding 146285 repetitions
per second, or 146KHz.

You can improve this by doing:

loop STA gameport
STA gameport
STA gameport
[...]
JMP loop

With enough STAs, the JMP goes into the noise, and you get 256KHz.

--
Send mail to XXXX@XXXXX.COM (Andy McFadden) - http://www.fadden.com/
CD-Recordable FAQ - http://www.cdrfaq.org/
CiderPress Apple II archive utility for Windows - http://www.faddensoft.com/
Fight Internet Spam - http://spam.abuse.net/spam/ & http ://spamcop.net/


programmer >> Using Apple II for frequency generator

by aiiadict » Mon, 12 Jun 2006 03:00:17 GMT




Thanks.... I'll have to experiment with the Transwarped IIe to see if I
can
break the 256khz barrier... I wonder if the TWIIe slows down for
gameport
access... I can check with my frequency meter, and the miniassembler
to enter code.

R



programmer >> Using Apple II for frequency generator

by Michael J. Mahon » Mon, 12 Jun 2006 15:51:37 GMT





It shouldn't.

-michael

Parallel computing for 8-bit Apple II's!
Home page: http://members.aol.com/MJMahon/

"The wastebasket is our most important design
tool--and it is seriously underused."


programmer >> Using Apple II for frequency generator

by BLuRry » Tue, 13 Jun 2006 22:06:59 GMT

I've seen some people use the BIT opcode when messing with the speaker
-- probably used to preserve the value of the accumulator. It also
takes 4 cycles. Not sure if that's worth anything. Here's a way to
shave off a cycle using a relative branch (2 cycles unless you jump a
page boundary)

start: clc
loop: sta gameport
bcc loop
which is then 6 cycles instead of 7. If the previous version yieded
146khz, this should make it 170khz.







programmer >> Using Apple II for frequency generator

by Andy McFadden » Wed, 14 Jun 2006 02:00:19 GMT




I believe branch instructions require 2 cycles if the branch is not taken,
3 if it is taken, or 4 if the branch is taken across a page boundary.

http://www.6502.org/tutorials/6502opcodes.html

--
Send mail to XXXX@XXXXX.COM (Andy McFadden) - http://www.fadden.com/
CD-Recordable FAQ - http://www.cdrfaq.org/
CiderPress Apple II archive utility for Windows - http://www.faddensoft.com/
Fight Internet Spam - http://spam.abuse.net/spam/ & http ://spamcop.net/


programmer >> Using Apple II for frequency generator

by BLuRry » Wed, 14 Jun 2006 05:09:29 GMT

> I believe branch instructions require 2 cycles if the branch is not taken,

Whoops... silly me. I misread my own reference.

http://www.obelisk.demon.co.uk/65C02/reference.html #BCC

Sorry about the confusion there.

-B



programmer >> Using Apple II for frequency generator

by Ed Eastman » Wed, 14 Jun 2006 15:35:19 GMT



...


Seems like you may want to run an external circuit with maybe a 555
timer that you can trigger and adjust from the II. I am certain someone
here has access to aproject book that may have such a ciecuit. Just
remember to isolate your power sources and measuring equipment, a tsla
coil can produce a large voltage spike (not to mention current) that may
be unhealthy for your Apple II.

Thankx,
Ed


programmer >> Using Apple II for frequency generator

by heuser.marcus » Thu, 15 Jun 2006 01:56:12 GMT





Perhaps a card with an 6522 could be an alternative.
I'm fairly sure that Rich has some lying around.

Use PB7 as the output, program timer 1 to count down as fast as you
like and set it up for continuous operation. This will output a square
wave.

IIRC the timers operate at system clock rate so that should be fast
enough. Better check the data sheets, however, as my memory is a bit
hazy ;o)

bye
Marcus



programmer >> Using Apple II for frequency generator

by Michael J. Mahon » Thu, 15 Jun 2006 12:41:16 GMT




BIT messes with the status bits, while STA leaves everything alone.

Any absolute reference is going to be a 4-cycle op (3 to fetch, + 1).

You can't jump *anywhere* with a 6502 in less than 3 cycles, regardless
of the opcode.

-michael






--

-michael

Parallel computing for 8-bit Apple II's!
Home page: http://members.aol.com/MJMahon/

"The wastebasket is our most important design
tool--and it is seriously underused."


programmer >> Using Apple II for frequency generator

by Michael J. Mahon » Thu, 15 Jun 2006 12:47:40 GMT






You remember correctly.

A 6522 clocked at 1MHz can generate a 500kHz square wave.

The problem with using anthing clocked at 1MHz to generate frequencies
this high is that your frequency resolution is *terrible*. The highest
frequency you can generate is 500kHz, the next highest is 333kHz, the
next highest is 250kHz, etc. See the problem?

Much better to build a little tuned circuit oscillator which will have
infinite resolution and can produce a sinewave output. A 3:1 tunable
range shouldn't be hard to do.

Using an Apple as an arbitrary frequency generator gets more interesting
at lower frequencies (like audio).

-michael

Parallel computing for 8-bit Apple II's!
Home page: http://members.aol.com/MJMahon/

"The wastebasket is our most important design
tool--and it is seriously underused."


programmer >> Using Apple II for frequency generator

by heuser.marcus » Fri, 16 Jun 2006 01:56:26 GMT




This "could" be a problem. Rich will know if ;-)


Of course you are right. But one would have to build something first.


I bet the designers of the 6522 had audio output in their minds, too.
I re-read the datasheet today and got the impression the timers are
seldomly used to their full potential.
And I doubt that they were often used for such high frequencies.

bye
Marcus



programmer >> Using Apple II for frequency generator

by Michael J. Mahon » Fri, 16 Jun 2006 13:55:19 GMT





He wanted to use it to "tune" a Tesla coil--he will want to use
a continuously variable frequency to do that.


Sometimes you have to do that...


They also included the ability to rotate a "serial" register
under timer control, allowing some control of harmonics.

-michael

Parallel computing for 8-bit Apple II's!
Home page: http://members.aol.com/MJMahon/

"The wastebasket is our most important design
tool--and it is seriously underused."


programmer >> Using Apple II for frequency generator

by Linards Ticmanis » Sun, 18 Jun 2006 02:10:05 GMT





The serial shift register is known to be buggy however, at least in
early 6522s. That's why the Commodore VIC 20 (and in consequence the
Commodore 64) have such a god awful slow serial bus if you don't run a
fastloader.

--
Linards Ticmanis


programmer >> Using Apple II for frequency generator

by Michael J. Mahon » Sun, 18 Jun 2006 03:06:47 GMT





I wouldn't expect much problem from a circular shift register. ;-)

I presume the problem is with the handshaking related to the shift
register function...or is it?

-michael

Parallel computing for 8-bit Apple II's!
Home page: http://members.aol.com/MJMahon/

"The wastebasket is our most important design
tool--and it is seriously underused."


Similar Threads

2. Apple II Dos - Apple II " The DOS Manual - Disk Operating System "

3. Apple II E-books CD electronic copy of apple II books

Hi group,

Apple II technical reference
CD.

$25 shipped anywhere in USA,
includes understandingIIe,
interface card building books,

several books off the net that
I didn't scan are also included.

all are in PDF format.  I have
bitmap format available as well.

Rich

aiiadict AT gmail DOT com

4. Manual Apple II Dos - Apple II " The DOS Manual - Disk Operating System "