Thread: temperature sensors

  1. #16
    Registered User
    Join Date
    Jul 2007
    Posts
    26
    Code:
    unsigned int read_adc(unsigned char adc_input){
      ADMUX=adc_input|ADC_VREF_TYPE; //Set channel for input
      ADCSRA=( (1<<ADEN) | (1<<ADSC) | (1<<ADIE) | (1<<ADPS1) | (1<<ADPS2) 
    );//start conversion
      while(!(ADCSRA & 0x10)); //Wait for conversion to complete
      ADCSRA|=0x10;
      return ADCW;
    }
    Salem this is something i found at the website you gave me. This is the conversion part right?

  2. #17
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Looks promising.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #18
    Registered User
    Join Date
    Jul 2007
    Posts
    26
    Salem > so sorry to bother you always, but I've been hearing alot of the Vref thingy. But i don't really understand what is it about.

    They gave me an example.

    Supposing, at a temperature of 30 deg C, it gives an output of 3V (this is just an example, check the datasheet of LM35 for exact figures). You have set a Vref+ at 5V and Vref- at 0V. Then if you do the AD conversion correctly, your ADC will read:


    3 volt
    -------- x 0x3FF ~= 0x265
    5 volt


    I'm somewhere there, but not fully.

    Thanks in advance, greatly appreiciated.

  4. #19
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    It's just simple linear interpolation
    0V is read by the ADC as 0x000
    5V is read by the ADC as 0x3FF

    You then need another set of interpolation limits (assuming the relationship is linear), which turns say 3V into 30&#176;C
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #20
    Registered User
    Join Date
    Jul 2007
    Posts
    26
    woah, hmm it's getting weird.

    What i heard from my friend is Vref is generated using a potentiometer. Using that you can "substitude" it for the sensor.

    How do you determine that 3V is 30 celsius?. Or do i assume a imaginary figure and work from there on?.

  6. #21
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    > How do you determine that 3V is 30 celsius?.
    I thought you knew that already, with "check the datasheet of LM35 for exact figures".

    We really need a circuit diagram of some sort to visualise how all these Vref's relate to one another.

    A potentiometer is good, since you can just turn it to generate varying input at the ADC, and from that generate a changing display.

    For the moment, just try displaying the hex value of the ADC result on your LCD, then worry about all the conversions later.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  7. #22
    Registered User
    Join Date
    Jul 2007
    Posts
    26
    i think i got alot of reading to do.

    thanks Salem, i'll do whatever i can before i comeback here agaiin.

    the code i pasted youi before, some other forummers said it was for another PIC18 controller.

    thanks

  8. #23
    Registered User
    Join Date
    Jul 2007
    Posts
    26
    I've been reading alot this few days, but suddenly something struck me.

    >For the moment, just try displaying the hex value of the ADC result on your LCD, then worry about all the conversions later.
    If I plugged the sensor into the ADC port, it will display the hex values on the LCD? I mean after programming.

    I don't know whether the sensor is working or not lol. Cause it's like no where to show even hex values.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Temperature Conversion code problems
    By eroth88 in forum C Programming
    Replies: 6
    Last Post: 10-22-2006, 01:24 AM
  2. Motherboard Temperature
    By MK4554 in forum Windows Programming
    Replies: 1
    Last Post: 07-18-2006, 10:51 AM
  3. Temperature conversion...
    By Onslaught in forum C Programming
    Replies: 3
    Last Post: 10-21-2005, 01:15 PM
  4. different types of sensors
    By Shadow12345 in forum C++ Programming
    Replies: 3
    Last Post: 07-24-2002, 05:46 PM
  5. functions ??? help
    By Unregistered in forum C++ Programming
    Replies: 2
    Last Post: 10-17-2001, 02:33 AM