|
|
View previous topic :: View next topic |
Author |
Message |
Maxs conde
Joined: 01 Oct 2020 Posts: 1 Location: Peru
|
How to calculate the ADC value ? |
Posted: Thu Oct 01, 2020 9:13 am |
|
|
"You want to design a digital thermometer, for which you must use a PIC18F4550, a 2-line LCD and a 10KΩ thermistor. The circuit must give a welcome message for 1s, then present the student's data for 2s".
THIS PART ALREADY DONE IT.
"Then it will present the temperature value in °C, for the conversion.
Consider that the temperature is proportional to the voltage generated by the thermistor, that is, for 0V you have 0 °C and for 5V you have 100 °C."
HOW CAN I CALCULATE THIS PART OF 0 - 100 °C WITH 0 - 5v ?
Code: |
#include <18F4550.h>
#device adc=10 // Define the number of bits of the converter
// This is used when using an A/D converter
#fuses XT, WDT, NOPROTECT, NOPUT, NOPBADEN // fuse configuration
#use delay (clock=4000000) // Fosc = 4 MHz
#include <lcd.c> // lcd library
// FOR YOU TO RECOGNIZE THE COMMANDS BELOW
void main()
{
float valor, valor_conversion; // value and conversion_value are variables that I can modify for example by voltage
setup_adc_ports(AN0); // We tell it to use port 0
setup_adc(ADC_CLOCK_INTERNAL); // we told it to use the internal clock
set_adc_channel(0); // select analog channel 0
// we are putting channel 0
lcd_init(); // we are saying with this command that the LCD is activated
lcd_putc("\f BIENVENIDO \n"); // command or sentence that will allow us to display on the screen at startup
delay_ms(1000); // Delete the message in the requested time
lcd_putc("\f"); // Clear screen
// Wait 1 second while the screen is cleared.
lcd_putc("\f ESTUDIANTE GQT\n"); // Here can go the name
lcd_putc(" Max's Conde");
delay_ms(2000); // Delete the message in the requested time
lcd_putc("\f"); // Clear screen
// Wait 2 seconds while the screen is cleared.
while(true){
valor = read_adc(); // Reads the analog value and assigns it to the 16-bit variable
valor_conversion = valor*5/1023; // Formula for equivalent voltage value
lcd_gotoxy(4,1); // Cursor goes to column 1 row 2 as the LCD is 2 lines
printf(lcd_putc,"TEMPERATURA ",); // print a message
lcd_gotoxy(4,2); // Cursor goes to column 1 row 2 as the LCD is 2 lines
printf(lcd_putc,"%6.1f C ", valor_conversion); // To put its equivalent in voltage of what the cursor reads: ADC
}
|
_________________ Quiero ser apoyado en algunas consultas sobre mis practicas en la universidad |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19195
|
|
Posted: Thu Oct 01, 2020 10:19 am |
|
|
0v = adc value of 0.
5v = (theoretical) value of 1024.
The ADC cannot actually read '5v', is gives it's maximum of 1023, just on
5mV below this input.
So for 0 to 100, multiply by 0.0976.
1024 counts * 0.0976 = 100.
In fact though for the likely accuracy of the sensor, just *.1 or /10. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9081 Location: Greensville,Ontario
|
|
Posted: Fri Oct 02, 2020 2:32 pm |
|
|
re: Quote: | In fact though for the likely accuracy of the sensor, just *.1 or /10.
|
YES ! Especially since unless you design the PCB for 10 bit ADC, 'noise' alone will negate 2-2 bits of data. Getting reliable, repeatable ADC readings over 8 bits is quite a challenge ! Noise comes from the PSU, airborne, wiring, wrong caps (or missing), power surges (turn an LED on or off...), EMI, etc...... |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19195
|
|
Posted: Sat Oct 03, 2020 12:08 am |
|
|
Yes. There is also more, since I cannot think of a basic thermocouple
circuit that will actually give 0 to 5v for 0 to 100C, without a huge amount of
analog signal processing.... |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|