MC9S08DZ60 ADC interrupt won't work properly

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

MC9S08DZ60 ADC interrupt won't work properly

Jump to solution
1,636 Views
ohanica
Contributor III
Hello!
 
I'm back again with another problem debugging my MC9S08DZ60.
After I managed to get the timer-interrupt working properly, I try to make use of the ADC-interrupt. what I want to do is making an ADC-conversion on channel12, and turning on a LED in the ADC-ISR. This ADC-ISR is configured to run when the conversion is complete ADIEN-flag.
 
When I debug the code in the target-HW, i.e. on the microcontroller-board, everything works as I want to. The ISR starts after the line
 
ADCSC1_ADCH = 12; 
 
the LED turns on (LEDs are active low-type) and the program continues to execute with the line "aux = 5;". So far so good. When the microcontroller is in normal run mode, the LED doas not turn on, which means the ISR is even not executed. Why? It should start at some time after the conversion start - like in BDM-mode.
 
Does somebody have some hints/tips why it does not work in normal run mode?
 
Thanks,
Johannes
 
PS: here's the code:
Code:
#include  /* for EnableInterrupts macro */#include "derivative.h" /* include peripheral declarations *//*----------------------------------------------------------definitions ------------------------------------------------ -----------------------------------------------------------*/typedef unsigned char   UINT8;typedef signed char     SINT8;typedef unsigned int    UINT16;typedef int             SINT16;typedef unsigned long int UINT32;typedef long int        SINT32;#define TRESHOLD12 512   //ca. 2,5V#define TRESHOLD13 256   //ca. 1,25V/*----------------------------------------------------------Interrupt Vector Numbers definitions---------------------------------------------------------------------------------- */#define ISR_VEC_TPM1OVF 11#define ISR_VEC_ADC 23/*----------------------------------------------------------define LED's --------------------------------------------------------------------------------------------------------- */#define LED2 PTBD_PTBD3#define LED1 PTCD_PTCD5/*----------------------------------------------------------globals -------------------------------------------------------------------------------------------------------------- */UINT16 ADC_RESULT;/*----------------------------------------------------------interrupts ------------------------------------------------- -----------------------------------------------------------*/interrupt 23  void intADC(void)  //ISR_VEC_TPM1OVF{    ADC_RESULT = ADCR;     LED1 = 0;           // LED1 on    }void init_adc(void) {  ADCCFG_ADLPC  = 0;    // high speed, no low power consumption  ADCCFG_ADIV   = 1;    // clock/2  ADCCFG_ADLSMP = 1;    // long sample time  ADCCFG_MODE   = 0x02; // 10bit-mode  ADCCFG_ADICLK = 0;    // i/o bus clock    ADCSC2_ADTRG  = 0;    // software trigger  ADCSC2_ACFE   = 0;    // disable compare function  ADCSC2_ACFGT  = 0;    // compare function greater than disabled    ADCSC1_AIEN   = 1;    // enable ADC Interrupt  //ADCSC1_AIEN = 0;    // disable ADC Interrupt  ADCSC1_ADCH   = 0x1f; // disable ADC  ADCSC1_ADCO   = 0;    // enable single conversion (continuous conversions disabled)   LED2 = 1;   LED2 = 0;      APCTL1        = 0x00;   APCTL2_ADPC12 = 1;    // disable I/O-control on AD-ports 12 and 13   APCTL2_ADPC13 = 1;    // all other ports remain GPIOs.}/* main -------------------------------------------------- */void main(void) {  UINT16 ADC12;  UINT8 aux;      PTBDD_PTBDD3 = 1;      // configure Ports with green led as outputs  PTCDD_PTCDD5 = 1;    LED1 = 1;              // turn off LED1  LED2 = 0;     init_adc();    EnableInterrupts; /* enable interrupts */  /* include your code here */    for(;;)   {    //start conversion on channel 12 --------------------------    ADCSC1_ADCH = 12;              //dummy operations    aux=5;            // interrupt occurs here when debugging in realt time with the P&E Micro debuger    aux=6+aux;           ADC12=ADC_RESULT;    //set LED according to ADC-treshold    if(ADC12>TRESHOLD12)       LED2 = 0;    else      LED2 = 1;      __RESET_WATCHDOG(); /* feeds the dog */  } /* loop forever */    /* please make sure that you never leave main */}

 
 
 
 
 


Message Edited by ohanica on 2007-07-16 08:26 AM

Message Edited by ohanica on 2007-07-16 08:26 AM
Labels (1)
Tags (1)
0 Kudos
1 Solution
374 Views
ohanica
Contributor III
Hello again,
 
incredible. Shortly after I posted the new thread I found a/the solution. Even if I use the ADC-ISR, I have to wait for the COCO-flag after starting the conversion. Apperently the uC has a problem when reading the ADCRx bytes before a conversion is complete (first time), so he does not execute the programm correctly...
 
So just change the code
Code:
          .          .          .//start conversion on channel 12 --------------------------    ADCSC1_ADCH = 12;              //dummy operations    aux=5;            // interrupt occurs here when debugging in realt time with the P&E Micro debuger    aux=6+aux;           ADC12=ADC_RESULT;    //set LED according to ADC-treshold    if(ADC12>TRESHOLD12)           .          .          .

 
into
Code:
          .          .          . //start conversion on channel 12 --------------------------    ADCSC1_ADCH = 12;              //wait until COCO-bit is set.            while (!ADCSC1_COCO)     {              //just wait, do nothing    }        aux=5;    aux=6+aux;            ADC12=ADC_RESULT;    //set LED according to ADC-treshold    if(ADC12>TRESHOLD12)           .          .          .
This means that in BDM mode, while stepping through the lines manually the uC had time enough to do conversion, and read the ADCRx bytes correctly but when running in normal run mode he did not.
 
I did not find anything in the datasheet to point me to this "feature" :smileyhappy: . Maybe I did not search enough.
With AVR-uCs for example this problem does not occur. (...grrrr I'm allways comparing to what I'm used to... )
 
greetx,
Johannes

View solution in original post

0 Kudos
1 Reply
375 Views
ohanica
Contributor III
Hello again,
 
incredible. Shortly after I posted the new thread I found a/the solution. Even if I use the ADC-ISR, I have to wait for the COCO-flag after starting the conversion. Apperently the uC has a problem when reading the ADCRx bytes before a conversion is complete (first time), so he does not execute the programm correctly...
 
So just change the code
Code:
          .          .          .//start conversion on channel 12 --------------------------    ADCSC1_ADCH = 12;              //dummy operations    aux=5;            // interrupt occurs here when debugging in realt time with the P&E Micro debuger    aux=6+aux;           ADC12=ADC_RESULT;    //set LED according to ADC-treshold    if(ADC12>TRESHOLD12)           .          .          .

 
into
Code:
          .          .          . //start conversion on channel 12 --------------------------    ADCSC1_ADCH = 12;              //wait until COCO-bit is set.            while (!ADCSC1_COCO)     {              //just wait, do nothing    }        aux=5;    aux=6+aux;            ADC12=ADC_RESULT;    //set LED according to ADC-treshold    if(ADC12>TRESHOLD12)           .          .          .
This means that in BDM mode, while stepping through the lines manually the uC had time enough to do conversion, and read the ADCRx bytes correctly but when running in normal run mode he did not.
 
I did not find anything in the datasheet to point me to this "feature" :smileyhappy: . Maybe I did not search enough.
With AVR-uCs for example this problem does not occur. (...grrrr I'm allways comparing to what I'm used to... )
 
greetx,
Johannes
0 Kudos