StuartsProjects / SX12XX-LoRa

Library for SX12XX LoRa devices
315 stars 68 forks source link

OCP Trim Settings are not updated based on TX power level when using default example #60

Closed floatAsNeeded closed 1 year ago

floatAsNeeded commented 1 year ago

I just wanted to note an issue regarding the library using an SX1276 that I was testing.

Basically, if you try the example code 8_LoRa_LowMemory_TX the OCP trim settings are by default at 100mA The only thing is that they don't change based on different TX settings.

The only way I found out (by seeing the cpp file) to let the settings change based on the TX power is by adding this line of code

LT.setTxParams(TXpower, RADIO_RAMP_DEFAULT);

I'm not sure if that is the behaviour intended by the library. Maybe when using setupLora, it should also have the routine done with setTxParams to modify the OCP trim settings based on TX power. Maybe something like this:


void SX127XLT::setupLoRa(uint32_t Frequency, int32_t Offset, int8_t txPower, uint8_t modParam1, uint8_t modParam2, uint8_t  modParam3, uint8_t modParam4)
{
#ifdef SX127XDEBUG1
  Serial.println(F("setupLoRa() "));
#endif

  setMode(MODE_STDBY_RC);                            //go into standby mode to configure device
  setPacketType(PACKET_TYPE_LORA);                   //use LoRa packets
  setRfFrequency(Frequency, Offset);                 //set the operating frequncy
  calibrateImage(0);                                 //run calibration after setting frequency
  setModulationParams(modParam1, modParam2, modParam3, modParam4);
  setBufferBaseAddress(0x00, 0x00);                  //set bases addresses for TX and RX packets in SX buffer
  setPacketParams(8, LORA_PACKET_VARIABLE_LENGTH, 255, LORA_CRC_ON, LORA_IQ_NORMAL); //set the packet options
  setSyncWord(LORA_MAC_PRIVATE_SYNCWORD);            //syncword to use, 0x12 for standard private, 0x34 for public (LORAWAN)
  setHighSensitivity();

 //common routines for PABOOST and RFO
  OcpTrim = OCP_TRIM_110MA;                    //value for OcpTrim 11dBm to 16dBm

  if (txPower >= 17)
  {
    OcpTrim = OCP_TRIM_150MA;
  }

  if (txPower <= 10)
  {
    OcpTrim = OCP_TRIM_80MA;
  }

  writeRegister(REG_PARAMP, rampTime);
  writeRegister(REG_OCP, (OcpTrim + 0x20));
  writeRegister(REG_PACONFIG, (boostval  + MaxPower + OutputPower));    //MaxPower does not care for SX1272
}

I believe they are essential settings when using higher power like 17dbm to ensure output power and in general best practices from the datasheet. I had an issue with the module resetting that is how I find out that the OCP settings were not changing when using different TX power but were always stuck in 100mA regardless of TX power. I used LoRa.printOCPTRIM(); and I was always getting:

REG_OCP,2B,OCP_TRIM_100MA

StuartsProjects commented 1 year ago

I dont see that there is an issue here, the 'default' OCP trim value is indeed 100mA, that is the reset value of the SX127x register.

The library TX routines, such as transmitSXBuffer() need the TXpower as a parameter by design, and set OCP trim appropriately before every transmission, so there is no need to set OCP trim in setupLoRa().

Use the printOCPTRIM() function after a transmission, what value do you see ?

floatAsNeeded commented 1 year ago

You're right, the routine is done in the SX buffer anyway before transmitting. I do get the proper OCPTRIM after transmitting. Thank you for clarifying! I think the reason why my board was resetting was that I was not supplying enough power when transmitting, now I resolved that issue I was having, and nothing related to that.