LoRa笔记02 LoRa sx1276 sx1278的发射功率研究

1 前言

发射功率也是射频基础指标,目前SX1278可以支持最大20dBm。

我正在学习LoRa和LoRaWAN,基本按照 官方资料+梳理解析+相关源码 的方式来记录笔记,相信对不少同行者有所帮助,可点此查看帖子LoRa学习笔记_汇总

本文作者twowinter,转载请注明作者:http://blog.csdn.net/iotisan/

2 官方datasheet资料

5.4.2. RF Power Amplifiers

PA_HF and PA_LF are high efficiency amplifiers capable of yielding RF power programmable in 1 dB steps from -4 to
+14dBm directly into a 50 ohm load with low current consumption. PA_LF covers the lower bands (up to 525 MHz), whilst
PA_HF will cover the upper bands (from 779 MHz). The output power is sensitive to the power supply voltage, and typically
their performance is expressed at 3.3V.

PA_HP (High Power), connected to the PA_BOOST pin, covers all frequency bands that the chip addresses. It permits
continuous operation at up to +17 dBm and duty cycled operation at up to +20dBm. For full details of operation at +20dBm
please consult section 5.4.3

Table 33 Power Amplifier Mode Selection Truth Table

PaSelect Mode Power Range Pout Formula
0 PA_HF or PA_LF on RFO_HF or RFO_LF -4 to +15dBm Pout=Pmax-(15-OutputPower) Pmax=10.8+0.6*MaxPower [dBm]
1 PA_HP on PA_BOOST, any frequency +2 to +17dBm Pout=17-(15-OutputPower) [dBm]
Notes 
- For +20 dBm restrictions on operation please consult the following .
- To ensure correct operation at the highest power levels ensure that the current limiter OcpTrim is adjusted to permit delivery of the requisite supply current.
- If the PA_BOOST pin is not used it may be left floating

5.4.2 中文解读

芯片有几个不同的射频管脚,PA_HF(大于779 MHz) and PA_LF(小于525 MHz)都最多输出14dBm。PA_BOOST则比较厉害点,可持续输出17dBm,duty cycled operation周期性工作可飙到20dBm。

有个朋友上次做了868MHz的LoRa,蛋疼地用了RFO_HF引脚,只能输出14dBm。要是多看下datasheet,也许就能避免这些问题了。

总的来说,目前像我们用了PA_BOOST,那么套用公式,就是可以常规输出2-17dBm,由寄存器控制。如果要输出20dBm,则要看接下去这一章节。

5.4.3. High Power +20 dBm Operation

The SX1276/77/78/79 have a high power +20 dBm capability on PA_BOOST pin, with the following settings:

Table 34 High Power Settings

Register Address Value for High Power Default value PA_HF/LF or +17dBm Description
RegPaDac 0x4d 0x87 0x84 Set Pmax to +20dBm for PA_HP

Notes
– High Power settings must be turned off when using PA_LF or PA_HF
– The Over Current Protection limit should be adapted to the actual power level, in RegOcp

Specific Absolute Maximum Ratings and Operating Range restrictions apply to the +20 dBm operation. They are listed in
Table 35 and Table 36.

The duty cycle of transmission at +20 dBm is limited to 1%, with a maximum VSWR of 3:1 at antenna port, over the
standard operating range [-40;+85°C]. For any other operating condition, contact your Semtech representative.

5.4.3 中文解读

如果要设置20dBm,则必须对高功率寄存器(RegPaDac)进行配置。如果用 PA_LF 和 PA_HF 那就不需要设置高功率寄存器(RegPaDac)。20dBm发送时占空比最大只能为1%。天线驻波比不能超过3:1。供电电压为2.4~3.7V。

IoT小能手twowinter注:此种情况下输出功率为 20 – (15 – OutputPower),也就是5~20dBm。这就目前绝大多数厂家对外宣称的功率参数。

5.4.4. Over Current Protection

The power amplifiers of SX1276/77/78/79 are protected against current over supply in adverse RF load conditions by the over current protection block. This has the added benefit of protecting battery chemistries with limited peak current capability and minimising worst case PA consumption in battery life calculation. The current limiter value is controlled by the OcpTrim bits in RegOcp, and is calculated according to the following formulae:

5.4.4 中文解读

电流过载保护。RegOcp的OcpTrim可以限制最大电流。

3 不同发射功率下的耗电

4 代码分析

LoRa这部分的代码是使用LORAMAC_DEFAULT_TX_POWER这个宏来定义,这个宏的值是根据各地区的数值来的,有的地区默认是14dBm,有的地区默认是20dBm。
具体可以查看LoRaWAN协议V1.0.2中文版_配套文件 地区参数(物理层)

在SendFrameOnChannel()这个函数中有具体的调用,根据不同地区参数,调用Radio.SetTxConfig(),把所有的地区参数一并设置进去。

void SX1276SetTxConfig( RadioModems_t modem, int8_t power, uint32_t fdev,
                        uint32_t bandwidth, uint32_t datarate,
                        uint8_t coderate, uint16_t preambleLen,
                        bool fixLen, bool crcOn, bool freqHopOn,
                        uint8_t hopPeriod, bool iqInverted, uint32_t timeout )
{
    uint8_t paConfig = 0;
    uint8_t paDac = 0;

    SX1276SetModem( modem );

    paConfig = SX1276Read( REG_PACONFIG );
    paDac = SX1276Read( REG_PADAC );

    paConfig = ( paConfig & RF_PACONFIG_PASELECT_MASK ) | SX1276GetPaSelect( SX1276.Settings.Channel );
    paConfig = ( paConfig & RF_PACONFIG_MAX_POWER_MASK ) | 0x70;

    if( ( paConfig & RF_PACONFIG_PASELECT_PABOOST ) == RF_PACONFIG_PASELECT_PABOOST )
    {
        if( power > 17 )
        {
            paDac = ( paDac & RF_PADAC_20DBM_MASK ) | RF_PADAC_20DBM_ON;
        }
        else
        {
            paDac = ( paDac & RF_PADAC_20DBM_MASK ) | RF_PADAC_20DBM_OFF;
        }
        if( ( paDac & RF_PADAC_20DBM_ON ) == RF_PADAC_20DBM_ON )
        {
            if( power  20 )
            {
                power = 20;
            }
            paConfig = ( paConfig & RF_PACONFIG_OUTPUTPOWER_MASK ) | ( uint8_t )( ( uint16_t )( power - 5 ) & 0x0F );
        }
        else
        {
            if( power  17 )
            {
                power = 17;
            }
            paConfig = ( paConfig & RF_PACONFIG_OUTPUTPOWER_MASK ) | ( uint8_t )( ( uint16_t )( power - 2 ) & 0x0F );
        }
    }
    else
    {
        if( power  14 )
        {
            power = 14;
        }
        paConfig = ( paConfig & RF_PACONFIG_OUTPUTPOWER_MASK ) | ( uint8_t )( ( uint16_t )( power + 1 ) & 0x0F );
    }
    SX1276Write( REG_PACONFIG, paConfig );
    SX1276Write( REG_PADAC, paDac );
    ......
}

另外本尊还弄到官方旧的驱动库,大家看看就好了。^_^

1.设置频点时,顺便把是否PA Select给配置了。

void SX1276LoRaSetRFFrequency( uint32_t freq )
{
    LoRaSettings.RFFrequency = freq;

    freq = ( uint32_t )( ( double )freq / ( double )FREQ_STEP );
    SX1276LR->RegFrfMsb = ( uint8_t )( ( freq >> 16 ) & 0xFF );
    SX1276LR->RegFrfMid = ( uint8_t )( ( freq >> 8 ) & 0xFF );
    SX1276LR->RegFrfLsb = ( uint8_t )( freq & 0xFF );
    SX1276WriteBuffer( REG_LR_FRFMSB, &SX1276LR->RegFrfMsb, 3 );

    SX1276Read( REG_LR_PACONFIG, &SX1276LR->RegPaConfig );

    if( LoRaSettings.RFFrequency > 860000000 )
    {
        SX1276LR->RegPaConfig = ( SX1276LR->RegPaConfig & RFLR_PACONFIG_PASELECT_MASK ) | RFLR_PACONFIG_PASELECT_RFO;
    }
    else
    {
        SX1276LR->RegPaConfig = ( SX1276LR->RegPaConfig & RFLR_PACONFIG_PASELECT_MASK ) | RFLR_PACONFIG_PASELECT_PABOOST;
    }
    SX1276Write( REG_LR_PACONFIG, SX1276LR->RegPaConfig );
}

2.设置是否使能20dBm

void SX1276LoRaSetPa20dBm( bool enale )
{
    SX1276Read( REG_LR_PADAC, &SX1276LR->RegPaDac );
    SX1276Read( REG_LR_PACONFIG, &SX1276LR->RegPaConfig );

    if( ( SX1276LR->RegPaConfig & RFLR_PACONFIG_PASELECT_PABOOST ) == RFLR_PACONFIG_PASELECT_PABOOST )
    {
        if( enale == true )
        {
            SX1276LR->RegPaDac = 0x87;
        }
    }
    else
    {
        SX1276LR->RegPaDac = 0x84;
    }
    SX1276Write( REG_LR_PADAC, SX1276LR->RegPaDac );
}

3.重点部分,设置发射功率。

void SX1276LoRaSetRFPower( int8_t power )
{
    SX1276Read( REG_LR_PACONFIG, &SX1276LR->RegPaConfig );
    SX1276Read( REG_LR_PADAC, &SX1276LR->RegPaDac );

    if( ( SX1276LR->RegPaConfig & RFLR_PACONFIG_PASELECT_PABOOST ) == RFLR_PACONFIG_PASELECT_PABOOST )
    {
        if( ( SX1276LR->RegPaDac & 0x87 ) == 0x87 )
        {
            if( power  20 )
            {
                power = 20;
            }
            SX1276LR->RegPaConfig = ( SX1276LR->RegPaConfig & RFLR_PACONFIG_MAX_POWER_MASK ) | 0x70;
            SX1276LR->RegPaConfig = ( SX1276LR->RegPaConfig & RFLR_PACONFIG_OUTPUTPOWER_MASK ) | ( uint8_t )( ( uint16_t )( power - 5 ) & 0x0F );
        }
        else
        {
            if( power  17 )
            {
                power = 17;
            }
            SX1276LR->RegPaConfig = ( SX1276LR->RegPaConfig & RFLR_PACONFIG_MAX_POWER_MASK ) | 0x70;
            SX1276LR->RegPaConfig = ( SX1276LR->RegPaConfig & RFLR_PACONFIG_OUTPUTPOWER_MASK ) | ( uint8_t )( ( uint16_t )( power - 2 ) & 0x0F );
        }
    }
    else
    {
        if( power  14 )
        {
            power = 14;
        }
        SX1276LR->RegPaConfig = ( SX1276LR->RegPaConfig & RFLR_PACONFIG_MAX_POWER_MASK ) | 0x70;
        SX1276LR->RegPaConfig = ( SX1276LR->RegPaConfig & RFLR_PACONFIG_OUTPUTPOWER_MASK ) | ( uint8_t )( ( uint16_t )( power + 1 ) & 0x0F );
    }
    SX1276Write( REG_LR_PACONFIG, SX1276LR->RegPaConfig );
    LoRaSettings.Power = power;
}

4.总体流程

void SX1276LoRaInit( void )
{
    ......
    SX1276LoRaSetRFFrequency( LoRaSettings.RFFrequency );
    SX1276LoRaSetPa20dBm( true );
    SX1276LoRaSetRFPower( LoRaSettings.Power );
    ......
}

End

测试结束,截图留念,确实到了20dBm。

说明:LPWA物联网应用站(LPWAP.com)通过公开互联网收集、整理并转载有关LPWA物联网应用解决方案,以供广大LPWA应用开发者和爱好者共同学习交流和参考运用到实际生产生活中。本站所有转载的文章、图片、音频、视频等资料的版权归版权所有人所有并衷心感谢您的付出,由于本站采纳的非本站原创文章及图片等内容无法一一联系确认版权者,如果本网所选内容的文章原创作者认为其作品不宜放在本站,请及时通过以下留言功能通知我们采取适当措施,避免给双方造成不必要的经济损失。如果您希望保留文章在本站,但希望文章末尾提供对作者的致谢或者产品、网站交换链接的,也请将需求写入以下留言栏中,谢谢您的支持。让我们共同努力,打造万物互联的未来美好生活!

您的留言或需求: