dears all:
I set TIMER1B to PWM mode; The rest of the configuration is the same, except when different edges are used to capture interrupt update cycles and duty cycles, the phenomenon is different;
1、Code section: PWM period value change mode(ms): 1 -> 2 -> 3 -> 4 ->5 - 4 -> 3 -> 2- > 1 ->2 ... ; duty: 50%
/* timer configuration */ GPIOPinConfigure(GPIO_PL6_T1CCP0); GPIOPinConfigure(GPIO_PL7_T1CCP1); GPIOPinTypeTimer(GPIO_PORTL_BASE, GPIO_PIN_6|GPIO_PIN_7); TimerConfigure(TIMER1_BASE, TIMER_CFG_SPLIT_PAIR|TIMER_CFG_A_PWM|TIMER_CFG_B_PWM); HWREG(TIMER1_BASE + TIMER_O_TBMR)|=0x00000500; // update on the next timeout. TimerControlLevel(TIMER1_BASE,TIMER_B,0); TimerControlEvent(TIMER1_BASE, TIMER_B, TIMER_EVENT_POS_EDGE); //TIMER_EVENT_NEG_EDGE); TimerIntClear(TIMER1_BASE, TIMER_CAPB_EVENT); TimerIntEnable(TIMER1_BASE,TIMER_CAPB_EVENT); IntEnable(INT_TIMER1B); /* timer start */ TimerLoadSet(TIMER1_BASE, TIMER_B, 120000 & 0xFFFF); // 1ms period TimerPrescaleSet(TIMER1_BASE,TIMER_B, (120000 >> 16)&0xff); TimerMatchSet(TIMER1_BASE,TIMER_B, 60000 & 0xFFFF); // 50% duty TimerPrescaleMatchSet(TIMER1_BASE,TIMER_B, (60000 >> 16)&0xff); TimerEnable(TIMER1_BASE, TIMER_B); /* interrupt handle */ void Timer1BIntHandler(void) { static uint32_t period = 120000; // 1ms static uint32_t duty = 0; static uint8_t inc_flag = 1; // printf("timer1B int\n"); if (inc_flag) { period += 120000; if (period >= 600000) { inc_flag = 0; } } else { period -= 120000; if (period <= 120000) { inc_flag = 1; } } duty = period >> 1; TimerLoadSet(TIMER1_BASE, TIMER_B, period&0xffff); // period TimerPrescaleSet(TIMER1_BASE, TIMER_B, (period >> 16)&0xFF); TimerMatchSet(TIMER1_BASE, TIMER_B, duty&0xffff); // duty TimerPrescaleMatchSet(TIMER1_BASE, TIMER_B, (duty >> 16)&0xFF); // TimerIntClear(TIMER1_BASE, TIMER_TIMB_TIMEOUT); TimerIntClear(TIMER1_BASE, TIMER_CAPB_EVENT); }
2、When using the drop edge mode, the normal, waveform is as follows:
3、When using the rising edge mode, anomalies and waveforms appear as follows:
Thanks.