Hello Gang,
Thanks for quick replying. You are right, there are some errors in the code. I corrected these errors and now it looks nearly the same as in the app. note. However, the output waveform is still different from Fig 6. I also attach the screenshoot of the waveform. What would be the reason?
(BTW, example 1 works out exactly the same results as shown in Fig 4 and 5. )
----------------------------------------------------------------------------------
/* 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;
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 = 0x2000;
//PDB1DLYA = 0x01U;
//PDB1DLYB = 0xFFFFU;
PDB1DLYA = 0x01;
PDB1DLYB = 0x1000;
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;
}
----------------------------------------------------------------------------------
