Sonsivri
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
December 08, 2016, 11:01:28 23:01


Login with username, password and session length


Pages: [1]
Print
Author Topic: Linear to Logarithmic  (Read 2583 times)
0 Members and 1 Guest are viewing this topic.
metal
Global Moderator
Hero Member
*****
Offline Offline

Posts: 2018

Thank You
-Given: 514
-Receive: 477


Top Topic Starter


« on: April 17, 2010, 06:18:57 06:18 »

I have values ranging from 0 to 255. If I step thru them incrementing by 1, then this is a linear increment: 1 2 3 4 5 6 7 8....253 254 255 I am looking for a way to correctly calculate a lookup table that has values incrementing in a logarithmic manner: 3 5 6 9 11 14 17 18 19.... More, I am looking for the code that can generate the these values in real time instead of storing it in a table.

Application: Turning Linear digital pot into logarithmic.
Logged

nothing to say..
sphinx
Hero Member
*****
Offline Offline

Posts: 504

Thank You
-Given: 232
-Receive: 124



« Reply #1 on: April 17, 2010, 07:14:53 07:14 »

could this i found be of any help

http://www.dattalo.com/technical/software/pic/piclog.html

regards
Logged

the more you learn, the lesser you get to understand. is it then good know alot but not understand what you know or.......
hate
Hero Member
*****
Offline Offline

Posts: 556

Thank You
-Given: 156
-Receive: 354


« Reply #2 on: April 17, 2010, 10:40:22 10:40 »


If u'll use adc on the output, there is a way to turn a linear pot into a logarithmic 1 by using an extra resistor. But it slightly changes the pot values. I can't think of a reason it wouldn't work with a digital pot. Link below:

http://www.geofex.com/Article_Folders/potsecrets/potscret.htm

Regards...
Logged

Regards...
metal
Global Moderator
Hero Member
*****
Offline Offline

Posts: 2018

Thank You
-Given: 514
-Receive: 477


Top Topic Starter


« Reply #3 on: April 17, 2010, 02:11:36 14:11 »

I am running experiments on PGA2311 and ATmega16.

I connected ZCEN to Vcc. Then I played some tracks, ranging from speech, trance, classic, and heavy metal. I had to low/up the volume to see if there audible clicks while changing the volume, I did not hear any, I was impressed, but not convinced. I got a function generator that I sat to 1KHz, I injected that tone and started lowering and raising the volume to see, and guess what?

I HEARD THE CLICKS. They were awful, and so much audible Grin

Now what I want to try is to make the increments in logarithmic style rather than incrementing by 2 (1 dB steps).

I wish I was not sleepy to explain all that in the first post, but I was so much tired and it was sunrise after a long night of experimenting for me.

Here is the code I wrote for PGA2311 data put function:

Code:
void PGA_put(uint16_t PGA_data)
{
    uint8_t cnt;

    PGA_PORT &= ~(1 << PGA_CS); //Clear CS

    for(cnt = 0; cnt < 16; cnt++)
    {
        PGA_PORT &= ~(1 << PGA_SCLK); //Clear SCLK

        if((PGA_data << cnt) & 0x8000)
        {
            //Don't set SDI unless it's cleared
            //This means don't set an already set
            //pin, this is a waste of time
            if(bit_is_clear(PGA_PIN, PGA_SDI))
            {
                PGA_PORT |= 1 << PGA_SDI; // Set SDI
            }
        }
        else
        {
            //Don't clear SDI unless it's set
            //This means don't clear an already
            //cleared pin, this is a waste of time
            if(bit_is_set(PGA_PIN, PGA_SDI))
            {
                PGA_PORT &= ~(1 << PGA_SDI); // Clear SDI
            }
        }

        //_delay_us(1);
        PGA_PORT |= (1 << PGA_SCLK); //Set SCLK
        //_delay_us(1);
    }

    PGA_PORT &= ~(1 << PGA_SCLK); //Clear SCLK
    PGA_PORT &= ~(1 << PGA_SDI); //Clear SDI
    PGA_PORT |= (1 << PGA_CS); //Set CS
}

ATmega16 is running at 16MHz, and I commented the couple of delays. As a matter of fact, when I uncommented them in the case of 1KHz test signal, things became so much worse. I noticed that sending the data this fast was a plus, and thanks to PGA2311 that it can handle reading the data sent at this high speed.
« Last Edit: April 17, 2010, 02:20:16 14:20 by metal » Logged

nothing to say..
hate
Hero Member
*****
Offline Offline

Posts: 556

Thank You
-Given: 156
-Receive: 354


« Reply #4 on: April 17, 2010, 02:38:01 14:38 »

Then I guess u need to implement it in software. A quick idea maybe normalizing ur output on log scale. Assuming u have 255 output levels, log(255)~=2.4 and log(1)=0. If u use -+.1 steps that gives u 25 steps for output swing. Assuming x is the variable for input 0<=x<=2.4 in -+.1 steps, output becomes y=10^x within a range of 1<=y<=255 roughly and in logarithmic scale. Then u can use whether the log functions if supported by the compiler or calculate a lookup for ur 25 values and use it. That's just an idea, I didn't try it. Wink

Regards...
Logged

Regards...
metal
Global Moderator
Hero Member
*****
Offline Offline

Posts: 2018

Thank You
-Given: 514
-Receive: 477


Top Topic Starter


« Reply #5 on: April 17, 2010, 05:53:00 17:53 »

These are the results of the calculations you suggested:

Code:
 
0 1
0.1 1.258925412
0.2 1.584893192
0.3 1.995262315
0.4 2.511886432
0.5 3.16227766
0.6 3.981071706
0.7 5.011872336
0.8 6.309573445
0.9 7.943282347
  1 10
1.1 12.58925412
1.2 15.84893192
1.3 19.95262315
1.4 25.11886432
1.5 31.6227766
1.6 39.81071706
1.7 50.11872336
1.8 63.09573445
1.9 79.43282347
  2 100
2.1 125.8925412
2.2 158.4893192
2.3 199.5262315
2.4 251.1886432

Valid values should be integers only, so it becomes like this:

Code:
 
0 1
0.1 1
0.2 2
0.3 2
0.4 3
0.5 3
0.6 4
0.7 5
0.8 6
0.9 8
  1 10
1.1 13
1.2 16
1.3 20
1.4 25
1.5 32
1.6 40
1.7 50
1.8 63
1.9 79
  2 100
2.1 126
2.2 158
2.3 200
2.4 251

I don't know, I have to try it and see what I get. 25 steps seems reasonable, we will see.

Logged

nothing to say..
hate
Hero Member
*****
Offline Offline

Posts: 556

Thank You
-Given: 156
-Receive: 354


« Reply #6 on: April 17, 2010, 06:54:08 18:54 »

Well looking through the calculations u made first 6 values doesn't much resemble a logarithmic behaviour but the rest seems fine. It's quite obvious a wider output range is needed for a better log behaviour at values near 0. Please post the results.

Regards...
Logged

Regards...
metal
Global Moderator
Hero Member
*****
Offline Offline

Posts: 2018

Thank You
-Given: 514
-Receive: 477


Top Topic Starter


« Reply #7 on: April 17, 2010, 08:33:52 20:33 »

man... I applied those values, it is no good at all. I need wider range. Problem is that difference between numbers at the high end is too large.

We need something like this one:

0 3 5 6 9 11 14 17 18 19 20 23 24 25 26 28 30 31 33 34 35 39 40 42 44 48 49 60 62 63 65 69 70 71 72 73 75 76 78 79 82 84 86 87 88 89 90 91 95 100 101 104 105 109 110 112 113 118 119 121 122 123 126 129 132 134 135 136 138 142 143 144 147 149 150 152 153 155 157 160 164 165 166 167 169 170 172 173 178 180 183 184 185 186 190 191 192 193 196 200 201 206 207 208 214 215 218 220 221 222 226 227 229 230 231 233 234 235 238 240 241 244 245 246 248 251 253 254 255

Look at this http://www.samiam.org/galois.html I have not read it yet, but seems there are interesting things there Smiley
Logged

nothing to say..
hate
Hero Member
*****
Offline Offline

Posts: 556

Thank You
-Given: 156
-Receive: 354


« Reply #8 on: April 18, 2010, 11:51:39 11:51 »

man... I applied those values, it is no good at all. I need wider range. Problem is that difference between numbers at the high end is too large.

That should be the logarithmic behaviour, I don't understand what the problem is here. What are u using as an output, maybe it is a logarithmic amplifier so it needs linear input? If that's the case feeding a logarithmic signal into a logarithmic amplifier may result in erratic behaviour.

Regards...
Logged

Regards...
metal
Global Moderator
Hero Member
*****
Offline Offline

Posts: 2018

Thank You
-Given: 514
-Receive: 477


Top Topic Starter


« Reply #9 on: April 18, 2010, 01:09:21 13:09 »

I did not say it is not logarithmic. For a range of 0~255 with 10 steps, it is not appropriate at all to be 10 steps. Need a wider range in order to have better control on volume level. I am working on and have to try it first with a wider range.
Logged

nothing to say..
an007
Active Member
***
Offline Offline

Posts: 111

Thank You
-Given: 53
-Receive: 51


« Reply #10 on: April 18, 2010, 08:39:50 20:39 »

I did not undersantd the relation between log scale and clicks.
Anyway PGA2311 has inside a Zero Crossing Detection circuit; this means switching is done only when the input signal pass 0 which means no clicks. (Connection of ZCEN to Vcc should be ok).

Please check if your input signal pass 0 (and has a DC component). If the input signal has a DC component, place at each input a capacitor for DC isolation.

Hope this helps,
-an
Logged
metal
Global Moderator
Hero Member
*****
Offline Offline

Posts: 2018

Thank You
-Given: 514
-Receive: 477


Top Topic Starter


« Reply #11 on: April 19, 2010, 12:12:48 00:12 »

The problem was not about relation between clicks and making PGA2311 behave in a log way. When running music, there are no clicks audible, at all. As a test, I wanted to hear those clicks, so I applied a sine wave of 1KHz, and I heard them at the high end, putting caps at input changed nothing, this is an artifact, this has nothing to do with log.

I was thinking about making PGA2311 behave like a normal log POT, that's why I asked about how to make it increment in a log way. I was thinking about some nice way today, and it came to me that from 0 to 255, I can divide this range into 8 groups. First group is incremented by 1, second group is incremented by 2,etc.. For example, this can be done this way:

Code:
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
21
23
25
27
29
31
33
35
37
39
41
43
45
47
49
51
53
55
57
59
62
65
68
71
74
77
80
83
86
89
92
95
98
101
104
107
110
113
116
119
123
127
131
135
139
143
147
151
155
159
163
167
171
175
179
183
187
191
195
199
204
209
214
219
224
229
234
239
244
249
254

This will plot like shown in the attachment. I think 91 steps is good and fair enough here, compared to 10 steps. I have not tried it yet, I have to see how this one performs first. I was looking at this graph, and it came to me if I can imitate something like this for my project, it would be nice if I find it ok while changing the volume this way.
« Last Edit: April 19, 2010, 12:19:55 00:19 by metal » Logged

nothing to say..
metal
Global Moderator
Hero Member
*****
Offline Offline

Posts: 2018

Thank You
-Given: 514
-Receive: 477


Top Topic Starter


« Reply #12 on: April 19, 2010, 01:12:51 01:12 »

Okay, I tried it. It is the one Smiley Range is just OK. Increments are much better this way, and they are not aggressive as with the 10 steps solution.
Logged

nothing to say..
Pages: [1]
Print
Jump to:  


DISCLAIMER
WE DONT HOST ANY ILLEGAL FILES ON THE SERVER
USE CONTACT US TO REPORT ILLEGAL FILES
ADMINISTRATORS CANNOT BE HELD RESPONSIBLE FOR USERS POSTS AND LINKS

... Copyright 2003-2999 Sonsivri.to ...
Powered by SMF 1.1.18 | SMF © 2006-2009, Simple Machines LLC | HarzeM Dilber MC