Logarithmic increment.

Hi,

I'm working on a project that controls a digital volume control chip (Ti PGA2311). It's all working fine, but I'd like to implement a logarithmic volume scale instead of a linear one.

The PGA2311 has a range of -96dB to +31.5dB in 0.5dB steps. This is controlled by sending values between 0 and 255. I don't actually want to go much above 0dB which is a value of 192. I also don't specifically need to get all the way to zero (-96dB). Zero is mute, and the very low numbers are well below audible, so there is a bit of flexibility in the range.

I only have 63 available increments to go from 0 to 192. I'm currently incrementing by 3 for each of the 63 volume steps. Could one of you kind souls possibly advise how to increment in a more logarithmic fashion ?

I appreciate that it won't be 100% logarithmic, but I can only send whole numbers to the chip, so floats would need to be rounded up/down.

Thanks,

Ian.

could you just use an array?

Could one of you kind souls possibly advise how to increment in a more logarithmic fashion ?

Give an example. I assume you know how to convert dB to Gain .
127 dB corresponds to a voltage gain of 2238721.
2238721 /255= 8779 per step
8779 x 192 steps = a voltage overall gain(or range) of 1685625.
How do you propose to implement a log scale ?
Can you give an example ?

There are two c maths functions you and use

log() and exp(). Both take a double and return a double.

I suspect you will need to use log()

So your overall conversion function will need to look like

Output = outputOffset + outputScale * log ((input + input offset) * inputScale)

You will need to work out the offset and scale values yourself, bear in mind the offsets can be negative or positive, as can the input and output scale values, and the scale values can act as division if you use values between zero and one e.g. 0.5

I'm sure there is a clever maths way to determine the value you need for scale and constants, possibly involving four simultaneous equations, but its often simpler just to put the equation into a program like excel and tweak the values until you get the results you want, and then you can put the values into your program.
Note however if you use excel, which log it uses e.g. Log in c is natural log, and in excel it may be log10

not sure which end is up, but at one end, you need to increment by 5 or so, and at the other by 1

the problem is that yo need to increment by 1 for the first 40 places, then start to increase that so that at the list of the 63 steps, you increment by 5.

hardly worth the effort with the existing 10 bit PWM output.

probably need to either bit bang an output, or get a higher resolution D/A chip.

ian332isport:
I only have 63 available increments to go from 0 to 192. I'm currently incrementing by 3 for each of the 63 volume steps. Could one of you kind souls possibly advise how to increment in a more logarithmic fashion ?

But the chip already has an exponential response to the numbers, you just
send 3xN and it will just work. That's what 0.5dB/step means.

You may find if you don't use the part of the range with gain > 1 then the S/N
ratio may be worse, BTW.

MarkT:

ian332isport:
I only have 63 available increments to go from 0 to 192. I'm currently incrementing by 3 for each of the 63 volume steps. Could one of you kind souls possibly advise how to increment in a more logarithmic fashion ?

But the chip already has an exponential response to the numbers, you just
send 3xN and it will just work. That's what 0.5dB/step means.

You may find if you don't use the part of the range with gain > 1 then the S/N
ratio may be worse, BTW.

I did not follow this. if there are limited number of pwm steps, how can you get multiple settings in-between ?

not sure what I am missing.

MarkT:
But the chip already has an exponential response to the numbers, you just
send 3xN and it will just work. That's what 0.5dB/step means.

Now I've re-read the datasheet it appears this is the case. I think I just need to stop using the bottom of the range. as it's well below what's audible. From reading further, it sounds like -60dB upwards is considered adequate for most applications. I also need to look at the amplifier gain as I think the sensitivity is a little low. I'll get a scope on it and see when the signal starts to clip.

dave-in-nj:
If there are limited number of pwm steps, how can you get multiple settings in-between ?

not sure what I am missing.

Where are you getting PWM from ?

Ian.

The PGA2311 has a range of -96dB to +31.5dB in 0.5dB steps. This is controlled by sending values between 0 and 255.

@Dave,
The 0 to 255 he referred to is not an analogWrite value but a control byte value for the PGA2311. (FYI)