+ Post New Thread
Results 1 to 7 of 7
  1. #1
    Member level 2
    Points: 1,509, Level: 8

    Join Date
    Feb 2006
    Posts
    44
    Helped
    0 / 0
    Points
    1,509
    Level
    8

    How to write a formula for PIC16F in C to measure a sensor reading?

    how to write a formula to measure a sensor reading? for an example i want to measure temperature using LM35DZ ...newbie

    •   AltAdvertisment

        
       

  2. #2
    Advanced Member level 5
    Points: 14,575, Level: 29
    blueroomelectronics's Avatar
    Join Date
    Sep 2006
    Location
    Toronto, Canada
    Posts
    1,686
    Helped
    184 / 184
    Points
    14,575
    Level
    29

    Reading formula

    For what processor, language?



    •   AltAdvertisment

        
       

  3. #3
    Member level 2
    Points: 1,509, Level: 8

    Join Date
    Feb 2006
    Posts
    44
    Helped
    0 / 0
    Points
    1,509
    Level
    8

    Re: Reading formula

    for PIC MCU 16F series using C language



    •   AltAdvertisment

        
       

  4. #4
    Advanced Member level 4
    Points: 14,334, Level: 28

    Join Date
    Jun 2005
    Location
    Stanford, SF Bay Peninsula, California, Earth, Solar System, Milky Way
    Posts
    1,418
    Helped
    139 / 139
    Points
    14,334
    Level
    28

    Re: Reading formula

    Quote Originally Posted by blueroomelectronics
    For what processor, language?
    ... and which compiler?



  5. #5
    Banned
    Points: 8,931, Level: 22

    Join Date
    Jan 2007
    Posts
    943
    Helped
    177 / 177
    Points
    8,931
    Level
    22

    Re: Reading formula

    Hi,
    You use the formula as follows:

    Sensor output in Volts(Vs) = ( N * Vref ÷ Nf) ÷ A

    Where N = Current ADC Count
    Vref = Vlaue of the reference Voltage in Volts ( 2V, 2.5V , 5V etc.)
    Nf = ADC Full scale count (1023 for a 10 bit ADC, 255 for an 8Bit ADC etc.)
    A = Amplifier Gain if used, else A = 1

    Sensor Output as variable X = Vs÷ K, where K is the Conversion factor V/U(X),
    U(X) is the unit of X

    For LM35, K = 10 mV/°C = 0.01V/°C

    So the current temperature measured Tc = Vs÷0.01 °C
    = [( N * Vref ÷ Nf) ÷ A ]÷0.01 °C

    Regards,
    Laktronics


    1 members found this post helpful.

  6. #6
    Member level 2
    Points: 1,509, Level: 8

    Join Date
    Feb 2006
    Posts
    44
    Helped
    0 / 0
    Points
    1,509
    Level
    8

    Re: Reading formula

    Laktronics , thanks...all the sensor reading can refer to your formula?



    •   AltAdvertisment

        
       

  7. #7
    Advanced Member level 5
    Points: 14,575, Level: 29
    blueroomelectronics's Avatar
    Join Date
    Sep 2006
    Location
    Toronto, Canada
    Posts
    1,686
    Helped
    184 / 184
    Points
    14,575
    Level
    29

    Reading formula

    Looks right to me.

    As a sidenote if you can convert the math to integer you won't need a floating point library.



--[[ ]]--