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 定时器1产生四路PWM问题!help !help !help !help !help !

 #include <ioCC2530.h>

void Init_T1_Direction(void)
{
//EA=0;
PERCFG = 0x00; //Timer1位于位置1 P0_3~P0_6
P0SEL |= 0x78; //P03-P06用作外设接口01111000
P0DIR |=0X78; //output
P2DIR = 0XC0; //P0优先作为TIMER1()1st priority: Timer 1 channels 0-1
/*******************************************
 P2DIR   0X00       0X40       0X80                        0XC0  
               P0_6       P0_6         P0_3、P0_6         P0_4、P0_5、P0_6  
********************************************/

/*******************************************
P2DIR :BIT7-6
00 USART0 USART1 TIMER1
01 USART1 USART0 TIMER1
10 TIMER1(channels0-1) USART1 USART0 TIMER1(channels2-3)
11 TIMER1(channels2-3) USART0 USART1 TIMER1(channels0-1)

********************************************/
T1CNTL=0X00;
T1CNTH=0X00; //Timer1 counter


T1CC0L= 0xff; //
T1CC0H= 0x05;

//T1CCTL1=0x1c; //Clear when equal CCRO,Set when equal CCRx,00 101 100
T1CCTL1=0x34; //Set when equal CCRO,Clear when equal CCRx,00 110 100
T1CC1L= 0x7f;
T1CC1H= 0x02;

//T1CCTL2=0x1c;
T1CCTL2=0x34;
T1CC2L= 0x7f;
T1CC2H= 0x02;

//T1CCTL3=0x1c;
T1CCTL3=0x34;
T1CC3L=0x7f;
T1CC3H=0x02;

//T1CCTL4=0x1c;
T1CCTL4=0x34;
T1CC4L= 0x7f;
T1CC4H= 0x02; //

T1CTL =0X00;
T1CTL |=0X0c; // divider=128
T1CTL |= 0x02; //modulo mode and start

}

void main()
{
    Init_T1_Direction();
   while(1) { }
}

程序 如上,配置后不能正常产生四路,当改变 P2DIR配置时(改变Timer1与Usart优先级),P0_3、P0_4、 P0_5、P0_6能产生PWM的如下

  P2DIR                          0X00            0X40                 0X80                            0XC0

 能产生PWM的I/O         P0_6           P0_6                P0_3、P0_6               P0_4、P0_5、P0_6 

附上 Timer1与Usart优先级关系:

/*******************************************
P2DIR :BIT7-6
             00 USART0 USART1 TIMER1
             01 USART1 USART0 TIMER1
            10 TIMER1(channels0-1) USART1 USART0 TIMER1(channels2-3)
            11 TIMER1(channels2-3) USART0 USART1 TIMER1(channels0-1)

 ********************************************/

谢谢!! 

 

 

 

 

 

 

 

 

  • 你好你的这个问题解决了么?  

    定时器1产生4路pwm,通道1不能正常产生pwm。我的qq249034648,很希望得到你的回复,先谢谢你了!!!

  • ok了,依然感谢!

  • 你的问题怎么解决的    我也是这个问题,望解答一下,先谢过啦

  • 使用TIM1的不同通道产生不同的PWM信号,例如:配置P0_2、P0_3、P0_4、P0_5、P0_6分别配置不同的PWM信号等。

    部分相关配置如下:

    PERCFG &= ~0x40; // Select Timer 1 Alternative 0 location
    PERCFG |= 0x03; // Move USART0 and USART1 to Alternative 2 location to allow all Timer 1 channels on P0
    P2DIR = (P2DIR & ~0xC0) | 0x80; // Give priority to Timer 1
    P0SEL |= 0x3C;  // Set P0_2-P0_5 to peripheral

    T1CC0L = 0xff;   // PWM signal period
    T1CC0H = 0x7f;

    T1CCTL0 = 0x1c; // Channel 0 in compare mode, Set output on compare-up, clear on 0 (50% duty cycle)

    T1CC1L = 0x78;  // PWM duty cycle, Channel 1 (P0_3)
    T1CC1H = 0x10;

    T1CCTL1 = 0x1c; // Channel 1 in compare mode, Set output on compare-up, clear on compare-down

    T1CC2L = 0x78;  // PWM duty cycle, Channel 2 (P0_4)
    T1CC2H = 0x10;

    T1CCTL2 = 0x1c; // Channel 2 in compare mode, Set output on compare-up, clear on compare-down

    T1CC3L = 0x78;  // PWM duty cycle, Channel 3 (P0_4)
    T1CC3H = 0x10;

    T1CCTL3 = 0x1c; // Channel 3 in compare mode, Set output on compare-up, clear on compare-down

    T1CC4L = 0x78;  // PWM duty cycle, Channel 4 (P0_5)
    T1CC4H = 0x10;

    T1CCTL4 = 0x1c; // Channel 4 in compare mode, Set output on compare-up, clear on compare-down

    T1CTL |= 0x0f; // divide with 128 and to do i up-down mode

    注意:

    on P0_2 you can only get 50% duty cycle unless you can use free-running mode, which will limit the available settings for the period. The period you are using now is 131 ms, provided that you use the maximum tick speed (32 MHz). If you change to free running mode, you have to choose between a period of 65.5 ms and 262 ms using the maximum tick speed. But if you use a tick speed of 16 MHz, you can get a period of 131 ms in free-running mode using a presacler of 32. See the CLKCONCMD register on how to change the tick speed.

     

    If you want more concrete advice on this, please let me know what your requirements are for the period and the duty cycle.

     

    A program can look something like this. Here, I have set up the same duty cycle on all channels except channel 0. To use different duty cycle for some of the channels, just change the value of T1CCnL/T1CCnH for those channels.