Page 1 of 1

Detecting zero crossings from sin LFO

Posted: Wed Feb 24, 2016 12:18 pm
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

Posted: Wed Feb 24, 2016 6:56 pm
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:

Posted: Wed Feb 24, 2016 7:50 pm
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: 

Posted: Thu Feb 25, 2016 7:18 am
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


Posted: Fri Feb 26, 2016 8:34 am
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

Posted: Fri Feb 26, 2016 9:18 am
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.