CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

10-bit ADC on pic 18F4550
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Maxs conde



Joined: 01 Oct 2020
Posts: 1
Location: Peru

View user's profile Send private message

How to calculate the ADC value ?
PostPosted: Thu Oct 01, 2020 9:13 am     Reply with quote

"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

View user's profile Send private message

PostPosted: Thu Oct 01, 2020 10:19 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Oct 02, 2020 2:32 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Oct 03, 2020 12:08 am     Reply with quote

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.... Sad
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
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