|
|
| Author |
Message |
| The Shaggy D.A. |
This post is not being displayed .
|
 The Shaggy D.A. Super Spammer

Joined: 12 Sep 2008 Karma :  
|
 Posted: 16:08 - 26 Sep 2009 Post subject: Calling Electronics/Maths geeks :-) |
 |
|
I have a circuit, part of which is based on a voltage divider using resistors :-
https://www.bikechatforums.com/files/voltagedivider.gif
The maths behind this is :-
Vout = Vin * R2 / (R1 + R2)
So, for example, if R1 and R2 were equal, Vout would be half of Vin. In my circuit, R1 is fixed at 1k, whilst R2 varies between 25k and 1k, in steps of 1k. With an input of 5V, this gives me the following theoretical voltages at each step :-
0 4.807692308
1 4.8
2 4.791666667
3 4.782608696
4 4.772727273
5 4.761904762
6 4.75
7 4.736842105
8 4.722222222
9 4.705882353
10 4.6875
11 4.666666667
12 4.642857143
13 4.615384615
14 4.583333333
15 4.545454545
16 4.5
17 4.444444444
18 4.375
19 4.285714286
20 4.166666667
21 4
22 3.75
23 3.333333333
24 2.5
I'm using an Analogue to Digital converter to read these values, in a C# proggy. I need to return what step number the circuit is at, from 0 to 24. If the voltage was linear, this would be simple. Alas
These values vary due to heat, contact resistance, quality of components, stability of the input voltage etc. Not by much, but enough to stop me being able to do an exact equality check. To get around this, I have a table of thresholds which I simply loop through and compare the value against. These are represented by an integer, thus :-
Value = INT(Vin / 32767 * Vout)
The ADC does this for me, I'm just including it for clarity.
These thresholds are the halfway point between each step, so that (for example) between steps 24 and 23, my threshold is 19113. If I'm lower than that, I'm at step 24. If I'm lower than 23209, I'm at step 23, and so on. Once I've obtained a step number, I can exit my loop.
Which brings me, finally, to my question.
Can anyone think of a clever formula that can remove the necessity of looping through a lookup table, to return an integer of 0 to 24 dependant on the output voltage? I get the feeling it's staring me in the face, but I never was any good at maths. ____________________ Chances are quite high you are not in my Monkeysphere, and I don't care about you. Don't take it personally.
Currently : Royal Enfield 350 Meteor
Previously : CB100N > CB250RS > XJ900F > GT550 > GPZ750R/1000RX > AJS M16 > R100RT > Bullet 500 > CB500 > LS650P > Bullet Electra X & YBR125 > Bullet 350 "Superstar" & YBR125 Custom > Royal Enfield Classic 500 Despatch Limited Edition (28 of 200) & CB Two-Fifty Nighthawk > ER5 |
|
| Back to top |
|
You must be logged in to rate posts |
|
 |
| The Shaggy D.A. |
This post is not being displayed .
|
 The Shaggy D.A. Super Spammer

Joined: 12 Sep 2008 Karma :  
|
 Posted: 16:27 - 26 Sep 2009 Post subject: |
 |
|
If it makes it easier to understand, here's a spready. ____________________ Chances are quite high you are not in my Monkeysphere, and I don't care about you. Don't take it personally.
Currently : Royal Enfield 350 Meteor
Previously : CB100N > CB250RS > XJ900F > GT550 > GPZ750R/1000RX > AJS M16 > R100RT > Bullet 500 > CB500 > LS650P > Bullet Electra X & YBR125 > Bullet 350 "Superstar" & YBR125 Custom > Royal Enfield Classic 500 Despatch Limited Edition (28 of 200) & CB Two-Fifty Nighthawk > ER5 |
|
| Back to top |
|
You must be logged in to rate posts |
|
 |
| The Shaggy D.A. |
This post is not being displayed .
|
 The Shaggy D.A. Super Spammer

Joined: 12 Sep 2008 Karma :  
|
 Posted: 16:51 - 26 Sep 2009 Post subject: |
 |
|
I've only got Vout available to the proggy, expressed as an integer between 0 and 32767. With a smoothing capacitor, the values are as near as dammit, and I can get away with dividing the result by 10 to lower the DAC's resolution, which gives me :-
24) 3150
23) 3145
22) 3140
21) 3134
20) 3127
19) 3120
18) 3112
17) 3104
16) 3094
15) 3083
14) 3071
13) 3058
12) 3042
11) 3024
10) 3003
9) 2978
8) 2949
7) 2912
6) 2867
5) 2808
4) 2730
3) 2621
2) 2457
1) 2184
0) 1638
But it's still not linear. ____________________ Chances are quite high you are not in my Monkeysphere, and I don't care about you. Don't take it personally.
Currently : Royal Enfield 350 Meteor
Previously : CB100N > CB250RS > XJ900F > GT550 > GPZ750R/1000RX > AJS M16 > R100RT > Bullet 500 > CB500 > LS650P > Bullet Electra X & YBR125 > Bullet 350 "Superstar" & YBR125 Custom > Royal Enfield Classic 500 Despatch Limited Edition (28 of 200) & CB Two-Fifty Nighthawk > ER5 |
|
| Back to top |
|
You must be logged in to rate posts |
|
 |
| The Shaggy D.A. |
This post is not being displayed .
|
 The Shaggy D.A. Super Spammer

Joined: 12 Sep 2008 Karma :  
|
 Posted: 17:08 - 26 Sep 2009 Post subject: |
 |
|
Well bugger me with a slide rule. It seems that typing all this out focused me enough
If Vout is the DAC reading and Vin is 32767, then
Step = ((Vout * R1 / (Vin - Vout)) / 1000) - 1
As you were  ____________________ Chances are quite high you are not in my Monkeysphere, and I don't care about you. Don't take it personally.
Currently : Royal Enfield 350 Meteor
Previously : CB100N > CB250RS > XJ900F > GT550 > GPZ750R/1000RX > AJS M16 > R100RT > Bullet 500 > CB500 > LS650P > Bullet Electra X & YBR125 > Bullet 350 "Superstar" & YBR125 Custom > Royal Enfield Classic 500 Despatch Limited Edition (28 of 200) & CB Two-Fifty Nighthawk > ER5 |
|
| Back to top |
|
You must be logged in to rate posts |
|
 |
| carvell |
This post is not being displayed .
|
 carvell Scuttler

Joined: 05 Sep 2003 Karma :  
|
|
| Back to top |
|
You must be logged in to rate posts |
|
 |
| The Shaggy D.A. |
This post is not being displayed .
|
 The Shaggy D.A. Super Spammer

Joined: 12 Sep 2008 Karma :  
|
 Posted: 17:37 - 26 Sep 2009 Post subject: |
 |
|
I'd hate to try and debug that in a couple of year's time though  ____________________ Chances are quite high you are not in my Monkeysphere, and I don't care about you. Don't take it personally.
Currently : Royal Enfield 350 Meteor
Previously : CB100N > CB250RS > XJ900F > GT550 > GPZ750R/1000RX > AJS M16 > R100RT > Bullet 500 > CB500 > LS650P > Bullet Electra X & YBR125 > Bullet 350 "Superstar" & YBR125 Custom > Royal Enfield Classic 500 Despatch Limited Edition (28 of 200) & CB Two-Fifty Nighthawk > ER5 |
|
| Back to top |
|
You must be logged in to rate posts |
|
 |
| Banned |
This post is not being displayed because the poster has bad karma. Unhide this post / all posts.
|
 Banned World Chat Champion

Joined: 29 Jun 2009 Karma :    
|
 Posted: 17:52 - 26 Sep 2009 Post subject: |
 |
|
Live footy is on  |
|
| Back to top |
|
You must be logged in to rate posts |
|
 |
| The Shaggy D.A. |
This post is not being displayed .
|
 The Shaggy D.A. Super Spammer

Joined: 12 Sep 2008 Karma :  
|
 Posted: 18:02 - 26 Sep 2009 Post subject: |
 |
|
Well, we wouldn't want you to tax yourself. ____________________ Chances are quite high you are not in my Monkeysphere, and I don't care about you. Don't take it personally.
Currently : Royal Enfield 350 Meteor
Previously : CB100N > CB250RS > XJ900F > GT550 > GPZ750R/1000RX > AJS M16 > R100RT > Bullet 500 > CB500 > LS650P > Bullet Electra X & YBR125 > Bullet 350 "Superstar" & YBR125 Custom > Royal Enfield Classic 500 Despatch Limited Edition (28 of 200) & CB Two-Fifty Nighthawk > ER5 |
|
| Back to top |
|
You must be logged in to rate posts |
|
 |
| Fnatic |
This post is not being displayed .
|
 Fnatic World Chat Champion

Joined: 11 May 2008 Karma :  
|
|
| Back to top |
|
You must be logged in to rate posts |
|
 |
Old Thread Alert!
The last post was made 16 years, 352 days ago. Instead of replying here, would creating a new thread be more useful? |
 |
|
|