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在Z-STACK中使用定时器

Other Parts Discussed in Thread: CC2530, Z-STACK

1.如果CC2530一直使用定时器计时,功率大概是多少?

2.z-stack协议栈中,osal_start_timerEx()这个API计时精确吗?

3.如果在使用Z-stack协议栈完成单位时间内p0口中断次数统计的功能,有什么好的方案吗?

  • Q1: 如果CC2530一直使用定时器计时,功率大概是多少?

    看数据手册,有给外设电流大小。或者接个万用表实测下电流就好了。

    PARAMETER TEST CONDITIONS MIN TYP MAX UNIT
    Digital regulator on. 16-MHz RCOSC running. No radio, crystals, or peripherals active.
    3.4 mA
    Medium CPU activity: normal flash access(1), no RAM access
    32-MHz XOSC running. No radio or peripherals active.
    6.5 8.9 mA
    Medium CPU activity: normal flash access(1), no RAM access
    32-MHz XOSC running, radio in RX mode, –50-dBm input power, no peripherals active, CPU 20.5 mA idle
    32-MHz XOSC running, radio in RX mode at -100-dBm input power (waiting for signal), no 24.3 29.6 mA Core current peripherals active, CPU idle Icore consumption 32-MHz XOSC running, radio in TX mode, 1-dBm output power, no peripherals active, CPU idle 28.7 mA
    32-MHz XOSC running, radio in TX mode, 4.5-dBm output power, no peripherals active, CPU 33.5 39.6 mA idle
    Power mode 1. Digital regulator on; 16-MHz RCOSC and 32-MHz crystal oscillator off; 0.2 0.3 mA 32.768-kHz XOSC, POR, BOD and sleep timer active; RAM and register retention
    Power mode 2. Digital regulator off; 16-MHz RCOSC and 32-MHz crystal oscillator off; 1 2 μA 32.768-kHz XOSC, POR, and sleep timer active; RAM and register retention
    Power mode 3. Digital regulator off; no clocks; POR active; RAM and register retention 0.4 1 μA
    Peripheral Current Consumption (Adds to core current Icore for each peripheral unit activated)
    Timer 1 Timer running, 32-MHz XOSC used 90 μA
    Timer 2 Timer running, 32-MHz XOSC used 90 μA
    Timer 3 Timer running, 32-MHz XOSC used 60 μA
    Iperi Timer 4 Timer running, 32-MHz XOSC used 70 μA
    Sleep timer Including 32.753-kHz RCOSC 0.6 μA
    ADC When converting 1.2 mA
    Erase 1 mA
    Flash
    Burst write peak current 6 mA

  • 2.z-stack协议栈中,osal_start_timerEx()这个API计时精确吗?

    毫秒级吧,看你的应用需求。

  • 原文地址:http://www.kaleidscope.cn:1020/archives/1056

    以下为部分内容:

    Zigbee协议栈中如果要实现一个定时事件或者延时的话,有很多种方法,定时事件呢其实就是我们熟悉的使用定时器来定时,产生定时事件,当然也可以用来延时。 1、协议栈定时器HalTimerConfig ZigBee协议栈提供了定时器的使用接口,在hal层调用HalTimerConfig即可配置使用,而定时器2被协议栈占用了,所以只有使用1、3、4三个定时器。 在hal_timer.h中我们可以看到几个定时器的定义:

    /* Timer ID definitions */

    #define HAL_TIMER_0 0x00 // 8bit timer

    #define HAL_TIMER_1 0x01 // 16bit Mac timer

    #define HAL_TIMER_2 0x02 // 8bit timer

    #define HAL_TIMER_3 0x03 // 16bit timer

    #define HAL_TIMER_MAX 4 // Max number of timer

    所以和硬件中的定时器是有区别的,经过了映射,这里需要注意一下。

    * HAL_TIMER_0 --> HW Timer 3 8bit

    * HAL_TIMER_2 --> HW Timer 4 8bit

    * HAL_TIMER_3 --> HW Timer 1 16bit

    如果我们要使用协议栈的定时器进行相关操作,只需进行定时器的配置即可:

    extern uint8 extern uint8 HalTimerConfig ( uint8 timerId,uint8 opMode,uint8 channel,uint8 channelMode,bool intEnable,halTimerCBack_t cback );

    opMode - Operation mode操作方式共3种

    * channel - Channel where the counter operates on选择通道,对应IO口

    * channelMode - Mode of that channel通道的模式

    * intEnable -可中断

    * cBack - Pointer to the callback function 中断函数

    然后在回调函数中进行处理相关事件即可。

    void timer_callback(uint8 timerId, uint8 channel, uint8 channelMode);

    2、使用寄存器直接操作

    直接使用寄存器就更简单了,就把CC2530当做一个单片机用就可以了,这里我拿了我以前写的代码给大家演示,注释有错的地方请忽略,大概就这样吧。

    void InitT3(void)

    {

    T3CTL |= 0x08 ; //开溢出中断

    T3IE = 1; //开总中断和T3中断

    T3CTL|=0X12; //,128/16000000*N=0.5S,N=65200

    T3CC0 = 0x01;

    T3CTL &= ~0X03; //自动重装 00->0xff

    T3CTL |=0X10; //启动

    }

    void timer1Init(void)

    {/*设置定时器T1,128分频,模模式,从0计数到T1CC0*/