Subversion Repositories HomeAutomation

Rev

Rev 797 | Blame | Compare with Previous | Last modification | View Log | SVN | RSS feed

  1. /*
  2.  * TC1047 temperature sensor
  3.  *
  4.  * Using ADC for reading sensor value.
  5.  *
  6.  * Author: Erik Larsson
  7.  * Date: 2006-12-19
  8.  *
  9.  */
  10.  
  11. /*-----------------------------------------------
  12.  * Includes
  13.  * ---------------------------------------------*/
  14. #include <avr/io.h>
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17. #include <config.h>
  18.  
  19. #include "tc1047.h"
  20. #include <drivers/adc/adc.h>
  21.  
  22. /*----------------------------------------------
  23.  * Functions
  24.  * --------------------------------------------*/
  25.  
  26. /*
  27.  * Initiate ADC for reading temperature from sensor.
  28.  */
  29. uint8_t adcTemperatureInit()
  30. {
  31.     return ADC_Init();
  32. }
  33.  
  34. /*
  35.  * Start reading and return the temperature value.
  36.  */
  37. uint16_t getTC1047temperature(uint8_t sensor)
  38. {
  39.     uint32_t temperatureData;
  40.  
  41.     temperatureData = ADC_Get(sensor);
  42.  
  43.     /* Use 5 volt as reference */
  44.     temperatureData = temperatureData * 5;
  45.     temperatureData = (temperatureData * 100 / 1024) - 50;
  46.  
  47.     return temperatureData;
  48. }
  49.