Help me this ADC problem

cancel
Showing results for 
Search instead for 
Did you mean: 

Help me this ADC problem

718 Views
kayji
Contributor I

Hey guys. i'd like to ask about my tiny  ADC problem which has bothered me about 3 days.

 

Problem is, Even if i don't give any signals to adc channels, there are values remained. Logically, system can't show any 

 

values since there are no signals. So i checked that i' m using  a reference voltage which is internally in a adc module. But 

 

i'm not.

 

Specifically i use adc like below.

 

 - 10 bit resolution

 -  Right justified data

 - ATD Clock at least 2M to 8M (System clock is 16M)

 - single conversion at once.

 

And below is my register setting  for using adc

 

void initialize_ADC(void)
{

  ATD1CTL2 = 0x40;  // ADC enable
 
  wait4(1);
  wait4(1);
   
  ATD1CTL3 = 0xA0;  // ADC conversion start
  ATD1CTL4 = 0x00;
  ATD1DIEN = (ATD1DIEN || 0xFF00);
      
}

 

int get_adc(int ch)
{
  ATD1CTL5 = 0x08+ch;            // ch means channel i use. in this case channel 8 to 15            
  while(!(ATD1STAT0 & 0x80));
  return ATD1DR0L+(ATD1DR0H<<8);         // get_adc function is getting conversed values from each channels
}                .

 

i really no idea of this. Plz help pity developer!

Labels (1)
0 Kudos
3 Replies

227 Views
DPB
NXP Employee
NXP Employee

Hello 

 

Which S12 device are you using? Not all  S12 devices feature the same ATD module.

 

For  S12C, S12XD....   ATD1CTL2 = 0x40 is not sufficient.    To power up the ATD bit7 should be set.  i.e. ATD1CTL2 = 0x80

Also the ATD1CTL3 = 0xA0 seems to conflict with the intended "single conversion at once".

 

What reference voltages are you applying on VRH and VRL?

 

You can check the reference voltage connections by setting SC in ATDCTL5 and converting the internal VRH,VRL and (VRH+VRL)/2 channels.

 

DPB

0 Kudos

227 Views
kayji
Contributor I

Sorry for not giving specific information

 

i'm using HC12X series board, mc9s12xep100 demo board.

 

i've checked what you mensioned about ATDCTL2 but there is no bit in the bit 7, The problem of conflicting with single

 

conversion in ATDCTL3 is fixed after your advice. thank you. Though still ADC is not  working.

 

anyway i appreciate your help and like you said i think i need to check the reference voltage.

0 Kudos

227 Views
AROK
Contributor I

Here a basic adc driver for S12XS

 

//Driver configuration
#define Du16DIna_eUse12BitsResolution            1
#define Du16DIna_eUseErrorCheck                    0

 

//----------------------------------------------------------------------------
// Return Codes
//----------------------------------------------------------------------------
#define Ds16DIna_eSuccessfull        0
#define Ds16DIna_eBadParameter    -1
#define Ds16DIna_eNotAvailable    -2

 

//============================================================================//
// NAME : s16DIna_eInit_Exe
//============================================================================//
// ROLE : Acquisition Init
//----------------------------------------------------------------------------//
// INPUT  :
// OUTPUT :
//============================================================================//
TS16 s16DIna_eInit_Exe (void)
{
    //--------------------------------------------------------------------------
   // Init ATD
   // Access to Peripheral regsiter should be a word access to minimize code size
   // Write to the ATD0CTL5 Register will launch the first conversion sequence
   //--------------------------------------------------------------------------

    /*Disable digital buffers*/
    ATD0DIEN = 0;
   
    /* ATD Automatic compare Feature Setup */
    ATD0CMPE = 0x0000;

   
    /* Disable ATD Sequence Complete Interrupt                                                        */
    /* Disable ATD Compare Interrup                                                                        */
    /* Reading Conversion Result registers clears flags                                            */
    /* Abort conversion sequence in Stop Mode (do not use internal clock)                    */
    /* Data is Right justified in the Result Registers                                                */
    /* 1 Conversion Sequence Length                                                                        */
    /* Conversion results are placed in the corresponding result register                    */
    /* Continue conversion                                                                                    */
    ATD0CTL23 = ATD0CTL23_DJM_MASK
                    |ATD0CTL23_S1C_MASK
                    |ATD0CTL23_AFFC_MASK;                   

    /* Clear all interrupts flag */
    ATD0STAT0            = 0xFF;
    ATD0STAT2            = 0xFFFF;


    /* 12 bits data resolution                                                                                                        */
    /* Discharge Internal Sample Capacitor before sampling channel (2 ATD clocks added to sampling time)    */
    ATD0CTL01 = 0
#if(Du16DIna_eUse12BitsResolution>0)
                    |ATD0CTL01_SRES1_MASK        //12 Bits resolution
#else
                    |ATD0CTL01_SRES0_MASK        //10 Bits resolution
#endif
                    |ATD0CTL01_SMP_DIS_MASK;

    /* 4 ATD Clock Cycles Sample Time                            */
    /* 6.66 MHz ATD Clock (Max ATD Frequency is 8.3 MHz)    */
    ATD0CTL45 = ATD0CTL45_PRS1_MASK;

    return (Ds16DIna_eSuccessfull);
}





//============================================================================//
// NAME : s16DIna_eRawValue_Get
//============================================================================//
// ROLE : Get Analogue Input Raw Value
//----------------------------------------------------------------------------//
// INPUT  :  Channel ID
// OUTPUT :  Raw Value (>=0) else Error(<0)
//============================================================================//
TS16 s16DIna_eRawValue_Get(TU8 Fu8ChId)
{
    TS16    s16RetVal = Ds16DIna_eSuccessfull;

    /* Parameter Check */
#if(Du16DIna_eUseErrorCheck>0)
    if(Fu8ChId>=Du16DIna_eNbCh)
    {
        s16RetVal = Ds16DIna_eBadParameter;
    }
#endif
    {
        //Start the conversion
        ATD0CTL5 = Fu8ChId; //Start conversion
       
        // Wait for AD conversion complete
        while (0 == ATD0STAT0_SCF);        
       
        //Return the result
        s16RetVal = ATD0DR0;
    }

    return(s16RetVal);
}

0 Kudos