Example source code for Maxim Integrated MAX6605 low-power, inexpensive analog output temperature sensor using the MAX32630FTHR analog input. The MAX6605 precision, low-power, inexpensive, analog output temperature sensor is available in a 5-pin SC70 package. The device has a +2.7V to +5.5V supply voltage range and 10µA supply current over the -55°C to +125°C temperature range.
Dependencies: max32630fthr USBDevice
main.cpp@2:9ceed197ca58, 2019-04-27 (annotated)
- Committer:
- phonemacro
- Date:
- Sat Apr 27 10:09:59 2019 +0000
- Revision:
- 2:9ceed197ca58
- Parent:
- 1:9b9c2989d4eb
initial commit;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
phonemacro | 0:a9f350f894e7 | 1 | #include "mbed.h" |
phonemacro | 0:a9f350f894e7 | 2 | #include "max32630fthr.h" |
phonemacro | 0:a9f350f894e7 | 3 | #include "USBSerial.h" |
phonemacro | 0:a9f350f894e7 | 4 | |
phonemacro | 0:a9f350f894e7 | 5 | MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3); |
phonemacro | 0:a9f350f894e7 | 6 | |
phonemacro | 0:a9f350f894e7 | 7 | // Hardware serial port over DAPLink |
phonemacro | 0:a9f350f894e7 | 8 | Serial daplink(P2_1, P2_0); |
phonemacro | 0:a9f350f894e7 | 9 | |
phonemacro | 0:a9f350f894e7 | 10 | // Virtual serial port over USB |
phonemacro | 0:a9f350f894e7 | 11 | USBSerial microUSB; |
phonemacro | 0:a9f350f894e7 | 12 | |
phonemacro | 0:a9f350f894e7 | 13 | DigitalOut rLED(LED1); |
phonemacro | 0:a9f350f894e7 | 14 | DigitalOut gLED(LED2); |
phonemacro | 0:a9f350f894e7 | 15 | DigitalOut bLED(LED3); |
phonemacro | 0:a9f350f894e7 | 16 | |
phonemacro | 0:a9f350f894e7 | 17 | /* Analog inputs 0 and 1 have internal dividers to allow measuring 5V signals |
phonemacro | 0:a9f350f894e7 | 18 | * The dividers are selected by using inputs AIN_4 and AIN_5 respectively. |
phonemacro | 0:a9f350f894e7 | 19 | * The full scale range for AIN0-3 is 1.2V |
phonemacro | 0:a9f350f894e7 | 20 | * The full scale range for AIN4-5 is 6.0V |
phonemacro | 0:a9f350f894e7 | 21 | */ |
phonemacro | 0:a9f350f894e7 | 22 | AnalogIn ain1(AIN_5); |
phonemacro | 0:a9f350f894e7 | 23 | const float AIN5_FSV = 6.0f; /* Full scale value for AIN5 */ |
phonemacro | 0:a9f350f894e7 | 24 | |
phonemacro | 2:9ceed197ca58 | 25 | float celsius_to_fahrenheit(float temp_c) |
phonemacro | 0:a9f350f894e7 | 26 | { |
phonemacro | 0:a9f350f894e7 | 27 | float temp_f; |
phonemacro | 0:a9f350f894e7 | 28 | temp_f = ((temp_c * 9)/5) + 32; |
phonemacro | 0:a9f350f894e7 | 29 | return temp_f; |
phonemacro | 0:a9f350f894e7 | 30 | } |
phonemacro | 1:9b9c2989d4eb | 31 | |
phonemacro | 2:9ceed197ca58 | 32 | void blink_timer(void) { |
phonemacro | 1:9b9c2989d4eb | 33 | gLED = !gLED; /* blink the green LED */ |
phonemacro | 1:9b9c2989d4eb | 34 | } |
phonemacro | 1:9b9c2989d4eb | 35 | |
phonemacro | 1:9b9c2989d4eb | 36 | |
phonemacro | 0:a9f350f894e7 | 37 | // main() runs in its own thread in the OS |
phonemacro | 0:a9f350f894e7 | 38 | // (note the calls to Thread::wait below for delays) |
phonemacro | 0:a9f350f894e7 | 39 | /** |
phonemacro | 2:9ceed197ca58 | 40 | * @brief Sample main program for MAX6605 |
phonemacro | 0:a9f350f894e7 | 41 | * @version 1.0000.0000 |
phonemacro | 0:a9f350f894e7 | 42 | * |
phonemacro | 2:9ceed197ca58 | 43 | * @details Sample main program for MAX6605 |
phonemacro | 2:9ceed197ca58 | 44 | * The MAX6605 precision, low-power, analog output temperature |
phonemacro | 2:9ceed197ca58 | 45 | * sensor is available in a 5-pin SC70 (0.65 mm pitch)package. |
phonemacro | 2:9ceed197ca58 | 46 | * The device has a +2.7V to +5.5V supply voltage range |
phonemacro | 2:9ceed197ca58 | 47 | * and 10µA supply current over the -55°C to +125°C temperature range. |
phonemacro | 2:9ceed197ca58 | 48 | * For the -40°C to +105°C temperature range, the supply voltage can go as low as +2.4V. |
phonemacro | 2:9ceed197ca58 | 49 | * Supply Current: 10µA |
phonemacro | 2:9ceed197ca58 | 50 | * Supply voltage: 2.7V to 5.5V |
phonemacro | 2:9ceed197ca58 | 51 | * Accuracy : ±0.75°C 25°C |
phonemacro | 2:9ceed197ca58 | 52 | * ±3.00°C 0.0°C to 70°C |
phonemacro | 2:9ceed197ca58 | 53 | * ±3.80°C -20°C to 85°C |
phonemacro | 2:9ceed197ca58 | 54 | * ±5.00°C -40°C to 100°C |
phonemacro | 2:9ceed197ca58 | 55 | * ±5.80°C -55°C to 125°C |
phonemacro | 1:9b9c2989d4eb | 56 | * |
phonemacro | 0:a9f350f894e7 | 57 | * The prints are sent to the terminal window (9600, 8n1). |
phonemacro | 0:a9f350f894e7 | 58 | * The program sets the GPIOs to 3.3V and the program |
phonemacro | 0:a9f350f894e7 | 59 | * configures the chip and reads temperatures. |
phonemacro | 0:a9f350f894e7 | 60 | * To run the program, drag and drop the .bin file into the |
phonemacro | 0:a9f350f894e7 | 61 | * DAPLINK folder. After it finishes flashing, cycle the power or |
phonemacro | 0:a9f350f894e7 | 62 | * reset the Pegasus (MAX32630FTHR) after flashing by pressing the button on |
phonemacro | 0:a9f350f894e7 | 63 | * the Pegasus next to the battery connector or the button |
phonemacro | 0:a9f350f894e7 | 64 | * on the MAXREFDES100HDK. |
phonemacro | 0:a9f350f894e7 | 65 | */ |
phonemacro | 0:a9f350f894e7 | 66 | int main() |
phonemacro | 0:a9f350f894e7 | 67 | { |
phonemacro | 0:a9f350f894e7 | 68 | float temperature; |
phonemacro | 0:a9f350f894e7 | 69 | uint32_t i; |
phonemacro | 2:9ceed197ca58 | 70 | const float A = 0.000001604f; |
phonemacro | 2:9ceed197ca58 | 71 | const float B = 0.0119f; |
phonemacro | 2:9ceed197ca58 | 72 | const float C1 = 0.744f; |
phonemacro | 0:a9f350f894e7 | 73 | float c2; |
phonemacro | 0:a9f350f894e7 | 74 | microUSB.printf("micro USB serial port\r\n"); |
phonemacro | 0:a9f350f894e7 | 75 | rLED = LED_OFF; |
phonemacro | 1:9b9c2989d4eb | 76 | gLED = LED_OFF; |
phonemacro | 0:a9f350f894e7 | 77 | bLED = LED_OFF; |
phonemacro | 1:9b9c2989d4eb | 78 | Ticker ticker; // calls a callback repeatedly with a timeout |
phonemacro | 2:9ceed197ca58 | 79 | ticker.attach(callback(&blink_timer), 1.0f); /* set timer for one second */ |
phonemacro | 0:a9f350f894e7 | 80 | |
phonemacro | 2:9ceed197ca58 | 81 | daplink.printf("MAX6605 Temperature Sensor\r\n\r\n"); |
phonemacro | 1:9b9c2989d4eb | 82 | |
phonemacro | 2:9ceed197ca58 | 83 | temperature = (float)(((AIN5_FSV * ain1) -0.744f) / 0.0119f); |
phonemacro | 1:9b9c2989d4eb | 84 | #if 0 |
phonemacro | 1:9b9c2989d4eb | 85 | daplink.printf("AIN1: %1.5f\n", (AIN5_FSV * ain1) ); // analog inputs 1 |
phonemacro | 1:9b9c2989d4eb | 86 | #endif |
phonemacro | 0:a9f350f894e7 | 87 | |
phonemacro | 0:a9f350f894e7 | 88 | daplink.printf("Temperature using Linear Approximation\r\n"); |
phonemacro | 0:a9f350f894e7 | 89 | for (i = 0; i < 8; i++) { |
phonemacro | 2:9ceed197ca58 | 90 | temperature = (float)(((AIN5_FSV * ain1) -0.744f) / 0.0119f); |
phonemacro | 2:9ceed197ca58 | 91 | daplink.printf("temperature: %3.1f degrees C, %3.1f degrees F\r\n", temperature, celsius_to_fahrenheit(temperature)); |
phonemacro | 0:a9f350f894e7 | 92 | wait(2); |
phonemacro | 0:a9f350f894e7 | 93 | } |
phonemacro | 0:a9f350f894e7 | 94 | daplink.printf("\r\n"); |
phonemacro | 0:a9f350f894e7 | 95 | |
phonemacro | 0:a9f350f894e7 | 96 | daplink.printf("Temperature using the Quadratic Equation\r\n"); |
phonemacro | 0:a9f350f894e7 | 97 | for (i = 0; i < 8; i++) { |
phonemacro | 0:a9f350f894e7 | 98 | c2 = AIN5_FSV * ain1; |
phonemacro | 2:9ceed197ca58 | 99 | temperature = (-B + sqrt(B*B - 4*A*(C1-c2)))/(2*A); |
phonemacro | 2:9ceed197ca58 | 100 | daplink.printf("temperature: %3.1f degrees C C, %3.1f degrees F\r\n", temperature, celsius_to_fahrenheit(temperature)); |
phonemacro | 0:a9f350f894e7 | 101 | wait(2); |
phonemacro | 0:a9f350f894e7 | 102 | } |
phonemacro | 1:9b9c2989d4eb | 103 | daplink.printf("\r\n\r\n"); |
phonemacro | 0:a9f350f894e7 | 104 | |
phonemacro | 0:a9f350f894e7 | 105 | while(1) { |
phonemacro | 0:a9f350f894e7 | 106 | } |
phonemacro | 0:a9f350f894e7 | 107 | } |
phonemacro | 0:a9f350f894e7 | 108 |