TI中文支持网
TI专业的中文技术问题搜集分享网站

cc2530 怎样在协议栈中使用timer3 P1.4引脚输出PWM

     目前有一个项目,需要使用到5路PWM,需要使用timer3 的P1.4作为PWM的输出,在代码中模仿TIMER1 的初始化,添加代码,但是使用示波器为检测到有波形输出,请帮忙看看哪里出了问题,使用的是compare mode ,代码如下:

引脚初始化

P1 &= ~( 0x10);
P1DIR |= (0x10);
P1INP&= ~(0x10);
//DISABLE_LAMP;
P1DIR |= 0x10;
PERCFG &= ~(0x20);
P2SEL |= 0x20;

添加timer3 的初始化
void HalTimer3Init(halTimerCBack_t cBack)
{
T3CCTL0 = 0; /* Make sure interrupts are disabled */
T3CCTL1 = 0; /* Make sure interrupts are disabled */
/* Setup prescale & clock for timer3 */
halTimerRecord[HW_TIMER_3].prescale = HAL_TIMER34_8_TC_DIV1; //HAL_TIMER3_8_PRESCALE;
halTimerRecord[HW_TIMER_3].clock = HAL_TIMER_32MHZ;
halTimerRecord[HW_TIMER_3].prescaleVal = HAL_TIMER4_8_PRESCALE_VAL;

/* Setup Timer3 Channel structure */
//halTimerChannel[HW_TIMER_3].TxCCTL = TCHN_T3CCTL;
//halTimerChannel[HW_TIMER_3].TxCCL = TCHN_T3CCL;
//halTimerChannel[HW_TIMER_3].TxCCH = TCHN_T3CCH;
//halTimerChannel[HW_TIMER_3].TxOVF = TCNH_T3OVF;
//halTimerChannel[HW_TIMER_3].ovfbit = TCHN_T3OVFBIT;
//halTimerChannel[HW_TIMER_3].intbit = TCHN_T3INTBIT;

halTimerRecord[HW_TIMER_3].configured = TRUE;
halTimerRecord[HW_TIMER_3].opMode = 0x02; //HAL_TIMER1_OPMODE_UPDOWN;
halTimerRecord[HW_TIMER_3].channel = 0;
halTimerRecord[HW_TIMER_3].channelMode = 0;
halTimerRecord[HW_TIMER_3].intEnable = FALSE;
halTimerRecord[HW_TIMER_3].callBackFunc = cBack;

Timer3MaxCount = halTimer3SetPeriod (1000);

halTimerSetPrescale (HW_TIMER_3, halTimerRecord[HW_TIMER_3].prescale);
halTimerSetChannelMode (HW_TIMER_3, halTimerRecord[HW_TIMER_3].channelMode);

*(halTimer3Channel[0].TxCCTL + channel) = 0x2C;

halTimer3SetChannelDuty (HAL_T1_CH1, 0);

T3CTL = 0x1c; 

}

Viki Shi:

参考下这边类似贴: e2echina.ti.com/…/52977

user4675303:

回复 Viki Shi:

放在协议栈中配置,P1.4 没有输出PWM,一直是低电平输出,能否看看配置是否正确?

Susan Yang:

回复 user4675303:

您可以试一下以下链接的代码 sunmaysky.blogspot.com/…/how-to-output-pwm-from-cc2530.html

Refer to CC253x/4x User's Guide. The following sample code can send PWM to P1_4.

PERCFG &= (~(0x20)); // Select Timer 3 Alternative 1 locationP2SEL |=0x20;P2DIR |= 0xC0;// Give priority to Timer 1 channel2-3P1SEL |= BV(4);// Set P1_4 to peripheral, Timer 1,channel 2P1DIR |= BV(4);
T3CTL &= ~0x10;// Stop timer 3 (if it was running)T3CTL |= 0x04;// Clear timer 3T3CTL &= ~0x08;// Disable Timer 3 overflow interruptsT3CTL |= 0x03;// Timer 3 mode = 3 – Up/Down
T3CCTL1 &= ~0x40;// Disable channel 0 interruptsT3CCTL1 |= 0x04;// Ch0 mode = compareT3CCTL1 |= 0x10;// Ch0 output compare mode = toggle on compare
T3CTL &= ~0xE0;// Clear Prescaler divider valueT3CTL |= 0xA0;//Set Prescaler divider value = Tick frequency /32T3CC0 = 128;//Set ticks = 128
// Start timerT3CTL |= 0x10;

Then, the following example shows you how you output 6.5K PWM with 50% duty cycle to P1.1 with CC2530 Timer 1.
PERCFG |= BV(6); // Select Timer 1 Alternative 2 locationP2DIR = (P2DIR & ~0xC0) | 0x80; // Give priority to Timer 1P1SEL |= BV(1);// Set P1_1 to peripheral
T1CC0L = 0x3A;// PWM signal periodT1CC0H = 0x01;
T1CC1L = 0x9D;// PWM duty cycleT1CC1H = 0x00;
T1CCTL1 = 0x1c;
T1CTL |= (BV(2)|0x03); // divide with 128 and to do i up-down mode

赞(0)
未经允许不得转载:TI中文支持网 » cc2530 怎样在协议栈中使用timer3 P1.4引脚输出PWM
分享到: 更多 (0)