so basically, if the code and my understanding is correct, if the value read by the adc(0) is max which is 255, does it mean when it being divided by 2, the output should be 128 or something.. but what i got i far more than 128. i do not understand. can anyone please help. thanks
Hi,
Your above statement should be right. >>2 means divide by 4, not divide by 2. /2 is divide by 2, so for 3, it's /3, for 4, it's /4, for 1.3456, it's /1.3456
Hi,
Your above statement should be right. >>2 means divide by 4, not divide by 2. /2 is divide by 2, so for 3, it's /3, for 4, it's /4, for 1.3456, it's /1.3456
The result is not like expected. I'm using MATLAB simulink toolbox to query instrument to get the rs232 data and seems like the matlab cannot read the number with few decimals.
At first glance on your code several bugs can be noted;
Too many endless loops ( several while (1) & For(; ),
i is not defined as a variable,
y is defined as int, but it holds floating-point value (y= 0.13725*temp_res1),
Before sending y via UART1_write, it has not converted to text, (you may use FloatToStr function),
The best way to represent number in float is using Q format, it is a fixed point format. For example Q12.4 means that you have an unsigned float using 12 bits for integer part and 4 bits for fractional. Try to use as resolution of phisican signal as power of 2 , so you can reduce amount of computation involved.