Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Newbie math question

Status
Not open for further replies.

lb50398

New Member
I am working on am automotive project that adapts a sensor with with a fairly linear signal to work on a system that normally accepts a very non-linear signal.
I have algebraically worked out a formula that will correct the signal; Vout=3091.99(Vin/.0383)^-1.798. However this is for a decimal input. I will be using, unless something better is recommended, a 10 bit A/D converter with a 5 volt reference and matching it with a 10 bit D/A converter also with a 5 volt reference, so each step is approx .0048 volts. I am just starting in this so I am having trouble wrapping my head around this. I need to read the A/D converter and run it threw the formula, then spit the answer back out a D/A converter. But I can't figure out how to program the formula in a way that will work in the PIC. Any help will be greatly appreciated. I was planning on using a 16f**, but like I said if y'all know better please tell me.

P.S. wish there was a beating head on wall smiley
 
The simplest way to do this is to have a table that contains 1024 entries that correspond to the output signal required. If you use a 16F88 then you could use the last 1024 words of program memory to hold the table.

How experienced are you at writing code and what language do you intend using?

Mike.
 
Good advice. I doubt if you could get the floating point library to fit in 1024 words of program memory anyway.
 
I also have an excel sheet that will produce the table for you.

Mike.
 
I'm fairly advanced on basic on a PC, I know how to control serial and parallel ports. I plan on using basic. Pommie can you explain how to do that also what would be needed for floating point math? Thanks.
 
On a 16F88 you have 4096 words of program memory. In the last 1024 words you store the calculated value to output that corresponds to the input value. So in location 0 you would store the value to send to the DAC when the input is zero (1023 in this case). The last value would be the value to output when the input is 1023 (5V) and would contain 99 (0.485V).

I have an excel sheet that I used to do exactly this a while ago. I have put in your formula but it overflows on the first few values. I'll attach it.

Mike.
P.S. I had to zip it - xls files aren't allowed!!
 

Attachments

  • MakeTable.zip
    61.1 KB · Views: 96
You could have a look-up table for some of the values, and interpolate between those values.

It is easiest if you have 2^n+1 items in your lookup table, so you use n bits for the look-up index and the rest for the interpolate.

does that for log values, but you only have to change the look-up table.

It is easier with PICs that have multiply as that makes the interpolate easier / quicker.

I used this for a lookup of the arctangent in the 0 - 45 degree range. To get within 1 degree everywhere, I only needed 5 items in a lookup table.
 
You could have a look-up table for some of the values, and interpolate between those values.

It is easiest if you have 2^n+1 items in your lookup table, so you use n bits for the look-up index and the rest for the interpolate.

That's all very reasonable with a large table, but this table is only 1024 entries (or 2048 to simply give ten bits), so easily fits within the PIC's available space - so no need to interpolate.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top