Unable to wake up MCU (MC9RS08KA4) via ADC automatic compare enable

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

Unable to wake up MCU (MC9RS08KA4) via ADC automatic compare enable

510 Views
admin
Specialist II

Unable to wake up MCU (MC9RS08KA4) via asynchronous interrupt ADC automatic compare enable.

When compare value is set for a particular value and ADC compare function is enabled to compare for greater value, then entering in STOP mode. The MCU is not waking up as the voltage is crossed and the MCU is still in stop mode (as the LED is not toggling). Following is the code (in which LED_Green should turn OFF when i connect AC adapter of 9V spec) :

 

//INCLUDES ///////////////////////////////////////////////////////////                   

//---------------------------------------------------------------------                   

#include "derivative.h"       // Gives acces to all MCU registers


//DEFINES ////////////////////////////////////////////////////////////                   

//---------------------------------------------------------------------                   

#define SEL_V_BATT 0b00000110 //AN6 -> V_batSNS

#define PV_Voltage    0b00000001 //AN1 -> PV_SNS

 

// GLOBAL VARIABLES ///////////////////////////////////////////////////                   

//---------------------------------------------------------------------                   

unsigned int Battery_voltage = 0, Panel_voltage = 0, i = 0;


// FUNCTION HEADERS ///////////////////////////////////////////////////                   

//---------------------------------------------------------------------                   

void main(void);

void MCU_Init(void);                        

void LED_ON_RED(void);

void LED_ON_GREEN(void);

void LED_OFF_GREEN(void);

void LED_ON_RED_GREEN(void);

word read_adc(byte);

 

 

// *** MAIN ***********************************************************            1       

//---------------------------------------------------------------------                   

void main(void)                                                                           

{                                                                                         

  

   MCU_Init();      // MCU Initialization; has to be done prior to anything else

   LED_ON_RED_GREEN();

   //Panel_voltage = read_adc(PV_Voltage);

   //ADCSC2_ACFE = 0x1;  /* enable compare */

   //Panel_voltage = read_adc(PV_Voltage);

   ++i;

   __asm STOP

   //Panel_voltage = read_adc(PV_Voltage);

   while(1)

   {

      ++i;

      LED_OFF_GREEN();

   }

 

 

}     //MAIN

 

 

//---------------------------------

word read_adc(byte chan)                     // Analog-to-Digital Converter byte read: enter channel to read

{

    ADCSC1 = chan;

   

    while (!ADCSC1_COCO);

    return ADCR;

}

 

/* LED_ON_GREEN */

void LED_ON_GREEN()

{

  PTBD_PTBD6   = 0x1;    /* PTB6 ON_GREEN */                                 

}

 

/* LED_OFF_GREEN */

void LED_OFF_GREEN()

{

  PTBD_PTBD6   = 0x0;    /* PTB6 ON_GREEN */                                 

}

 

/* LED_ON_RED */

void LED_ON_RED() 

{

  PTBD_PTBD7   = 0x1;    /* PTB7 ON_RED */                                 

}

 

/* LED_ON_RED_GREEN */

void LED_ON_RED_GREEN(void)

{

  PTBD_PTBD7   = 0x1;    /* PTB7 ON_RED */

  PTBD_PTBD6   = 0x1;    /* PTB6 ON_GREEN */ 

}

 

// FUNCTION BODIES ////////////////////////////////////////////////////                   

//---------------------------------------------------------------------                   

void MCU_Init(void)

{

    SOPT=0x2F;                 // disable COP, enable Stop, map TPMCH1 to PTB5;TPMCH0 to PTB4 Reset & Bkgd = BDM

    SPMSC1=0x00;  

   

    SPMSC1_LVDSE = 0x1;    /* LVD enable during STOP mode */

    SPMSC1_LVDE = 0x1;     /* LVD logic level enable */

 

    //*************************** System Clock Init Start***************************************************************

    ICSTRM=NVICSTRM;             // initialize ICSTRM register from NV_ICSTRM

    ICSSC =NVFTRIM;              // initialize ICSSC  register from NV_FTRIM

    ICSC1=0x04;                  /* CLK_Disable in STOP mode */

    ICSC1_IREFSTEN = 0x1;        /* Internal reference CLK_Enable in STOP mode */

    ICSC1_IRCLKEN = 0x1;         /* needs to be enabled to enable ICSC1_IREFSTEN */

    ICSC2=0x00;                  //Full bus speed /1, Trim*512=39062.5Hz*512=20.000MHz (10.000MHz bus)

 

 

    //*************************** ADC Init Start *************************************************************************

      ADCCFG=0x9B;  //0x0B;            /* High speed, Prescale = 1, short sample, 10-bit mode, f_ADC = Asynchronous_clk */

      ADCSC2_ACFE = 0x1;      /* Compare function Enable */

      ADCSC2_ACFGT = 0x1;     /* when compare value is higher than Compare value */

      //ADCSC2_ACFGT = 0x0;     /* when compare value is lower than compare threshold value */

      ADCSC1_AIEN = 0x1;      /* Conversion complete Interrupt Enable */

      ADCSC1_ADCO = 0x1;      /* Continous convertion Enable */

      ADCSC1_ADCH = 0b00001;  /* Selecting I/P channel AD1 */

      ADCCV = 0x50;  //2.83V //0xB7; //6.5V //0xC5;           /* Compare Threshold 7V */

      APCTL1_ADPC1 = 0x1;     /* AD1 pin I/O control Disable  */

   

    //*************************** GPIO Init Start**************************************************************************

    PTBD=0x00;                   // PORTB  off by default                                  

    PTBDD=0xF0;   //1111 0000    // PORTB is an (PTB0/1/2/3)input/(PTB4/5/6/7)output as schematic

 

  PTBD_PTBD6   = 0x0;    /* PTB6 OFF by default */                                 

  PTBDD_PTBDD6 = 0x1;    /* PTB6 is an output */

  PTBSE_PTBSE6 = 0x1;    /* PTB6 -> Output slew rate control enabled */

  PTBDS_PTBDS6 = 0x1;    /* PTB6 -> High output drive enabled */        

 

 

  PTBD_PTBD7   = 0x0;    /* PTB7 OFF by default */                                 

  PTBDD_PTBDD7 = 0x1;    /* PTB7 is an output */

  PTBSE_PTBSE7 = 0x1;    /* PTB7 -> Output slew rate control enabled */

  PTBDS_PTBDS7 = 0x1;    /* PTB7 -> High output drive enabled */        

}    //MCU_Init();

 

Labels (1)
0 Kudos
0 Replies