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
Diff: main.cpp
- Revision:
- 0:a9f350f894e7
- Child:
- 1:9b9c2989d4eb
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon Apr 22 21:23:39 2019 +0000 @@ -0,0 +1,87 @@ +#include "mbed.h" +#include "max32630fthr.h" +#include "USBSerial.h" + +MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3); + +// Hardware serial port over DAPLink +Serial daplink(P2_1, P2_0); + +// Virtual serial port over USB +USBSerial microUSB; + +DigitalOut rLED(LED1); +DigitalOut gLED(LED2); +DigitalOut bLED(LED3); + +/* Analog inputs 0 and 1 have internal dividers to allow measuring 5V signals + * The dividers are selected by using inputs AIN_4 and AIN_5 respectively. + * The full scale range for AIN0-3 is 1.2V + * The full scale range for AIN4-5 is 6.0V + */ +AnalogIn ain1(AIN_5); +const float AIN5_FSV = 6.0f; /* Full scale value for AIN5 */ + +float max6613_celsius_to_fahrenheit(float temp_c) +{ + float temp_f; + temp_f = ((temp_c * 9)/5) + 32; + return temp_f; +} +// main() runs in its own thread in the OS +// (note the calls to Thread::wait below for delays) +/** +* @brief Sample main program for MAX6613 +* @version 1.0000.0000 +* +* @details Sample main program for MAX6613 +* The prints are sent to the terminal window (9600, 8n1). +* The program sets the GPIOs to 3.3V and the program +* configures the chip and reads temperatures. +* To run the program, drag and drop the .bin file into the +* DAPLINK folder. After it finishes flashing, cycle the power or +* reset the Pegasus (MAX32630FTHR) after flashing by pressing the button on +* the Pegasus next to the battery connector or the button +* on the MAXREFDES100HDK. +*/ +int main() +{ + float temperature; + uint32_t i; + const float A = -0.00000225f; + const float B = -0.01105f; + const float C1 = 1.8455f; + float c2; + microUSB.printf("micro USB serial port\r\n"); + rLED = LED_OFF; + gLED = LED_ON; + bLED = LED_OFF; + + rLED = LED_OFF; + temperature = (float)((1.8455f - (AIN5_FSV * ain1)) / 0.01123f); +// daplink.printf("AIN1: %1.5f\n", (AIN5_FSV * ain1) ); // analog inputs 1 + + daplink.printf("Temperature using Linear Approximation\r\n"); + for (i = 0; i < 8; i++) { + temperature = (float)((1.8455f - (AIN5_FSV * ain1)) / 0.01123f); + daplink.printf("temperature: %3.1f degrees C C, %3.1f degrees F\r\n", temperature, max6613_celsius_to_fahrenheit(temperature)); + wait(2); + } + daplink.printf("\r\n"); + + daplink.printf("Temperature using the Quadratic Equation\r\n"); + for (i = 0; i < 8; i++) { + c2 = AIN5_FSV * ain1; + temperature = (-B - sqrt(B*B - 4*A*(C1-c2)))/(2*A); + daplink.printf("temperature: %3.1f degrees C C, %3.1f degrees F\r\n", temperature, max6613_celsius_to_fahrenheit(temperature)); + wait(2); + } + + daplink.printf("\r\n"); + + while(1) { + gLED = !gLED; + wait(0.5); + } +} +