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.

CC1312R: How to generate two different PWMs from same timer channels?

Part Number: CC1312R

Dear Sir,

I am using Timer 3, channel a to generate pwm. Now, i am trying to use channel b to generate another PWM which has different frequency. Looks like it generates PWM using Ch a but Ch b is not generating PWM.

The PWM init code is below.

void Init_pwm(void)
{
PWM_init();

PWM_Params_init(&pwmParams);
PWM_Params_init(&beeperPWMParams);

pwmParams.idleLevel = PWM_IDLE_LOW; // Output low when PWM is not running
pwmParams.periodUnits = PWM_PERIOD_US; // Period in microseconds
pwmParams.periodValue = 333333;//1e6; // change this to 100hz the minimum freq can be set is 3hz
pwmParams.dutyUnits = PWM_DUTY_FRACTION; // Duty is in fractional percentage
pwmParams.dutyValue = 50; // 0% initial duty cycle

beeperPWMParams.idleLevel = PWM_IDLE_LOW; // Output low when PWM is not running
beeperPWMParams.periodUnits = PWM_PERIOD_US; // Period in microseconds
beeperPWMParams.periodValue = 200;//1e6; // 1MHz change this to 100hz the minimum freq can be set is 3hz
beeperPWMParams.dutyUnits = PWM_DUTY_FRACTION; // Duty is in fractional percentage
beeperPWMParams.dutyValue = 50; // 0% initial duty cycle


pwm = PWM_open(DRV_CLKIN_PWM, &pwmParams);

beeperPWM = PWM_open(BEEPER_PWM, &beeperPWMParams);

if ((pwm == NULL)||(beeperPWM==NULL))
{
// PWM_open() failed
SubgConPrint("Failed to open PWM Timer\r\n"); //print error
}

PWM_start(beeperPWM);
}

PWM Config is below.

#define CONFIG_PWM_COUNT 2

/*
* ======== pwmCC26XXObjects ========
*/
PWMTimerCC26XX_Object pwmTimerCC26XXObjects[CONFIG_PWM_COUNT];

/*
* ======== pwmCC26XXHWAttrs ========
*/
const PWMTimerCC26XX_HwAttrs pwmTimerCC26XXHWAttrs[CONFIG_PWM_COUNT] = {
/* DRV_CLKIN_PWM */
{
.pwmPin = IOID_25,
.gpTimerUnit = CONFIG_GPTIMER_0
},
/* BEEPER_PWM */
{
.pwmPin = IOID_16,
.gpTimerUnit = CONFIG_GPTIMER_4
},
};

/*
* ======== PWM_config ========
*/
const PWM_Config PWM_config[CONFIG_PWM_COUNT] = {
/* DRV_CLKIN_PWM */
{
.fxnTablePtr = &PWMTimerCC26XX_fxnTable,
.object = &pwmTimerCC26XXObjects[DRV_CLKIN_PWM],
.hwAttrs = &pwmTimerCC26XXHWAttrs[DRV_CLKIN_PWM]
},
/* BEEPER_PWM */
{
.fxnTablePtr = &PWMTimerCC26XX_fxnTable,
.object = &pwmTimerCC26XXObjects[BEEPER_PWM],
.hwAttrs = &pwmTimerCC26XXHWAttrs[BEEPER_PWM]
},
};

Timer config is blow

#define CONFIG_GPTIMER_COUNT 5

/*
* ======== gptimerCC26XXObjects ========
*/
GPTimerCC26XX_Object gptimerCC26XXObjects[CONFIG_GPTIMER_COUNT];

/*
* ======== gptimerCC26XXHWAttrs ========
*/
const GPTimerCC26XX_HWAttrs gptimerCC26XXHWAttrs[CONFIG_GPTIMER_COUNT] = {
/* CONFIG_GPTIMER_0, used by DRV_CLKIN_PWM */
{
.baseAddr = GPT3_BASE,
.intNum = INT_GPT3A,
.intPriority = (~0),
.powerMngrId = PowerCC26XX_PERIPH_GPT3,
.pinMux = GPT_PIN_3A
},
/* CONFIG_GPTIMER_4, used by BEEPER_PWM */
{
.baseAddr = GPT3_BASE,
.intNum = INT_GPT3B,
.intPriority = (~0),
.powerMngrId = PowerCC26XX_PERIPH_GPT3,
.pinMux = GPT_PIN_3B
},
/* CONFIG_GPTIMER_1, used by Timer_For_Hall_Edge_Detect */
{
.baseAddr = GPT1_BASE,
.intNum = INT_GPT1A,
.intPriority = 0x40,
.powerMngrId = PowerCC26XX_PERIPH_GPT1,
.pinMux = GPT_PIN_1A
},
/* CONFIG_GPTIMER_2, used by Ramp_Timer */
{
.baseAddr = GPT1_BASE,
.intNum = INT_GPT1B,
.intPriority = 0x60,
.powerMngrId = PowerCC26XX_PERIPH_GPT1,
.pinMux = GPT_PIN_1B
},
/* CONFIG_GPTIMER_3, used by CONFIG_ADC_TIMER */
{
.baseAddr = GPT0_BASE,
.intNum = INT_GPT0A,
.intPriority = 0xc0,
.powerMngrId = PowerCC26XX_PERIPH_GPT0,
.pinMux = GPT_PIN_0A
},
};

/*
* ======== GPTimer_config ========
*/
const GPTimerCC26XX_Config GPTimerCC26XX_config[CONFIG_GPTIMER_COUNT] = {
/* CONFIG_GPTIMER_0 */
{
.object = &gptimerCC26XXObjects[CONFIG_GPTIMER_0],
.hwAttrs = &gptimerCC26XXHWAttrs[CONFIG_GPTIMER_0],
.timerPart = GPT_A
},
/* CONFIG_GPTIMER_4 */
{
.object = &gptimerCC26XXObjects[CONFIG_GPTIMER_4],
.hwAttrs = &gptimerCC26XXHWAttrs[CONFIG_GPTIMER_4],
.timerPart = GPT_B
},
/* CONFIG_GPTIMER_1 */
{
.object = &gptimerCC26XXObjects[CONFIG_GPTIMER_1],
.hwAttrs = &gptimerCC26XXHWAttrs[CONFIG_GPTIMER_1],
.timerPart = GPT_A
},
/* CONFIG_GPTIMER_2 */
{
.object = &gptimerCC26XXObjects[CONFIG_GPTIMER_2],
.hwAttrs = &gptimerCC26XXHWAttrs[CONFIG_GPTIMER_2],
.timerPart = GPT_B
},
/* CONFIG_GPTIMER_3 */
{
.object = &gptimerCC26XXObjects[CONFIG_GPTIMER_3],
.hwAttrs = &gptimerCC26XXHWAttrs[CONFIG_GPTIMER_3],
.timerPart = GPT_A
},
};

const uint_least8_t CONFIG_GPTIMER_0_CONST = CONFIG_GPTIMER_0;
const uint_least8_t CONFIG_GPTIMER_4_CONST = CONFIG_GPTIMER_4;
const uint_least8_t CONFIG_GPTIMER_1_CONST = CONFIG_GPTIMER_1;
const uint_least8_t CONFIG_GPTIMER_2_CONST = CONFIG_GPTIMER_2;
const uint_least8_t CONFIG_GPTIMER_3_CONST = CONFIG_GPTIMER_3;
const uint_least8_t GPTimer_count = CONFIG_GPTIMER_COUNT;

Please guide me to make it work.

Thanks,

Satyakam.

 

  • Hello Sir,

    I have resolved the issue. it looks like, it does not like if is set the duty cycle in the initialization. So i have stared the pwm with 0 duty cycle and when i need to actually start PWM, i set duty cycle and period. This way it works. 

    Let me know if i am missing something here.

    Thanks,

    satyakam.