Hi all.........
some one please tell me that pic reads analog voltage and what thay give figure as answer in the source code....
explaination is here with example
adc_rd = ADC_read(0); // get ADC value from 0th channel
LCD_Out(1,1,text); // print string a on LCD, 1st row, 1st column
tlong = (long)adc_rd * 5000; // covert adc reading to milivolts
tlong = tlong / 1023; // 0..1023 -> 0-5000mV
ch = tlong / 1000; // extract volts digit
LCD_Chr(1,3,48+ch); // write ASCII digit at 1st row, 3rd column
LCD_Chr_CP('.');
this code is from a volt meter...
i want to know why adc_rd is multiplied by 5000,,, and why absolute 5000 onlyyy.
at second step.,,, why it is divided by 1023,,, and absolute 1023....
thanks for answering.....
analoge voltage reading
Re: analoge voltage reading
Result of analog voltage to 10-bit number conversion spans from 0 to 1023. If you divide it by 1023.0, you get 0..1. Multiplying this by input voltage span gives the momentary voltage at input of ADC (if the input voltage starts from 0 - otherwise one has also to subtruct the minimum voltage).sunny wrote:i want to know why adc_rd is multiplied by 5000,,, and why absolute 5000 onlyyy.
at second step.,,, why it is divided by 1023,,, and absolute 1023....
Problem is, such approach requires floating-point arithmetics which takes a lot of program memory and execution time. And one needs a complicated routine converting floating-point number to a string, if one wants to display the result on LCD.
Therefore, the best solution is to use fixed-point arithmetic, i.e. only integer multiplication and division. If the input voltage ranges from 0..5V, then multiplying the conversion result by 5000, and then dividing it by 1023, one gets a number ranging from 0 to 5000, i.e. from 0 to 5000mV, which is easy to display - also as 0.000 to 5.000 V.
There are even smarter (faster) algorithms further reducing the code size, like here.
Re: analoge voltage reading
thanks very very thanks....
now can u help me in making led moving msg using pic16f877 or pic16f628 but source code should in mikroC.... because i am using mnikroC
thanks.............
now can u help me in making led moving msg using pic16f877 or pic16f628 but source code should in mikroC.... because i am using mnikroC
thanks.............
Re: analoge voltage reading
Please post in mC PRO forum then. I'm sure somebody may direct you to posts on this subject - or you could search this, or old mC forum for yourself. I'm not an enthusiast of C so I'd rather avoid writing code in mC.
Re: analoge voltage reading
dear which language u use............
Re: analoge voltage reading
mikroPascal. mC offers little more than mP and I use assembly for critical parts anyway.
I use C or C++ only when I have to (on platforms where there is no other choice ).
I use C or C++ only when I have to (on platforms where there is no other choice ).