minimum code pseudo sine wave

Programming the 6502 microprocessor and its relatives in assembly and other languages.
Post Reply
bogax
Posts: 250
Joined: 18 Nov 2003

minimum code pseudo sine wave

Post by bogax »

Just playing

This is meant to be the standard parabolic pseudo sine wave generator.
in the absolute minimum of code.

Code: Select all

 clc
 ldy #$10
 lda #$7F
LOOP1
 dey
LOOP2
 sty temp
 adc temp
 bmi LOOP1
 iny
 jmp LOOP2
User avatar
GARTHWILSON
Forum Moderator
Posts: 8773
Joined: 30 Aug 2002
Location: Southern California
Contact:

Re: minimum code pseudo sine wave

Post by GARTHWILSON »

Good job! Here's what I got on the oscilloscope, having added only STA VIA2PA afer the ADC instruction to send the result to the D/A converter:
PseudoSine.jpg
PseudoSine.jpg (28.86 KiB) Viewed 1669 times
It would be even slightly better if I were to sync it to a timer interrupt, since as it is it's a couple more clocks for one half of the cycle than it is for the other (19 versus 17 with the variable not in ZP).
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
bogax
Posts: 250
Joined: 18 Nov 2003

Re: minimum code pseudo sine wave

Post by bogax »

GARTHWILSON wrote:
It would be even slightly better if I were to sync it to a timer interrupt, since as it is it's a couple more clocks for one half of the cycle than it is for the other (19 versus 17 with the variable not in ZP).
hmm

I get 15 and 13 cycles.

I guess if you were going to time it with code you'd have to add
a nop to the dey side.

Code: Select all

 clc
 ldy #$10
 lda #$7F
LOOP1
 nop
 dey
LOOP2
 sty temp
 adc temp
 bmi LOOP1
 iny
 jmp LOOP2
I wasn't really thinking of it as having any practical use :)
User avatar
GARTHWILSON
Forum Moderator
Posts: 8773
Joined: 30 Aug 2002
Location: Southern California
Contact:

Re: minimum code pseudo sine wave

Post by GARTHWILSON »

Add 4 clocks for the STA VIA2PA (for the D/A converter).

About the NOP-- of course. I was in too big of a hurry. :oops:
Quote:
I wasn't really thinking of it as having any practical use :)
I have recently been watching videos of home-computer history (or should I say "listening," since I had them going while working and didn't keep my eyes glued) and it was interesting that Jobs and Woz were going to these meetings of hobbyists who were trying to build their own computers that did absolutely nothing useful, and even that first huge Altair was pretty useless, apparently having only toggle switches for inputs and LED for outputs. My workbench computer gets used only for real-life control and data collection on the workbench though, and I might do an FFT on this method to get some harmonic-distortion numbers. It may come in handy someday. In the past I've done it with look-up tables which works well too of course.
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
Post Reply