test the function of a counter

Algorithm development and general DSP issues

Moderator: frank

Post Reply
alpignolo
Posts: 20
Joined: Tue May 27, 2014 8:40 am

test the function of a counter

Post by alpignolo »

Hello, i'm new in this forum.
I have write this code for test the function of a counter.
It should make sound by Left Out every 2.7 seconds, but don't work, it make sound always.
Where is the error?
Thanks

Code: Select all

equ time reg0
equ number reg1

equ counter 0.00001

skp run,START 
sof 1,-0.5
wrax number,0
sof 0,0
wrax time,0

START: 

ldax time
sof 1,counter
wrax time,1
sof 1,-0.9
skp neg,ONE
sof 0,0
wrax time,0
ldax number
sof -1,0
wrax number,0

ONE:
ldax number
skp neg,TWO
rdax 20,0
wrax 22,0
skp zro,END

TWO:
RDAX 20,1
WRAX 22,0

END:
slacker
Posts: 116
Joined: Tue Feb 01, 2011 1:13 pm

Post by slacker »

Your value for counter is too small, if you look at the sof command http://www.spinsemi.com/knowledge_base/ ... x.html#SOF

the constant is 11 bits (2048 values) spread over -1 to 0.999 which is a range of 1.999
1.999/2048 = 0.00098 that's the smallest number the constant can be. Any smaller number probably gets rounded down to zero so your counter will not increase. You can check this by making counter a bigger number and your code will work.
alpignolo
Posts: 20
Joined: Tue May 27, 2014 8:40 am

Post by alpignolo »

Perfect! I try with a value of 0,001.
Now work good.
Many thanks
Digital Larry
Posts: 338
Joined: Mon Nov 12, 2012 1:12 pm
Contact:

Post by Digital Larry »

Hi Slacker,

Seems like you have your FV-1 number relationships well ingrained. This morning I was trying out different frequency ranges for an RDFX based low pass filter for control smoothing. I was trying to get down to 0.1 Hz but it seems like much below 0.5 Hz, the filter output would never move (in SpinCAD's simulator anyway).

I see that RDFX uses 16 bits for its constant. 1/65536 = 0.000015259...

At 0.5 Hz (32768 kHz sampling rate) I am getting 0.0000983399 for the filter constant. So you have sort of answered my question about "how low can you go" with an RDFX based LPF. Fortunately I think that 0.51 Hz or thereabouts is plenty low enough for most purposes.

I just checked the Spin ASM reference. RDFX uses an S1.14 for C.

S1.14
Bits = 16

Range
­2 to 1.99993896484

Resolution (LSB value)
0.00006103516

So this kinda makes sense. The other thing that pops out (unfortunately for me as it is just another complication) is that at low frequencies, I'm not really able to offer as much real resolution in filter frequency as I think. But I'll keep chewing on it.


DL
slacker
Posts: 116
Joined: Tue Feb 01, 2011 1:13 pm

Post by slacker »

Digital Larry wrote:Hi Slacker,
Seems like you have your FV-1 number relationships well ingrained.
I wish, I just figured it out by going through his code and I couldn't see any reason why it wasn't working, so guessed it might be the constant and went from there.
The same thing has bit me in the ass a few times, be nice if the assembler warned you about such things.
Post Reply