Ed Jiang

AN4424 MP16 interrupt problem

Discussion created by Ed Jiang on Sep 27, 2012
Latest reply on Nov 2, 2012 by Gang Chen

Hi Guys,

 

I followed the code by the second example (p.6-7). Unfortunately, it never came out the waveform as shown in figure 6. I guess it is the problem of interrupt. Following is the complete codes. Could you please give me some hints to correct the problem? Thanks in advance!

 

Ed

---------------------------------------------------------------------------------------------------

/*  error existing!!!

GENERATE PULSE OUTPUT STRINGS (CONTINUOUS MODE)

PULSE WIDTH = (DelayB - DelayA)*PDB_freq

PULSE PERIOD = PDB COUNTER MODULO * PDB_freq

PERIOD = RTC overflow period (RTC clock)

*/

 

#include <hidef.h> /* for EnableInterrupts macro */

#include "derivative.h" /* include peripheral declarations */

 

 

void rtc_init(void);

void pdb1_init(void);

 

char pdb1_cont_times = 0;

 

void main(void) {

 

  SOPT1 = SOPT1_BKGDPE_MASK | SOPT1_RSTPE_MASK;//Disable COP,disable stop,Enable Reset

  //EnableInterrupts; /* enable interrupts */

  /* include your code here */

  rtc_init();

  pdb1_init();

  pdb1_cont_times = 0;

  PTDD_PTDD3 = 0;

  EnableInterrupts;

  for(;;) {

    //__RESET_WATCHDOG(); /* feeds the dog */

  } /* loop forever */

  /* please make sure that you never leave main */

}

 

void rtc_init(void) {

    /* Select the 1-KHz clock as the clock source, prescaler is 10 and modulo is 2 */

    /* So that it triggers every 20 ms */

    RTCMOD = 0x01;

    /* RTCSC: RTIF(b7)=0,RTCLKS(b6:b5)=0,RTIE(b4)=0,RTCPS(b3:b0)=11 (0xB) */

    /* RTCLKS = 0, Select the 1 KHz low power oscillator as clock source */

    /* RTCPS = 11, RTC prescaler is 10 */

    RTCSC = 0x0B;

}

 

void pdb1_init(void) {

    PDB1CTRL1 = 0x00;

    //PDB1CTRL2 = 0x00U;

    PDB1CTRL2 = 0x02;    //Enable continuous mode

    PDB1MOD = 0x20;

    //PDB1DLYA = 0x01U;

    //PDB1DLYB = 0xFFFFU;

    PDB1DLYA = 0x01;

    PDB1DLYB = 0xff;

    PDB1CTRL1_LDOK = 1;

    //PDB1SCR = 0xC0U;

    PDB1SCR = 0xF0;    //Enable counter overflow interrupt

}

 

void interrupt rtc_isr(void){

    PTDD_PTDD3 ^= 1;

    RTCSC_RTIF = 1;        /* Clear RTC interrupt */

}

 

void interrupt pdb1_isr(void){

    if(PDB1SCR_COF == 1){

        PDB1SCR_COF = 1;

        if(PDB1CTRL2_CONT)

        {

            if(++pdb1_cont_times >= 5)

            {

                PDB1CTRL2_CONT = 0;    //Disable continuous mode

                pdb1_cont_times =0;

            }

        }else

        {

            PDB1CTRL2_CONT = 1;

            pdb1_cont_times = 0;

        }

    }

    if(PDB1SCR_DAF == 1)

        PDB1SCR_DAF = 1;

    if(PDB1SCR_DBF == 1)

        PDB1SCR_DBF = 1;

}


---------------------------------------------------------------------------------------------------

Outcomes