This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

PWM causing Issue

Other Parts Discussed in Thread: CC2538

Hi all,

I am facing issue after PWM generation . PWM is affecting other process. 

My project is to count the number of pulses in an I/O pin and give warning according to the pulse rate.I am using CC2538 running at 32kHz, with sleep mode. The pulse rate in my case is 0-250 kHz. Threshold value is 75 kHz, so after 75 kHz i generate PWM to generate alarm tone in a speaker. PWM frequency is 1.5 kHz.

The processor will be in sleep for 5sec, then wakes-up and process the calculations and go to sleep mode again.

Till125 kHz with PWM ON iam getting the correct count. For 150 kHz with PWM ON, iam getting as 74 kHz. But for the same freq(150 kHz) with PWM OFF, i am getting the correct count. Till 250 kHz with PWM OFF, i am getting the correct count. But PWM ON is causing the issue.

I am counting the pulses in an interrupt handler and PWM is hardware driven. No interrupt for PWM. Single frequency(1.5 kHz) iam generating on PWM. 

I am configuring GPTimer1 in PWM mode and just turning ON the Timer1.

The Timer Configuration code is :  

void
GPTimer1Init(void)
{
        HWREG(IOC_GPT1OCP1) = IOC_MUX_OUT_SEL_GPT1_ICP1;
  
	SysCtrlPeripheralEnable(SYS_CTRL_PERIPH_GPT1);
        
        GPIOPinTypeTimer(GPIO_D_BASE, GPIO_PIN_0);      
        IOCPinConfigPeriphOutput(GPIO_D_BASE, GPIO_PIN_0, IOC_MUX_OUT_SEL_GPT1_ICP1);                  

	TimerDisable(GPTIMER1_BASE, GPTIMER_BOTH);

	TimerIntDisable(GPTIMER1_BASE, 0);
        
        TimerConfigure(GPTIMER1_BASE, GPTIMER_CFG_SPLIT_PAIR | GPTIMER_CFG_A_PWM | GPTIMER_CFG_B_PERIODIC);

	HWREG(GPTIMER1_BASE + GPTIMER_O_CTL) |= 0x02;				        //freezes on halting

	TimerPrescaleSet(GPTIMER1_BASE, GPTIMER_A, 50);
        TimerPrescaleSet(GPTIMER1_BASE, GPTIMER_B, 200);
        
        TimerMatchSet(GPTIMER1_BASE, GPTIMER_A, 0x27FF);

        TimerLoadSet(GPTIMER1_BASE, GPTIMER_A, 0xFFF);
        
        HWREG(IOC_GPT1OCP1) = IOC_MUX_OUT_SEL_GPT1_ICP1;
        
        HWREG(GPTIMER1_BASE + GPTIMER_O_TAMR) &= ~(GPTIMER_TAMR_TAPWMIE);

//        TimerEnable(GPTIMER1_BASE, GPTIMER_A);
}

The PWM generation is working fine. But it is affecting the High pulse count. Even in sleep mode PWM is generating.

Timer will be enabled on High pulse rate only.

Some Questios too-

  • Isn't the PWM hardware driven or on timeout weather it affect the controller.

  • Hi,

    What is the system clock set to (max: 32MHz) ? Do you see the issue with sleep mode disabled ? Since the threshold is set to 75KHz and  input 150Hz pulse is getting calculated as 74Khz , does it mean the PWM Timer is never enabled for input pulse >150KHz ?

    Saurabh

  • System Clock is 32Khz and peripheral clock is 16kHz  (since on sleep mode system clock is 16kHz).

    Thanks for the question anyway. It solved the problem.

    On giving 150kHz., it first counts as 150kHz and turns on the PWM. But on turning in. it was repeatedly turning on the pwm. This caused the issue. Now I have cleared it ,its working fine.