Detecting zero crossings from sin LFO

Algorithm development and general DSP issues

Moderator: frank

Post Reply
Digital Larry
Posts: 338
Joined: Mon Nov 12, 2012 1:12 pm
Contact:

Detecting zero crossings from sin LFO

Post by Digital Larry »

I should be able to do this, right?

<init LFO>

sin equ reg0

ldax sin
cho rdal, sin0
skp zrc sincrossing
wrax sin, 0

skp run, notcrossing

sincrossing:
etc, etc, etc.

notcrossing:
etc, etc, etc
-------------------------
Right now what it appears is happening is that the zrc is detected for fully half of the cycle.

I'll try it later tonight and post actual code example. There aren't a ton of skp zrc cases and I didn't find one yet that used the sin LFO as the source.

Thanks,

DL
Digital Larry
Posts: 338
Joined: Mon Nov 12, 2012 1:12 pm
Contact:

Post by Digital Larry »

Think I got it.

Code: Select all

equ sinreg reg0
equ output reg1

skp run, initend
wlds sin0, 111, 32767
initend:

ldax sinreg
cho rdal, sin0
skp zrc, sincrossing
wrax sinreg, 0
skp zro, nocrossing

sincrossing:
wrax sinreg, 0
ldax adcl
wrax output, 1
wrax dacr, 1
wrax dacl, 0
skp run, finish

nocrossing:
ldax output
wrax dacr, 1
wrax dacl, 0

finish:
frank
Posts: 1244
Joined: Wed Oct 19, 2005 12:26 pm
Contact:

Post by frank »

That looks good, could save an instruction doing:

Code: Select all

equ sinreg reg0
equ output reg1

skp run, initend
wlds sin0, 111, 32767
initend:

ldax sinreg
cho rdal, sin0
skp zrc, sincrossing
wrax sinreg, 0
ldax output
wrax dacr, 1
wrax dacl, 0
skp zro, finish

sincrossing:
wrax sinreg, 0
ldax adcl
wrax output, 1
wrax dacr, 1
wrax dacl, 0

finish: 
Frank Thomson
Experimental Noize
Digital Larry
Posts: 338
Joined: Mon Nov 12, 2012 1:12 pm
Contact:

Post by Digital Larry »

Thanks Frank.

I could save a couple more with:

Code: Select all

equ sinreg reg0
equ output reg1

skp run, initend
wlds sin0, 111, 32767
initend:

ldax sinreg
cho rdal, sin0
skp zrc, sincrossing
wrax sinreg, 0
ldax output
skp run, finish

sincrossing:
wrax sinreg, 0
ldax adcl
wrax output, 1
finish: 
wrax dacr, 1
wrax dacl, 0

Digital Larry
Posts: 338
Joined: Mon Nov 12, 2012 1:12 pm
Contact:

Post by Digital Larry »

Hi Frank,

Somewhat esoteric question about skp zrc, x:

Suppose the waveform we are tracking is oscillating +/- around 0. But on its way from + to -, it actually lands right on zero. Then in the next cycle it goes from 0 to - something. Will the zero crossing (over two cycles) be detected or missed?

Thanks,

DL
frank
Posts: 1244
Joined: Wed Oct 19, 2005 12:26 pm
Contact:

Post by frank »

Good question, been years since I looked at that part of the circuit. If I remember correctly I am looking at a sign change so it should only fire on 0-to-negative if you hit exactly 0.
Frank Thomson
Experimental Noize
Post Reply