ADC

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

ADC

1,223 Views
vinkar
Contributor III

Hello ,

I am using the KL04 (24 pin package). The issue I am having is with the ADC of this chip. I am driving a motor and trying to measure the BEMF. The issue is with the ADC read of the BEMF. The voltage supplied is 8.5V. The VEFHH and VREFL are connected to the Vcc and GND in the 24 pin package. Also I have a LPF of 3K and 10K. So, effectively,  the 8.5V is stepped down to 1.96V.

So, VREFH = 3.3V and hence-forth for 10bit ADC will show 3FF for 3.3V. Which implies for 1.96V I shld get 260(hex). but end up getting 118. I don't think I am having too much impedance loaded up in my pi. The schematic is shown below

free.png

The code for ADC initialisation and read is as shown below -

static void adcInit(void){

                    uint8_t roughReg;

                    uint16_t varRough;

                    uint8_t calibStatus;

                    SIM_SCGC6 |= SIM_SCGC6_ADC0_MASK;

                    ADC0_SC1A = 0;

                    ADC0_SC1A |= 0x80;

                    adcConfig();

                    calibStatus = adcCalib();

                    if(calibStatus == 1){  // calibration successful //

                            varRough =(ADC0_CLP0+ADC0_CLP1+ADC0_CLP2+ADC0_CLP3+ADC0_CLP4+ADC0_CLPS)/2;

                            varRough |=0x8000;

                            ADC0_PG = varRough;

                    }

                    else while(1);

                    adcConfig();

                              

                }

               

                static void adcConfig(void){                         

                    ADC0_CFG1 |= 8;     // 10 bit ADC mode //

                    //ADC0_CFG1 |= ADC_CFG1_MODE(2);

                }

                static uint8_t adcCalib(void){ 

                    uint16_t varRough;

                    uint8_t status;

                    ADC0_SC2 &=~ADC_SC2_ADTRG_MASK;

                    ADC0_SC3 &= ~ADC_SC3_CAL_MASK;

                    ADC0_SC3 |=  ADC_SC3_CAL_MASK;

                    while((ADC0_SC1A & 0x00000080) != 0x00000080);

                    // COCO flag is set //

                    ADC0_SC1A &= ~ADC_SC1_COCO_MASK;

                    status = 1;

                    return(status);

                }

and the adc read -

static uint16_t adcRead(uint8_t adcChannel){

                    switch(adcChannelRead){                                       

                        case 'W':

                        PORTB_PCR1  &= ~PORT_PCR_MUX_MASK;   // --- W ad

                        ADC0_SC1A = 0x05;

                        break;                   

                        case 'V':

                        PORTB_PCR0 &= ~PORT_PCR_MUX_MASK;    // --- V adc

                        ADC0_SC1A = 0x06;

                        break;  

                        case 'U':

                        PORTA_PCR7  &= ~PORT_PCR_MUX_MASK;   // --- U adc

                        ADC0_SC1A = 0x07;

                        break;

                        default:

                        asm("nop");

                        break;

                    }      

                    //ADC0_SC1A |= 0x07;

                    while((ADC0_SC1A & 0x00000080) != 0x00000080);

                    adcDataObt = ADC0_RA;

                    return(adcDataObt);

                }

why is this happening. Am I doing something wrong here.

Labels (1)
Tags (1)
0 Kudos
3 Replies

718 Views
RuiFaria
Contributor III

Hi,

You forgot to show adcConfig() function, are you reading always 0xFFFF from the ADC?


I am using KL15 and i am having problems with the ADC.


Do you have some answers or help from FREESCALE support?


Best Regards,

Rui Faria

0 Kudos

718 Views
vinkar
Contributor III

Hello Rui,

I solved the issue. I can can assist you if you have some issues with your ADC.

R u from Lisbon ?

Vinod

0 Kudos

718 Views
RuiFaria
Contributor III

Hi,

Thanks for your attention. No, i am from Oporto.

Yesterday, i got different values from ADC but they don't make sense to me yet. I am keep trying to developed a simple unit test with the help of Process Expert.

Process Expert ADC Properties

A/D resolution: 16 bits

Conversion Time: 27 us

Low-power mode: off

High-speed conversion mode: on

Asynchro clock output: off

Sample time: 0 = short

Number of converfsions: 1

Interrupt service/event: off

A/D Channels

0 - ADC0_SE8 - Single Ended

1 - ADC0_SE13 - Single Ended

2 - TempSensor - Single Ended

VREF = 3.284V

...in the inputs i suppose to have these voltages:

ADC CH 0 = 2.579V

ADC CH 1 = 1.638V

...and i read from ADC the following values:

ADC CH 0 0xfbf8

ADC CH 1 0xbcf8

ADC CH 2 0x7df8

Best Regards,

Rui Faria

0 Kudos