MCF51QE128 ADC problem

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

MCF51QE128 ADC problem

787 Views
naldo3
Contributor I

Hi everybody,

 

can anyone help me about my problem? I'm programming a MCF51QE128 Coldfire V1 and I want to get an adc value from a NTC resistor. The problem is that I receive from the ADCR a value that is not corresponding with the value read from a tester in the micro adc pin, in fact Vtester = 1.5 Vadcr.

 

The code is simply:

 

/*Includes*/
#include <hidef.h>                                     // For EnableInterrupts macro
#include "derivative.h"                                // Include peripheral declarations
#include <stdio.h>
#include <math.h>
#include <stdint.h>
#include <string.h>

/*Global Variables*/
unsigned char NTCHighValue = 0;
unsigned char NTCLowValue = 0;
                      
/*Function Calls*/                                  
void ICS_Configuration(void);
void MCU_Init(void);

/*Main Sequence*/
void main(void)
{  

  ICS_Configuration();
  MCU_Init();                                         // Call Device Initialization

  for(;:smileywink:
  {
      NTCHighValue = ADCRH;
      NTCLowValue = ADCRL;
  }
}

void MCU_Init(void)
{
  /* Common initialization of the CPU registers */
  SCGC1 = 0xFF;                                     
  PTASE &= (unsigned char)~0xDF;                    
  PTADS = 0x00;                                      
  SCGC2 |= (unsigned char)0x7F;                              
 

  /* ### Init_ADC init code */
  APCTL2 = 0x00;                                     
  ADCCFG = 0x14;                                     
  ADCSC2 = 0x00;                                     
  ADCCV = 0x00;                                     
  ADCSC1 = 0x29;                                     

 

  /* ### */
  asm {                                /* Set Interrupt level 0 */
    move.w SR,D0;
    andi.l #0xF8FF,D0;
    move.w D0,SR;
  }
}

void ICS_Configuration(void)
{
  /* ### MCF51QE128_80 "Cpu" init code ... */
  /*  PE initialization code after reset */
  /* Common initialization of the write once registers */
  SOPT1 = 0x52;                                     
  SPMSC1 = 0x1C;                                     
  SPMSC2 = 0x02;                                     
  SPMSC3 &= (unsigned char)~0x38;                    
 

  /* Initialization of CPU registers */
  asm {
    /* VBR: ADDRESS=0 */
    clr.l d0
    movec d0,VBR
    /* CPUCR: ARD=0,IRD=0,IAE=0,IME=0,BWD=0,FSD=0 */
    clr.l d0
    movec d0,CPUCR
  }
 

  /*  System clock initialization */
  ICSC1 = 0x04;                        /* Initialization of the ICS control register 1 */
  ICSC2 = 0x40;                        /* Initialization of the ICS control register 2 */
  while(!ICSSC_IREFST) {               /* Wait until the source of reference clock is internal clock */
  }
  ICSSC &= (unsigned char)~0xE0;       /* Initialization of the ICS status and control */
  while((ICSSC & 0xC0) != 0x00) {      /* Wait until the FLL switches to Low range DCO mode */
  }
  INTC_WCR = 0x00;                                     
}

Labels (1)
0 Kudos
Reply
1 Reply

360 Views
naldo3
Contributor I

Ok, problem solved.

 

I made a mistake in the hardware design, I do not why but I put a 100nF capacitor in a ground pin between it and general ground...maybe I just looked quickly its pins & connections from the RM.

 

Next time, I will ask a smarter question.

0 Kudos
Reply