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.

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

Other Parts Discussed in Thread: CC2530

     目前有一个项目,需要使用到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; 

}

  • 放在协议栈中配置,P1.4 没有输出PWM,一直是低电平输出,能否看看配置是否正确?
  • 您可以试一下以下链接的代码 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 location
    P2SEL |=0x20;
    P2DIR |= 0xC0; // Give priority to Timer 1 channel2-3
    P1SEL |= BV(4); // Set P1_4 to peripheral, Timer 1,channel 2
    P1DIR |= BV(4);

    T3CTL &= ~0x10; // Stop timer 3 (if it was running)
    T3CTL |= 0x04; // Clear timer 3
    T3CTL &= ~0x08; // Disable Timer 3 overflow interrupts
    T3CTL |= 0x03; // Timer 3 mode = 3 - Up/Down

    T3CCTL1 &= ~0x40; // Disable channel 0 interrupts
    T3CCTL1 |= 0x04; // Ch0 mode = compare
    T3CCTL1 |= 0x10; // Ch0 output compare mode = toggle on compare

    T3CTL &= ~0xE0; // Clear Prescaler divider value
    T3CTL |= 0xA0; //Set Prescaler divider value = Tick frequency /32
    T3CC0 = 128; //Set ticks = 128

    // Start timer
    T3CTL |= 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 location
    P2DIR = (P2DIR & ~0xC0) | 0x80; // Give priority to Timer 1
    P1SEL |= BV(1); // Set P1_1 to peripheral

    T1CC0L = 0x3A; // PWM signal period
    T1CC0H = 0x01;

    T1CC1L = 0x9D; // PWM duty cycle
    T1CC1H = 0x00;

    T1CCTL1 = 0x1c;

    T1CTL |= (BV(2)|0x03); // divide with 128 and to do i up-down mode