Sample source code for the MAX6613. The MAX6613 is a low-power analog output temperature sensor in a tiny 5-pin SC70 package. The supply current usage for the MAX6613 is typically 7.5µA.

Dependencies:   max32630fthr USBDevice

Committer:
phonemacro
Date:
Fri Apr 26 00:57:03 2019 +0000
Revision:
2:caf92ca064a9
Parent:
1:9b9c2989d4eb
FIx typo in prints

Who changed what in which revision?

UserRevisionLine numberNew 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 0:a9f350f894e7 25 float max6613_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 1:9b9c2989d4eb 32 void max6613_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 0:a9f350f894e7 40 * @brief Sample main program for MAX6613
phonemacro 0:a9f350f894e7 41 * @version 1.0000.0000
phonemacro 0:a9f350f894e7 42 *
phonemacro 0:a9f350f894e7 43 * @details Sample main program for MAX6613
phonemacro 1:9b9c2989d4eb 44 * The MAX6613 is a low-cost, low-power analog output (1 wire, plus power)
phonemacro 1:9b9c2989d4eb 45 * temperature sensor in a tiny 5-pin SC70 package (0.65 mm pitch)
phonemacro 1:9b9c2989d4eb 46 * Supply Current: 7.5µA typical
phonemacro 1:9b9c2989d4eb 47 * Supply voltage: 1.8V to 5.5V
phonemacro 1:9b9c2989d4eb 48 * Operating Range: -55°C to +130°C when VDD is 2.5V to 5.5V
phonemacro 1:9b9c2989d4eb 49 * 25°C to +130°C when VDD is 1.8V
phonemacro 1:9b9c2989d4eb 50 * Accuracy: +-4°C
phonemacro 1:9b9c2989d4eb 51 * Pin Compatible with LM20
phonemacro 1:9b9c2989d4eb 52 *
phonemacro 0:a9f350f894e7 53 * The prints are sent to the terminal window (9600, 8n1).
phonemacro 0:a9f350f894e7 54 * The program sets the GPIOs to 3.3V and the program
phonemacro 0:a9f350f894e7 55 * configures the chip and reads temperatures.
phonemacro 0:a9f350f894e7 56 * To run the program, drag and drop the .bin file into the
phonemacro 0:a9f350f894e7 57 * DAPLINK folder. After it finishes flashing, cycle the power or
phonemacro 0:a9f350f894e7 58 * reset the Pegasus (MAX32630FTHR) after flashing by pressing the button on
phonemacro 0:a9f350f894e7 59 * the Pegasus next to the battery connector or the button
phonemacro 0:a9f350f894e7 60 * on the MAXREFDES100HDK.
phonemacro 0:a9f350f894e7 61 */
phonemacro 0:a9f350f894e7 62 int main()
phonemacro 0:a9f350f894e7 63 {
phonemacro 0:a9f350f894e7 64 float temperature;
phonemacro 0:a9f350f894e7 65 uint32_t i;
phonemacro 0:a9f350f894e7 66 const float A = -0.00000225f;
phonemacro 0:a9f350f894e7 67 const float B = -0.01105f;
phonemacro 0:a9f350f894e7 68 const float C1 = 1.8455f;
phonemacro 0:a9f350f894e7 69 float c2;
phonemacro 0:a9f350f894e7 70 microUSB.printf("micro USB serial port\r\n");
phonemacro 0:a9f350f894e7 71 rLED = LED_OFF;
phonemacro 1:9b9c2989d4eb 72 gLED = LED_OFF;
phonemacro 0:a9f350f894e7 73 bLED = LED_OFF;
phonemacro 1:9b9c2989d4eb 74 Ticker ticker; // calls a callback repeatedly with a timeout
phonemacro 1:9b9c2989d4eb 75 ticker.attach(callback(&max6613_timer), 1.0f); /* set timer for one second */
phonemacro 0:a9f350f894e7 76
phonemacro 1:9b9c2989d4eb 77 daplink.printf("MAX6613 Temperature Sensor\r\n\r\n");
phonemacro 1:9b9c2989d4eb 78
phonemacro 0:a9f350f894e7 79 temperature = (float)((1.8455f - (AIN5_FSV * ain1)) / 0.01123f);
phonemacro 1:9b9c2989d4eb 80 #if 0
phonemacro 1:9b9c2989d4eb 81 daplink.printf("AIN1: %1.5f\n", (AIN5_FSV * ain1) ); // analog inputs 1
phonemacro 1:9b9c2989d4eb 82 #endif
phonemacro 0:a9f350f894e7 83
phonemacro 0:a9f350f894e7 84 daplink.printf("Temperature using Linear Approximation\r\n");
phonemacro 0:a9f350f894e7 85 for (i = 0; i < 8; i++) {
phonemacro 0:a9f350f894e7 86 temperature = (float)((1.8455f - (AIN5_FSV * ain1)) / 0.01123f);
phonemacro 2:caf92ca064a9 87 daplink.printf("temperature: %3.1f degrees C, %3.1f degrees F\r\n", temperature, max6613_celsius_to_fahrenheit(temperature));
phonemacro 0:a9f350f894e7 88 wait(2);
phonemacro 0:a9f350f894e7 89 }
phonemacro 0:a9f350f894e7 90 daplink.printf("\r\n");
phonemacro 0:a9f350f894e7 91
phonemacro 2:caf92ca064a9 92 daplink.printf("Temperature using Quadratic Equation\r\n");
phonemacro 0:a9f350f894e7 93 for (i = 0; i < 8; i++) {
phonemacro 0:a9f350f894e7 94 c2 = AIN5_FSV * ain1;
phonemacro 0:a9f350f894e7 95 temperature = (-B - sqrt(B*B - 4*A*(C1-c2)))/(2*A);
phonemacro 2:caf92ca064a9 96 daplink.printf("temperature: %3.1f degrees C, %3.1f degrees F\r\n", temperature, max6613_celsius_to_fahrenheit(temperature));
phonemacro 0:a9f350f894e7 97 wait(2);
phonemacro 0:a9f350f894e7 98 }
phonemacro 1:9b9c2989d4eb 99 daplink.printf("\r\n\r\n");
phonemacro 0:a9f350f894e7 100
phonemacro 0:a9f350f894e7 101 while(1) {
phonemacro 0:a9f350f894e7 102 }
phonemacro 0:a9f350f894e7 103 }
phonemacro 0:a9f350f894e7 104