Last edited by Acetronics2; - 27th December 2008 at 20:08.
************************************************** ***********************
Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
************************************************** ***********************
IF there is the word "Problem" in your question ...
certainly the answer is " RTFM " or " RTFDataSheet " !!!
*****************************************
I think you guys have it backwards.
You're turning a 0 into 165, he wants 165 to be 0.
And it should be adjustable according to each devices calibration numbers. Constants in the formula can't do that.
Here's a simple Y=mX + b type slope intercept.
It's limited to byte values and Positive slopes, but it should do the job.Which gives these resultsCode:DEFINE HSER_BAUD 9600 'Hser baud rate DEFINE HSER_CLROERR 1 'Hser clear overflow automatically DEFINE HSER_RCSTA 90h 'Hser receive status init DEFINE HSER_TXSTA 24h 'Hser transmit status init Value VAR BYTE Result VAR BYTE TempB VAR BYTE CAL_Low CON 165 ; These are the measurements from calibration CAL_High CON 245 Result_Low CON 0 ; These are what the final range should be Result_High CON 254 FOR Value = CAL_Low to CAL_High GOSUB Scale HSEROUT [DEC Value," = ",DEC Result,13,10] NEXT Value STOP Scale: TempB = (Value MAX CAL_Low) MIN CAL_High ; Limit Value to CAL range Result = ((TempB-CAL_Low)*(Result_High-Result_Low))/(CAL_High-CAL_Low) RETURNCode:Value = Result 165 = 0 166 = 3 167 = 6 168 = 9 169 = 12 170 = 15 171 = 19 172 = 22 173 = 25 174 = 28 175 = 31 176 = 34 177 = 38 178 = 41 179 = 44 180 = 47 181 = 50 182 = 53 183 = 57 184 = 60 185 = 63 186 = 66 187 = 69 188 = 73 189 = 76 190 = 79 191 = 82 192 = 85 193 = 88 194 = 92 195 = 95 196 = 98 197 = 101 198 = 104 199 = 107 200 = 111 201 = 114 202 = 117 203 = 120 204 = 123 205 = 127 206 = 130 207 = 133 208 = 136 209 = 139 210 = 142 211 = 146 212 = 149 213 = 152 214 = 155 215 = 158 216 = 161 217 = 165 218 = 168 219 = 171 220 = 174 221 = 177 222 = 180 223 = 184 224 = 187 225 = 190 226 = 193 227 = 196 228 = 200 229 = 203 230 = 206 231 = 209 232 = 212 233 = 215 234 = 219 235 = 222 236 = 225 237 = 228 238 = 231 239 = 234 240 = 238 241 = 241 242 = 244 243 = 247 244 = 250 245 = 254
DT
Oh craps, everyone's beaten me to it... my offering...
OutputByte=(InputByte-165)*318/100
This is calculated from...
245-165=80 (the original span)
254/80=3.175 (new span divided by old span)
3.175 is rounded up to 3.18 and then we multiply it by 100 so as to keep everything an integer (which is why we finally do a divide by 100 to bring us back to reality).
You may want to preceed the formula with...
If InputByte<165 then InputByte=165
If InputByte>245 then InputByte=245
OMG Darrel... How much have you had to drink to think of that one?
I guess that this was more complicated than I first guessed
..Currently I'm building a better test-rig so I can do some serious testing, right now I guess I just put a LCD in it and display the values.
The 165 and 245 was just typical values, I guess that the low value can be around 135-170 and the high one maybe 235-254. Maybe the span can be even larger.
The idea is to have a calibrating sequence first when the pic is started, where I determine the max and min value for this time, and then use this until the next start, where its calibrated again.'
Darrels solution was very neat btw![]()
Last edited by Glenn; - 27th December 2008 at 23:01.
Ha! Apparently not enough Eggnog yet. It worked on the first compile.
Of course, I did an Ugly spreadsheet for the math first.
<br>
DT
Bookmarks