微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 无线和射频 > TI Zigbee设计交流 > 如何在zstack 2530 2.3.0-1.4.0 加入Timer3 ,产生PWM信号

如何在zstack 2530 2.3.0-1.4.0 加入Timer3 ,产生PWM信号

时间:10-02 整理:3721RD 点击:

大家好~ 

     我想在zstack 2530 2.3.0-1.4.0的end device 用Time3 控制P1.3输出一个PWM波形。在裸机上已经实现功能,但是在协议栈里加入同样的代码后就不行了,困惑了好几天~ 希望大家能帮下~ 谢谢~

方便把代码贴出来吗?这里贴一份使用timer 3控制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_0 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;

谢谢回复,已经可以了~不过最终还是参照ZLL里Timer1 的控制,再加自己修改,才实现的。下面的ZLL里的timer1初始化代码

T1CCTL0 = 0; /* Make sure interrupts are disabled */
T1CCTL1 = 0; /* Make sure interrupts are disabled */
T1CCTL2 = 0; /* Make sure interrupts are disabled */
T1CCTL3 = 0; /* Make sure interrupts are disabled */
T1CCTL4 = 0; /* Make sure interrupts are disabled */

/* Setup prescale & clock for timer0 */
halTimerRecord[HW_TIMER_1].prescale = HAL_TIMER1_16_PRESCALE;
halTimerRecord[HW_TIMER_1].clock = HAL_TIMER_32MHZ;
halTimerRecord[HW_TIMER_1].prescaleVal = HAL_TIMER1_16_PRESCALE_VAL;

/* Setup Timer1 Channel structure */
halTimer1Channel[0].TxCCTL = TCHN_T1CCTL;
halTimer1Channel[0].TxCCL = TCHN_T1CCL;
halTimer1Channel[0].TxCCH = TCHN_T1CCH;

halTimerRecord[HW_TIMER_1].configured = TRUE;
halTimerRecord[HW_TIMER_1].opMode = HAL_TIMER1_OPMODE_UPDOWN;
halTimerRecord[HW_TIMER_1].channel = 0;
halTimerRecord[HW_TIMER_1].channelMode = 0;
halTimerRecord[HW_TIMER_1].intEnable = FALSE;
halTimerRecord[HW_TIMER_1].callBackFunc = cBack;
Timer1MaxCount = halTimer1SetPeriod (4292); // 233Hz

halTimerSetPrescale (HW_TIMER_1, halTimerRecord[HW_TIMER_1].prescale);
halTimerSetChannelMode (HW_TIMER_1, halTimerRecord[HW_TIMER_1].channelMode);
halTimer1SetChannelCCTL(HAL_T1_CH0, 0, 1, HAL_TIMER1_CH0_CMP_MODE_SET_ON_COMP, 1, HAL_TIMER1_CH_CAP_MODE_NO);
halTimer1SetChannelCCTL(HAL_T1_CH1, 0, 1, HAL_TIMER1_CHn_CMP_MODE_CLR_ON_COMP_SET_ON_0, 1, HAL_TIMER1_CH_CAP_MODE_NO);
halTimer1SetChannelCCTL(HAL_T1_CH2, 0, 1, HAL_TIMER1_CHn_CMP_MODE_CLR_ON_COMP_SET_ON_0, 1, HAL_TIMER1_CH_CAP_MODE_NO);
halTimer1SetChannelCCTL(HAL_T1_CH3, 0, 1, HAL_TIMER1_CHn_CMP_MODE_CLR_ON_COMP_SET_ON_0, 1, HAL_TIMER1_CH_CAP_MODE_NO);
halTimer1SetChannelCCTL(HAL_T1_CH4, 0, 1, HAL_TIMER1_CHn_CMP_MODE_CLR_ON_COMP_SET_ON_0, 1, HAL_TIMER1_CH_CAP_MODE_NO);

halTimer1SetChannelDuty (HAL_T1_CH1, 0);
halTimer1SetChannelDuty (HAL_T1_CH2, 0);
halTimer1SetChannelDuty (HAL_T1_CH3, 0);
halTimer1SetChannelDuty (HAL_T1_CH4, 0);


/* set timer 1 operating mode */
T1CTL &= ~(HAL_TIMER1_OPMODE_BITS);
T1CTL |= HAL_TIMER1_OPMODE_UPDOWN;

祝贺~感谢分享代码

你好,我正在学习zigbee,准备在z-stack中添加Timer1定时中断,采样ADC数据,但是参考hal_timer.c中的函数,还是没有实现进入timer1的回调函数。请问这个ZLL中是如何实现timer1操作的?能否将代码给我发一份:675412313@qq.com,谢谢啦!

能分享一下ZLL的例程吗?有些东西还是没看懂。很感谢了!1456448770@qq.com

To michael XU

如果你用了协议栈,那么建议用osal的定时函数来完成这个工作,不需要在硬件层操作定时器 osal_start_timerEx( ) 

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top