Skip to content

Commit

Permalink
Fixed unnecessary duty cycle delay
Browse files Browse the repository at this point in the history
- Second attempt to fix unnecessary duty cycle delay
- Re-extended debug messages
- Updated README
  • Loading branch information
foorschtbar committed Feb 19, 2022
2 parents e9d4a54 + e56f32c commit c96a483
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 22 deletions.
Binary file added .github/lorapromini_pcb.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed .github/pcb_back.png
Binary file not shown.
Binary file removed .github/pcb_front.png
Binary file not shown.
Binary file modified .github/pcb_front_assembled.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 12 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
A LoRaWAN sensor node, based on ATmega328P MCU (Arduino Pro Mini) and RFM95W/SX1276 LoRa Transceiver.

![PCB Front Assembled](.github/pcb_front_assembled.png)
![PCB Front Assembled](.github/pcb_real.jpg)


The module can be used:

Expand All @@ -38,6 +38,10 @@ The module can be used:
- Bosch BME280 (humidity, barometric pressure and ambient temperature)
- Maxim DS18B20(+)/DS18S20(+)/DS1822 1-Wire temperature sensor

### Warning

LoRaProMini does not take care of the compliance with the duty cycle limitation. Please select only transmission intervals that are within the legal limits (1%/0.1%). Please also note that the interrupt inputs may cause additional transmissions if this function is activated.

## Example Applications

### Environmental (Weather/Clima) Sensor
Expand All @@ -58,11 +62,9 @@ The module can be used:

## More pics

<!--- ![PCB Front](.github/pcb_front.png) --->
![PCB Real Assembled](.github/pcb_real.jpg)

![PCB Back](.github/pcb_back.png)

<!--- ![PCB Back](.github/pcb_back.png) --->
![PCB Front and Back](.github/lorapromini_pcb.png)

![PCB KiCad](.github/pcb_kicad.png)

Expand Down Expand Up @@ -101,6 +103,10 @@ avrdude -F -v -c arduino -p atmega328p -P COM4 -b 57600 -D -U flash:w:firmware_1

## Firmware Changelog

### Version 2.6

- Second attempt to solve the unnecessary delay due to the duty cycle limitation. Overflow of timer0 freezes the MCU after around 20 transmissions.

### Version 2.5

- Fixed problem with duty cycle limitation
Expand Down Expand Up @@ -230,6 +236,7 @@ function decodeUplink(input) {
- [ ] Multi point calibration for battery voltage
- [ ] Set ADR (On/Off)
- [ ] Set SF (7-12)
- [ ] Allow change of NetID
- [x] Add wake up trough interrupt pins
- [x] Move Major- and Minorversion byte to single byte. 4 bits for major and 4 bits for minor.
- [x] Add option for Confirmed Uplink to config
Expand Down
2 changes: 1 addition & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ build_flags =
-D USE_IDEETRON_AES
-D MIC_ENABLE_arbitrary_clock_error
-D VERSION_MAJOR=2
-D VERSION_MINOR=5
-D VERSION_MINOR=6

[env:config]
build_flags =
Expand Down
86 changes: 70 additions & 16 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ configData_t cfg; // Instance 'cfg' is a global variable with 'configData_t' str
volatile boolean wakedFromISR0 = false;
volatile boolean wakedFromISR1 = false;
unsigned long lastPrintTime = 0;
// unsigned long prepareCount = 0;
unsigned long prepareCount = 0;
boolean TXCompleted = false;
boolean foundBME = false; // BME Sensor found. To skip reading if no sensor is attached
boolean foundDS = false; // DS19x Sensor found. To skip reading if no sensor is attached
Expand Down Expand Up @@ -550,8 +550,8 @@ void do_send(osjob_t *j)
buffer[10] = temp2 >> 8;
buffer[11] = temp2;

log_d_ln("Prepare pck");
// log_d_ln(++prepareCount);
log_d("Prepare pck #");
log_d_ln(++prepareCount);
// log_d(F("> FW: v"));
// log_d(VERSION_MAJOR);
// log_d(F("."));
Expand Down Expand Up @@ -672,10 +672,8 @@ void lmicStartup()
// #endif
}

extern volatile unsigned long timer0_overflow_count;
void do_sleep(uint16_t sleepTime)
{

boolean breaksleep = false;

if (LOG_DEBUG_ENABLED)
Expand Down Expand Up @@ -739,11 +737,67 @@ void do_sleep(uint16_t sleepTime)
}

// LMIC does not get that the MCU is sleeping and the
// duty cycle limitation then provides a delay. A manual
// overflow of timer0_overflow_count (wiring.c from the arduino core)
// which is used for micros() fix that.
// duty cycle limitation then provides a delay.
// Reset duty cycle limitation to fix that.
LMIC.bands[BAND_MILLI].avail =
LMIC.bands[BAND_CENTI].avail =
LMIC.bands[BAND_DECI].avail = os_getTime();

// ++++++++++++++++++++++++++++++++++++++++++++++++++ //
// If that still not work, here a some other things to checkout:
//
// https://www.thethingsnetwork.org/forum/t/adafruit-feather-32u4-lora-long-transmission-time-after-deep-sleep/11678/11
timer0_overflow_count += 3E6;
// extern volatile unsigned long timer0_overflow_count;
// cli();
// timer0_overflow_count += 8 * 64 * clockCyclesPerMicrosecond();
// sei();
//
// https://www.thethingsnetwork.org/forum/t/lmic-sleeping-and-duty-cycle/15471/2
// https://github.com/matthijskooijman/arduino-lmic/issues/109
// https://github.com/matthijskooijman/arduino-lmic/issues/121
//
// https://www.thethingsnetwork.org/forum/t/modified-lmic-sleep-and-other-parameter/17027/3
//
// https://github.com/mcci-catena/arduino-lmic/issues/777
// LMIC.txend = 0;
// for (int i = 0; i < MAX_BANDS; i++)
// {
// LMIC.bands[i].avail = 0;
// }
// LMIC.bands[BAND_MILLI].avail = 0;
// LMIC.bands[BAND_CENTI].avail = 0;
// LMIC.bands[BAND_DECI].avail = 0;
//
// https://github.com/matthijskooijman/arduino-lmic/issues/293
//
// os_radio(OP_TXDATA);
// LMIC.opmode = OP_TXDATA;
// LMIC_setTxData2(1, mydata, sizeof(mydata) - 1, 0);
//
// https://www.thethingsnetwork.org/forum/t/feather-m0-with-lmic-takes-more-than-2-minutes-to-transmit/41803/20?page=2
// https://gist.github.com/HeadBoffin/95eac7764d94ccde83af2503c1e24eb8
//
/// We don't just send here, give the os_runloop_once() a chance to run
// and we keep the State machine pure
//
// https://forum.arduino.cc/t/manipulation-of-millis-value/42855/4
//
// https://www.thethingsnetwork.org/forum/t/arduino-sx1276-with-lmic-library-on-arduino-ide-sleep-mode-problem/54692
// void PowerDownUpdateMicros()
// {
// extern volatile unsigned long timer0_overflow_count;
// PowerDown();
// cli();
// // LMIC uses micros() to keep track of the duty cycle, so
// // hack timer0_overflow for a rude adjustment:
// timer0_overflow_count += 8 * 64 * clockCyclesPerMicrosecond();
// sei();
// }
// LMIC uses micros() to keep track of the duty cycle, so
// hack timer0_overflow for a rude adjustment:
// cli();
// timer0_overflow_count += 8 * 64 * clockCyclesPerMicrosecond();
// sei();
}

void onEvent(ev_t ev)
Expand Down Expand Up @@ -934,13 +988,13 @@ void setup()
}
}

log_d(F("Srch DS18x..."));
log_d(F("Search DS18x..."));

ds.begin();
ds.requestTemperatures();

log_d(ds.getDeviceCount(), DEC);
log_d_ln(F(" fnd"));
log_d_ln(F(" found"));

for (uint8_t i = 0; i < ds.getDeviceCount(); i++)
{
Expand Down Expand Up @@ -977,11 +1031,11 @@ void setup()
}

// BME280 forced mode, 1x temperature / 1x humidity / 1x pressure oversampling, filter off
log_d(F("Srch BME..."));
log_d(F("Search BME..."));
if (bme.begin(I2C_ADR_BME))
{
foundBME = true;
log_d_ln(F("1 fnd"));
log_d_ln(F("1 found"));
if (CONFIG_MODE_ENABLED)
{
bme.takeForcedMeasurement();
Expand All @@ -998,7 +1052,7 @@ void setup()
}
else
{
log_d_ln(F("0 fnd"));
log_d_ln(F("0 found"));
}

// Allow wake up pin to trigger interrupt on low.
Expand Down Expand Up @@ -1076,9 +1130,9 @@ void loop()
// sleep ended. do next transmission
doSend = true;
}
if (lastPrintTime == 0 || lastPrintTime + 5000 < millis())
if (lastPrintTime == 0 || lastPrintTime + 1000 < millis())
{
log_d_ln(F("> Cant sleep"));
log_d_ln(F("> Can't sleep"));
lastPrintTime = millis();
}

Expand Down

0 comments on commit c96a483

Please sign in to comment.