Hi there, i'm back with a new problem. This should be a lot easier to get resolved as it's got little to do with programming, and more to do with solving a problem.
I want the best approach, in other words.
Right, an introduction, I'm designing an lcd-based boost gauge for my car, which will tap into a 2.5 bar map sensor that also feeds the ecu (do have a seperate sensor of the same type if needs for a seperate sensor be)
I'm using this as a learning exercise, and it's designed to run from a 16f872, as having the three ports help me organise LCD i/o, LCD control and analogue inout (c,b and a respectively). I suppose I could share pins from the same port for multiple purposes by setting the bits individually but i'm not sure i've the confidence to manage this through code effectively yet.
Anyway, I've got things pretty much setup as far as I/O goes, I can read 0-5v in through the adc on the pic, which gives me an 8 bit conversion which I'm happy with (a binary 51 per volt applied), and I have setup routines that can be called to fire individual characters to the LCD, this also works well and I've got a lot of the hard work done.
At the moment though, I'm just a bit lost as to how to tackle taking the result from the adc and calling the correct subroutine to give the right reading on the LCD. I only want it to increment in psi, which is quite a large range of voltage between, so I have made a list of the adc result equivelents for a set psi, which is fine, but I'm still unsure how to proceed.
Let's say I want the lcd to report:
adc result: 12 psi:1
adc result: 24 psi:2
adc result: 36 psi:3
adc result: 48 psi:4
adc result: 60 psi:5
Obviously I'd want to find the closest value the adc output is to, so if I read the adc delivering 13, I'd want to register 1psi.
In all fairness I am happy to round UP in all cases, as it's safer with a tuned engine like mine to assume boost is higher rather than lower, but anyway..
any tips on the best logical approach to working these numbers? I thought of using lookup tables but they don't seem to offer much flexibility for rounding.
cheers
Kris
I want the best approach, in other words.
Right, an introduction, I'm designing an lcd-based boost gauge for my car, which will tap into a 2.5 bar map sensor that also feeds the ecu (do have a seperate sensor of the same type if needs for a seperate sensor be)
I'm using this as a learning exercise, and it's designed to run from a 16f872, as having the three ports help me organise LCD i/o, LCD control and analogue inout (c,b and a respectively). I suppose I could share pins from the same port for multiple purposes by setting the bits individually but i'm not sure i've the confidence to manage this through code effectively yet.
Anyway, I've got things pretty much setup as far as I/O goes, I can read 0-5v in through the adc on the pic, which gives me an 8 bit conversion which I'm happy with (a binary 51 per volt applied), and I have setup routines that can be called to fire individual characters to the LCD, this also works well and I've got a lot of the hard work done.
At the moment though, I'm just a bit lost as to how to tackle taking the result from the adc and calling the correct subroutine to give the right reading on the LCD. I only want it to increment in psi, which is quite a large range of voltage between, so I have made a list of the adc result equivelents for a set psi, which is fine, but I'm still unsure how to proceed.
Let's say I want the lcd to report:
adc result: 12 psi:1
adc result: 24 psi:2
adc result: 36 psi:3
adc result: 48 psi:4
adc result: 60 psi:5
Obviously I'd want to find the closest value the adc output is to, so if I read the adc delivering 13, I'd want to register 1psi.
In all fairness I am happy to round UP in all cases, as it's safer with a tuned engine like mine to assume boost is higher rather than lower, but anyway..
any tips on the best logical approach to working these numbers? I thought of using lookup tables but they don't seem to offer much flexibility for rounding.
cheers
Kris