1/X function issue

Software questions and issues with the FV-1

Moderator: frank

ZibiSound
Posts: 66
Joined: Fri Mar 15, 2013 3:02 pm

1/X function issue

Post by ZibiSound »

Hello,
I got a problem with 1/x calculation. Let's look at the test code I've made:

Code: Select all

rdax	pot0,	1
skp	zro,	2
log	-1,	0
exp	1,	0
wrax	reg0,	0

rdax	adcl,	0.05
rdax	adcr,	0.05
mulx	reg0

wrax	dacl,	1
wrax	dacr,	0
I would like to invert normal pot0 values 0<->1 to infinity<->1 (in practice ~100<->1) via 1/x formula.
The problem is it doesn't work. Regardless of the value of pot0, the output signal is constant and weak. Only when the pot0 reaches value of 0, the output signal stops (skp instruction). What am I doing wrong?
frank
Posts: 1244
Joined: Wed Oct 19, 2005 12:26 pm
Contact:

Re: 1/X function issue

Post by frank »

You can't generate gain that way, the result after the EXP will be clamped between 0 and 0.999, as it says in the instruction set PDF for EXP:

Positive logarithmic ACC values will be clipped to +0.99999988

So REG0 will always be 0.999... and your input is 0.1 (0.05+0.05 assuming same signal to ADCL and ADCR) so your output will be 0.0999... which is a very small signal.
Frank Thomson
Experimental Noize
ZibiSound
Posts: 66
Joined: Fri Mar 15, 2013 3:02 pm

Re: 1/X function issue

Post by ZibiSound »

Now I see, you're right.
So, what do you propose? How can I realize 1/x for output value >1?

Btw, registers are 24-bit, so max value I can write to them is 16777215? And what is the best accuracy of small values? 8 digits after point?
frank
Posts: 1244
Joined: Wed Oct 19, 2005 12:26 pm
Contact:

Re: 1/X function issue

Post by frank »

sebxx4 wrote: Wed May 05, 2021 12:33 pm Now I see, you're right.
So, what do you propose? How can I realize 1/x for output value >1?
You cannot really create 1/x as a linear value since it will be bigger than 1. The FV-1 normalizes to -1.0 to +0.9999.
sebxx4 wrote: Wed May 05, 2021 12:33 pm Btw, registers are 24-bit, so max value I can write to them is 16777215? And what is the best accuracy of small values? 8 digits after point?
No, the values are interpreted as -1.0 to +0.999... so no values will be considered integer, all are <1.0 (few exceptions like LOG but those are special cases). You cannot generate a large number to multiply by for gain, you will have to do adds or shifts.
Frank Thomson
Experimental Noize
ZibiSound
Posts: 66
Joined: Fri Mar 15, 2013 3:02 pm

Re: 1/X function issue

Post by ZibiSound »

Well, maybe there is some other way to make my program.
I would like to generate RAMP signal to control one of parameters in program. I need this RAMP to be variable time long (375ms <-> 600ms) and controlled via pot1. The values generated by ramp should change from +0.5 to 0. And the thing I got the biggest problem with is controlling RAMP frequency.
When value of pot1 is 0.375, ramp signal should be 375ms long (2,667Hz), when 0.5 - 500ms, when 0.6 - 600ms, etc. In general, it should vary linearly with the value of pot1, in the range of 0.375 - 0.600. But my scope observations shows the frequency of the RAMP increases with the factor entered into RMP0_RATE, that's why I needed the 1/x function to invert it (pot1 value up - ramp frequency down).
frank
Posts: 1244
Joined: Wed Oct 19, 2005 12:26 pm
Contact:

Re: 1/X function issue

Post by frank »

You don't need a 1/x you need a 1-x:

(1-POT1)

will go from 1 to 0 as POT1 goes from 0 to 1
Frank Thomson
Experimental Noize
ZibiSound
Posts: 66
Joined: Fri Mar 15, 2013 3:02 pm

Re: 1/X function issue

Post by ZibiSound »

Meh, I'm sitting and thinking about 1/x since 3 days, when it's so simple :D

I think it would be better to use 0.975-POT to keep original 1,6 factor between min and max value.

0.975 - 0.600 = 0.375
0.975 - 0.375 = 0.600

0.600 / 0.375 = 1,6

Thank you, Sir. It works fine.
frank
Posts: 1244
Joined: Wed Oct 19, 2005 12:26 pm
Contact:

Re: 1/X function issue

Post by frank »

sebxx4 wrote: Thu May 06, 2021 9:36 pm I think it would be better to use 0.975-POT to keep original 1,6 factor between min and max value.
Problem with this is if POT > 0.975 then the result is negative, you may consider:

(1 - POT) * 0.225 + 0.375

Result will now range 0.600 to 0.375 linearly.
Frank Thomson
Experimental Noize
ZibiSound
Posts: 66
Joined: Fri Mar 15, 2013 3:02 pm

Re: 1/X function issue

Post by ZibiSound »

You're right, but as I said, I'm only intrested in range of 0.375 <-> 0.600 ;)
This input will be controlled via dac, there won't be another voltages.
ZibiSound
Posts: 66
Joined: Fri Mar 15, 2013 3:02 pm

Re: 1/X function issue

Post by ZibiSound »

I'm back with 1/x issue, this time I need it for real.
I was thinking about the knowledge base examples of log and exp. I make something like this:

Code: Select all

log -1, 0
exp 0.01, 0
EXP output is multiplied by 0.01 and assuming LOG input (from pot) value of 0.01 <-> 0.99, I should get output in range of 1 <-> 0.01

Here is my test code:

Code: Select all

rdax pot0, 1
sof 0.98, 0.01
log -1, 0
exp 0.01, 0
wrax reg0, 0

rdax adcl, 1
mulx reg0
wrax dacl, 1

rdax adcr, 1
mulx reg0
wrax dacr, 1
It still doesn't work. Output signal is very week regardless of the pot position. What I'm I doing wrong? Or otherwise - how can I even use this 1/x function?
frank
Posts: 1244
Joined: Wed Oct 19, 2005 12:26 pm
Contact:

Re: 1/X function issue

Post by frank »

It is not working for the same reason it was not working above, you are exceeding the allowed range.

If you need the input to go 0.01 <-> 0.99 and the output to go 1 <-> 0.01 isn't that basically 1-input again?
Frank Thomson
Experimental Noize
ZibiSound
Posts: 66
Joined: Fri Mar 15, 2013 3:02 pm

Re: 1/X function issue

Post by ZibiSound »

Where I'm exceeding allowed range? Adding the factor of 0.01 in the exp function doesn't eliminate the clipping problem?

Overall, I need to divide ACC by pot value.
Multiplying acc by (1 - POT) gives completely different results.

Eg;
0.155 : 0.6 = 0.258
0.155 * 0.4 = 0.062
frank
Posts: 1244
Joined: Wed Oct 19, 2005 12:26 pm
Contact:

Re: 1/X function issue

Post by frank »

sebxx4 wrote: Sat May 15, 2021 10:57 pm Where I'm exceeding allowed range? Adding the factor of 0.01 in the exp function doesn't eliminate the clipping problem?
You are trying to pass a positive value to EXP, check the instruction PDF
sebxx4 wrote: Sat May 15, 2021 10:57 pm Overall, I need to divide ACC by pot value.
a/b = exp(log(a) - log(b))
Frank Thomson
Experimental Noize
ZibiSound
Posts: 66
Joined: Fri Mar 15, 2013 3:02 pm

Re: 1/X function issue

Post by ZibiSound »

Meh, maybe all this time I didn't need multiplying ACC by 1/x, but simply divide ACC by x (by pot, in my case) :? Lol, I feel stupid :lol:

Okay, so let's assume:

y = 0.005/POT

First, I should make log2(0.005) and then substract log2(pot) from it.
But, eg, first log gives me -7.64385618977 and I need to store it somewhere to clean the accumulator and then make second log. I suppose I can't just put such a large negative number to any register?
frank
Posts: 1244
Joined: Wed Oct 19, 2005 12:26 pm
Contact:

Re: 1/X function issue

Post by frank »

Read the instruction PDF.
Frank Thomson
Experimental Noize
Post Reply