Using ADC1 of Q2686


#1

Hi All,
I want to use 2 adc in Q2686. AUX_ADC (ADC2) is working properly but i’m not been able to use BAT_TEMP (ADC1) as it is returning 0 value in both AT+ADC? and adl_adcAnalogRead function. In my case, system is power operated and battery charging is not required.Can anyone help me to use BAT_TEMP input as analog input?


#2

Hi,
here is code for reading temp. from MCP9700T. Maybe you have a problem with this line:

s32 MyADCHandle=1; //1 - BAT TEMP, 2 - ADC2

/********************************************************************************************/
/*  ADC.c   -  Copyright Wavecom S.A. (c) 2006                                              */
/*                                                                                          */
/*                                                                                          */
/* DISCLAIMER OF WARRANTY                                                                   */
/* ======================                                                                   */
/* This Software is provided free of charge on an 'as is' basis. No warranty is given       */
/* by Wavecom S.A. in relation to the Software of the uses to which it may be put by you,   */
/* the user, or its merchantability, fitness or suitability for any particular purpose      */
/* or conditions; and/or that the use of the Software and all documentation relating        */
/* thereto by the Licensee will not infringe any third party copyright or other             */
/* intellectual property rights. Wavecom S.A. shall furthermore be under no obligation      */
/* to provide support of any nature for the Software and the Documentation.                 */
/*                                                                                          */
/* LIMIT OF LIABILITY                                                                       */
/* ==================                                                                       */
/* In no event shall Wavecom S.A. be liable for any loss or damages whatsoever or howsoever */
/* caused arising directly or indirectly in connection with this licence, the Software,     */
/* its use or otherwise except to the extent that such liability may not be lawfully        */
/* excluded. Notwithstanding the generality of the foregoing, Wavecom S.A. expressly        */
/* excludes liability for indirect, special, incidental or consequential loss or damage     */
/* which may arise in respect of the Software or its use, or in respect of other equipment  */
/* or property, or for loss of profit, business, revenue, goodwill or anticipated savings.  */
/*                                                                                          */
/********************************************************************************************/

/***************************************************************************/
/*  File       : ADC.c                                                     */
/*-------------------------------------------------------------------------*/
/*  Object     : Customer application                                      */
/*                                                                         */
/*  contents   : ADL ADC Sample                                            */
/*                                                                         */

/****************************************************************************/

/* includes */
#include "adl_global.h"


/***************************************************************************/
/*  Local variables                                                        */
/***************************************************************************/

/* --------- */
/* Constants */
/* --------- */

#define     ADC_MAX_LEVEL       2000
#define     ADC_INITIAL_LEVEL   0


// Commands strings
static const ascii * ADC_CMD_LEVEL  = "AT+ADCLEVEL";

/* --------- */
/* Variables */
/* --------- */

// ADC variables
s32 MyADCHandle=1; //1 - BAT TEMP, 2 - ADC2
u16 ADC_Level;

// Trace hard Level defined on entry point
static u8 ADC_Trace_Level = 2;

/***************************************************************************/
/*  Mandatory variables                                                    */
/*-------------------------------------------------------------------------*/
/*  wm_apmCustomStackSize                                                  */
/*-------------------------------------------------------------------------*/
/***************************************************************************/
const u16 wm_apmCustomStackSize = 1024*3;


/***************************************************************************/
/*  Local functions                                                        */
/***************************************************************************/

/***************************************************************************/
/*  Function   : ADC_LEVEL_CmdHandler                                      */
/*-------------------------------------------------------------------------*/
/*  Objet      : ADC output value                                          */
/*                                                                         */
/*-------------------------------------------------------------------------*/
/*  Variable Name     |IN |OUT|GLB|  Utilisation                           */
/*--------------------+---+---+---+----------------------------------------*/
/*  paras             | X |   |   |  set the ADC output value              */
/*--------------------+---+---+---+----------------------------------------*/
/***************************************************************************/
void ADC_LEVEL_CmdHandler ( adl_atCmdPreParser_t * paras )
{
    // Switch on CmdType
    switch(paras->Type)
    {
        case ADL_CMD_TYPE_TEST :
        {
            // Possible values
            ascii result[100];
            wm_sprintf ( result, "\r\n%s: (0-%d)\r\n", ADC_CMD_LEVEL + 2, ADC_MAX_LEVEL );
            adl_atSendResponsePort ( ADL_AT_RSP, paras->Port, result );
        }
        break;

        case ADL_CMD_TYPE_READ :
        {
			s32 sReturn;
            s32 ADCresult;
           // Read the current value on the ADC block
            sReturn = adl_adcAnalogRead ( MyADCHandle, &ADCresult );

            if ( sReturn == 0 )
            {
				// Current value
                ascii result[100];

                wm_sprintf ( result, "\r\n%s: %d,%d°C\r\n", ADC_CMD_LEVEL + 2, (ADCresult-500)/10, (ADCresult-500)%10);
                adl_atSendResponsePort ( ADL_AT_RSP, paras->Port, result );
            }
            else
            {
                // Bad parameter
                TRACE (( ADC_Trace_Level, "ADC sample : adl_ADCRead error %d", sReturn ));

                adl_atSendStdResponsePort ( ADL_AT_RSP, paras->Port, ADL_STR_ERROR );
            }
        }
        break;
    }
}



/***************************************************************************/
/*  Function   : ADC_run                                                   */
/*-------------------------------------------------------------------------*/
/*  Object     : Start Application Function                                */
/*                                                                         */
/*-------------------------------------------------------------------------*/
/*  Variable Name     |IN |OUT|GLB|  Utilisation                           */
/*--------------------+---+---+---+----------------------------------------*/
/***************************************************************************/
bool ADC_run ( u8 Port )
{
    bool sReturn = TRUE;

	// Subscribe to AT commands set
    adl_atCmdSubscribe ( (ascii*)(ADC_CMD_LEVEL),     ADC_LEVEL_CmdHandler,   ADL_CMD_TYPE_TEST | ADL_CMD_TYPE_READ | 0x11 );

    return sReturn;
}



/***************************************************************************/
/*  Function   : adl_main                                                  */
/*-------------------------------------------------------------------------*/
/*  Objet      : Customer ADL application initialisation                   */
/*                                                                         */
/*  Return     :                                                           */
/*                                                                         */
/*-------------------------------------------------------------------------*/
/*  Variable Name     |IN |OUT|GLB|  Utilisation                           */
/*--------------------+---+---+---+----------------------------------------*/
/*  adlInitType       |   |   |   |  Application starting mode             */
/***************************************************************************/
void adl_main(adl_InitType_e adlInitType)
{            
    bool bReturn = FALSE;

    // Call Monitoring test application
    TRACE (( 1, "ADC sample main" ));
    TRACE (( 1, __DATE__ ));
    TRACE (( 1, __TIME__ ));
    
    // start application
    bReturn = ADC_run ( 0 );
    if(bReturn == FALSE)
    {
        TRACE (( 1, "Application launch failed" ));
    }	
}

#3

Hi,
I have tried it with a new module and both the adc are working. Thanks a lot for the reply.