Template for LPC1768

Dependencies:   Gimbal MLX90620 Socket lwip-eth lwip-sys lwip mbed-rtos mbed

Fork of EkkoEye by EkkoSense

Revision:
54:aaf6b5ceedd8
Parent:
53:72f350a6d09c
--- a/CMLX90620.h	Thu Apr 14 13:45:38 2016 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,215 +0,0 @@
-/*
- * CMLX90620.h
- *
- *  Created on: 12 Mar 2016
- *      Author: mike
- */
-
-#ifndef MLX90620_H
-#define MLX90620_H
-
-#include "mbed.h"
-
-/** Software routines to access the Melexis MLX90620 64 pixel (4 X 16) infrared sensor array
- *   The MLX90620's internal RAM has different i2c behavior than it's internal EEPROM
- *   As a result, the MLX90620's RAM uses more primitive mbed i2c commands than does the EEPROM.
- *
- * @code
- * #include "mbed.h"
- * #include "MLX90620.h"
- *
- * char* EEbuf = new char[256];     //buffer for contents of EEPROM
- * char* RamCmmd = new char[8];     //holds / sends MLX90620 RAM commands
- * char* RamBuf = new char[128];    //0x3f words, values are 'unsigned short'
- *
- * Serial pc(USBTX, USBRX);
- * MLX90620 mlx(p9, p10, "mlx");
- * //MLX90620 mlx(PTE0, PTE1, "mlx");
- *
- * float Ta = 0.0;
- * float TempPxl = 0.0;
- *
- *
- * int main() {
- *     pc.baud(115200);
- *     mlx.LoadEEPROM();         //if returns non 0, MLX90620 may not be unconnected to i2c bus
- *     mlx.SetOscTrimReg();      //if returns non 0, MLX90620 is having RAM access problems with i2c bus
- *     mlx.SetConfigReg();       //if returns non 0, WTF?? - shouldn't be any i2c problems at this point
- *     mlx.StartMeasurement();   //if returns non 0, WTF??
- *     wait(0.5);
- *     mlx.CalcTa_To();          //if returns non 0, WTF??
- *     Ta = mlx.GetDieTemp();
- *     pc.printf("\nTa = %f\n\n", Ta);
- *     //simplistic dump of pixel array. Any terminal character
- *     //generates another acquisition cycle.
- *     //allows the program to run at maximum refresh rate of 4Hz
- *     //In order to save time, mlx.StartMeasurement(); is done
- *     //just after mlx.GetMLXRam();. This way the CPU can process
- *     //lots of floating math while the MLX90620 gets another round.
- *     while(1) {
- *         int config = mlx.GetConfigReg();
- *         int chk = config & 0x0300;
- *         if(chk == 0) {
- *             pc.printf("\nIR Array Capture\n");
- *             mlx.LoadMLXRam();         //if returns 0, WTF??
- *             mlx.StartMeasurement();   //if returns 0, WTF??
- *             for(int i = 0; i < 64; i++) {
- *                 TempPxl = mlx.CalcPixel(i);
- *                 pc.printf("Pix %2d   Temp %.3f\n", i, TempPxl);
- *             }
- *         } else {
- *             wait_ms(100);
- *         }
- *     }
- *}
- * @endcode
- */
-/* MLX90620 controller class
- */
-class MLX90620 {
-
-public:
-
-    /** Create a MLX90620 object using the specified I2C object
-     *
-     * @param constructor, - the I2C object to communicate with
-     */
-    MLX90620(PinName sda, PinName scl, const char* name);
-
-
-    /** Copy the contents of the MLX90620 EEPROM into local buffer for later use
-     *    Returns '1' if i2c error, '0' if ok.
-     *  Only done at initialization.  MUST be the first thing you do in MAIN.
-     *
-     * @param NONE, - loads all 256 bytes from EEPROM into local buffer
-     */
-    int LoadEEPROM();
-
-
-    /** Initialize the MLX90620's Oscillator Trim Register
-     *    Data is derived from values received from the EEPROM
-     *    Returns '1' if i2c error, '0' if ok.
-     *  Register is only set once during initialization
-     *
-     * @param NONE, - 7 lsb bits from 16 bit value, set by EEPROM value at initialization
-     */
-    int SetOscTrimReg();
-
-
-    /** Get the MLX90620's Oscillator Trim Register
-     *    Returns the Oscillator Trim Register value
-     *
-     * @param NONE, - 7 lsb bits from 16 bit value, Read from MLX RAM
-     */
-    unsigned short GetOscTrimReg();
-
-
-    /** Set the MLX90620's Configuration Register
-     *    Returns '0' if i2c error, '1' if ok.
-     *  Register is set only during initialization. Inital setup:
-     *  1. ADC low reference
-     *  2. Ta Ref Rate 8Hz
-     *  3. I2C FM+ mode enabled
-     *  4. MD / Brownout bit set
-     *  5. Normal Operation (non-Sleep) mode
-     *  6. Step(Melexis reserved) mode. (removed from later datasheets, but used in this code)
-     *  7. IR refresh rate 4Hz
-     *
-     * @param NONE, - 16 bit value set by code at initialization
-     */
-    int SetConfigReg();
-
-
-    /** Get the MLX90620's Configuration Register
-     *    Returns the Configuration Register value
-     *  periodic check for Ta ready, IR Array ready and brownout conditions
-     *
-     * @param returns unsigned short, - 16 bit value, Read from MLX RAM
-     */
-    unsigned short GetConfigReg();
-
-
-    /** Get the MLX90620's PTAT register. Register read at every Ta cycle
-     *    Returns the Proportional To Ambient Temperature Register value
-     *
-     * @param returns unsigned short, - 16 bit value, PTAT sensor, Read from MLX RAM
-     */
-    unsigned short GetPTATReg();
-
-
-    /** Get the MLX90620's TGC register
-     *    Returns the Temperature Gradient Coefficient Register value
-     *
-     * @param returns short, - 16 bit value, TGC, Read from MLX RAM
-     */
-    short GetTGCReg();
-
-
-    /** Get the MLX90620's IR pixel array and dump into local buffer
-     *    Returns nothing
-     *
-     * @param NONE, - loads IR Pixel array into buffer (0x7F bytes, 0x3f Pixels), Read from MLX RAM
-     */
-    void LoadMLXRam();
-
-
-    /** Start a Ta and IR array conversion update cycle
-     *    Returns '1' if i2c error, '0' if ok.
-     *  Also calls GetPTATReg() and GetTGCReg()
-     *
-     * @param NONE, - MLX90620 starts aquiring data, takes about 250mS /w 4Hz refresh rate
-     */
-    int StartMeasurement();
-
-
-    /** Get the MLX90620's die temperature in degC
-     *    Returns MLX90620 die temperature
-     *  Needs to be performed before every array update calculation
-     *
-     * @param returns, - float of die temperature of MLX90620 in degC
-     */
-    float GetDieTemp();
-
-
-    /** Calculate initial MLX90620 offsets. Performed only at initialization
-     *    Returns nothing
-     *
-     * @param NONE, - sets the MLX90620 with die correcting factors at initialization
-     */
-    void CalcTa_To();
-
-
-    /** Calculate temperature of any pixel within the array (0 - 63)
-     *  after an IR array dump into local buffer,
-     *
-     * @param set int(0-63) of pixel to convert, returns double of temperature in degC of pixel
-     */
-    double CalcPixel(int Pixel);
-
-private:
-    I2C _i2c;                   //local i2c communication interface instance
-    unsigned short Config;
-    unsigned short OscTrim;
-    unsigned short PtatD;
-    short VCP;
-    short Vth25X;
-    signed char AcpX;
-    signed char BcpX;
-    float Kt1fX;
-    float Kt2fX;
-    float TaXX;
-    signed char TGCX;
-    char BiScaleX;
-    unsigned short theta0X;
-    char theta0ScaleX;
-    char deltaThetaScaleX;
-    unsigned short elipsonX;
-    signed char AiPixelX;
-    signed char BiPixelX;
-    char dThetaPixelX;
-    short VirPixelX;
-    double TempPxlX;
-
-};
-
-#endif