AnsweredAssumed Answered

How can i use ADC conversion-complete interrupt on IAR

Question asked by maju on Sep 7, 2015
Latest reply on Oct 12, 2016 by Hui_Ma

Hello Community,

 

i am new to Cortex-programming, and i wanted to test the 16-bit ADC of te freedom kl25z board. And I am using IAR to develop and debug it.

The setup is 16 bit, continuous-Conversion-Mode, BUS-clock, Clock frequency divided by 8, hardware-averaging enabled with 32 sampels, and differential mode.

Now, i ve got a few problems,

1. COCO-flag (conversion complete) is permanently set

     -> i can not "manually" check whether conversion is finished or not

 

2. conversion complete interrupt does not fire, too

     -> i don't know how to enable them, "asm("CPSIE i");" does not seem to work

     -> void adc0_isr is built to read the ADC0_RA (result) register

#include "common.h"

#include "smc.h"

#include "adc16.h"

#include "isr.h"

 

#define ADC

 

#define EnableInterrupts asm(" CPSIE i");

 

void init_ADC16(void);

 

tADC_Config Master_Adc_Config;

uint32 result0A = 0;

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

int main (void)

{

  EnableInterrupts;

 

  //adc (diff-mode, continuous conversion, 16 bit)

  init_ADC16();

 

 

  while(1){

     /*

      * custom code here

      */

  }

}

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

/*

  *  custom function here

  */

 

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

//also mentioned in isr.h

//as: extern void adc0_isr(void);

 

void adc0_isr(void){

  result0A = ADC0_RA;

};

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

void init_ADC16(void){

 

          // Turn on the ADC0 clock as well as the PDB clocks to test ADC triggered by PDB

            SIM_SCGC6 |= (SIM_SCGC6_ADC0_MASK );

            PMC_REGSC |= PMC_REGSC_BGBE_MASK ;

            // setup the initial ADC default configuration

            Master_Adc_Config.CONFIG1  =0xFC;  //ADLPC_NORMAL           //Config Reg.1

              //| (11<<5) //ADC_CFG1_ADIV(ADIV_8)

              //| (1<<4)  //ADLSMP_LONG

              //| (11<<2) //ADC_CFG1_MODE(MODE_16)

              //| (00<<0); //ADC_CFG1_ADICLK(ADICLK_BUS);

            Master_Adc_Config.CONFIG2  = 0x00; //MUXSEL_ADCA            //Config Reg.2

              //| (0<<3)  //ADACKEN_DISABLED

              //| (0<<2)  //ADHSC_NORMAL

              //| (00<<0); //ADC_CFG2_ADLSTS(ADLSTS_20) ;

            //Status Register

            Master_Adc_Config.STATUS1A = 0x60; //AIEN_ON             //Status Reg SC1A

              //| (1<<5)  //DIFF_ENABLED

              //| (0x00); //Analog chanel 0

            Master_Adc_Config.STATUS2  = 0x00; //ADTRG_SW              //Status Reg SC2

              //| (0<<5)  //ACFE_DISABLED

              //| (0<<4)  //ACFGT_DISABLED

              //| (0<<3)  //ACREN_DISABLED

              //| (0<<2)  //DMA_DISABLED

              //| (00<<0);//ADC_SC2_REFSEL(REFSEL_EXT);

            Master_Adc_Config.STATUS3  = 0x0F;   //CAL_OFF             //Status Reg SC3

              //| (0<<3)      //ADCO_CONTINUOUS

              //| (1<<2)      //AVGE_ENABLED

              //| (11<<0);     //ADC_SC3_AVGS(AVGS_32);

            ADC_Config_Alt(ADC0_BASE_PTR, &Master_Adc_Config);  // config ADC

            ADC_Cal(ADC0_BASE_PTR);                    // do the calibration

            // The structure still has the desired configuration.  So restore it.

            // The calibration makes some adjustments to the

            // configuration of the ADC.  The are now undone:

            // config the ADC again to desired conditions

 

            ADC_Config_Alt(ADC0_BASE_PTR, &Master_Adc_Config);

}

I hope that someone can help me,

Regards

marius

Outcomes