Measures the temperature with averaging by using a Microchip MCP9700A analog thermometer. Averaged result is printed to standard output.

Dependencies:   mbed

/ 05_analog_thermometer2

  • Measeures the temperature by using a Microchip MCP9700A
  • analog thermometer (parameteres: 10 mV/C, 500 mV offset, VCC= 2.3-5.5V)
  • Averaged result is printed to standard output.
  • Hardware requirements:
  • - FRDM-KL25Z board
  • - MCP9700A analog thermometer connected to A0 (PTB0)
  • /
Committer:
icserny
Date:
Wed Nov 18 15:32:38 2015 +0000
Revision:
0:9f5cbd8850f2
First version

Who changed what in which revision?

UserRevisionLine numberNew contents of line
icserny 0:9f5cbd8850f2 1 /** 05_analog_thermometer2
icserny 0:9f5cbd8850f2 2 * Measeures the temperature by using a Microchip MCP9700A
icserny 0:9f5cbd8850f2 3 * analog thermometer (parameteres: 10 mV/C, 500 mV offset, VCC= 2.3-5.5V)
icserny 0:9f5cbd8850f2 4 * Averaged result is printed to standard output.
icserny 0:9f5cbd8850f2 5 *
icserny 0:9f5cbd8850f2 6 * Hardware requirements:
icserny 0:9f5cbd8850f2 7 * - FRDM-KL25Z board
icserny 0:9f5cbd8850f2 8 * - MCP9700A analog thermometer connected to A0 (PTB0)
icserny 0:9f5cbd8850f2 9 */
icserny 0:9f5cbd8850f2 10
icserny 0:9f5cbd8850f2 11 #include "mbed.h"
icserny 0:9f5cbd8850f2 12
icserny 0:9f5cbd8850f2 13 AnalogIn ain(A0); // Analog input at PTB0
icserny 0:9f5cbd8850f2 14 uint32_t mysum; // Used for summation
icserny 0:9f5cbd8850f2 15
icserny 0:9f5cbd8850f2 16 int main()
icserny 0:9f5cbd8850f2 17 {
icserny 0:9f5cbd8850f2 18 printf("\r\n05_analog_thermometer2 - with averaging\r\n");
icserny 0:9f5cbd8850f2 19 while(1) {
icserny 0:9f5cbd8850f2 20 mysum = 0;
icserny 0:9f5cbd8850f2 21 for(int i=0; i<3300; i++) {
icserny 0:9f5cbd8850f2 22 mysum += ain.read_u16(); // sum up raw 16-bit data
icserny 0:9f5cbd8850f2 23 }
icserny 0:9f5cbd8850f2 24 float voltage = mysum>>16; // voltage in millivolts
icserny 0:9f5cbd8850f2 25 float tempC = (voltage -500)/10; // tempereature in Celsius
icserny 0:9f5cbd8850f2 26 printf("voltage: %5.0f mV temp: %5.1f C\r\n",voltage,tempC);
icserny 0:9f5cbd8850f2 27 wait(2);
icserny 0:9f5cbd8850f2 28 }
icserny 0:9f5cbd8850f2 29 }