Hi I was wondering if you could explain whats happening in this piece of code please. I'v tried to figure it out as best as I can but still have some problems especially with the scaling_reF variable. I can't find what MainMDX.AllAnalogueInputs[accurate_index].CurrentValue; is in the source code.
digital_value = (int)(input_byte1 * 256) + (int)input_byte2;
double scaling_reF = 5.0;
if (accurate_index >= 0 && accurate_index < MainMDX.AllAnalogueInputs.Count)
scaling_reF = MainMDX.AllAnalogueInputs[accurate_index].CurrentValue;
if (scaling_reF == 0)
scaling_reF = 5.0;
double reF = ((double)digital_value / 1023.0f) * scaling_reF;
It is an old piece of code that can be fully deleted.
Basically it was for taking a value off of an analogue input, and using that for the reference voltage to do the digital to analogue conversion with instead of just blindly assuming it was 5v.
Since the voltage regulator on the brain will put out slightly less voltage when hot, it was thought of in a hurry to mabe compensate for that. However we shortly (within hours) realized we were being stupid as the reference voltage would be compared off of the same bad regulator voltage! duh... So it is still in there because... I just havent taken it out. :)
New Question then
Ok so that explains that, my next question is what are the bytes being put into the byte array by SendAndReceiveViaInterruptTransfers, and why is the low byte alyaws 0 for me.
Are they bytes from the ADC or someting else?
I am using the temperature sensor to try and figure out the meaning of the values returned to me but no joy so far.
I know that 10mv = 1 degree celsius, that 0 = -40 degrees celsius and 400 = 0 degrees celsius but in a room that is quite comfortable around 23 degrees celcius to sit in im getting 232 returned as the value which if divided by 10 is the right temperature.
it returns voltage. That's it. All analogue inputs are voltage only. If you attach a temperature sensor or photosensor, it doesnt care, it just returns the voltage.
Whatever is returned is the digital value read in. It is 10bit, and 5v reference. Hence the 5 * (value/1023) to get the raw voltage.
Then you send that through an equation to get whatever the sensor is. That is the point of the whole logic section.
Thanks that was what I was hoping for I just wanted to make sure before I made any wrong assumptions.