Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RS485 Bus stops after a few days #6

Open
impellerturn opened this issue Feb 12, 2019 · 7 comments
Open

RS485 Bus stops after a few days #6

impellerturn opened this issue Feb 12, 2019 · 7 comments

Comments

@impellerturn
Copy link

Hello,
i´ve encountered, that my sensors are not working after a few days of operation.

Setup

  • 3 Sensors
  • overall bus length 25m
  • Termination: VCC <-> 390Ohms <-> RS485-line-A <-> 220Ohms <-> RS485-line-B <-> 390Ohms <-> Ground
  • Termination is at my USB to RS485 Transceiver

Measurement

  • set measuerement interval to 500ms
  • do 100 measuerements, read the data once per second then calculate mean on the data
  • then do the next 100 measuerements

Result

  • This runs fine for about 2 days but occasionally stops.
  • Tested with the USBtoRS485 converter sold by @Miceuz and also with a different one. Same results.
  • Only pwer cycling the whole bus helps.

Has anyone else had similar issues? Maybe @cheeeeee?

Any help appreaciated, thanks and best regards

@cheeeeee
Copy link

cheeeeee commented Feb 12, 2019

My initial thought might be the watchdog timer on it in relation to the sleep function. It looks like the WDTCSR is still in the works honestly. I don't even have my sensors in production yet since I'm still going through the firmware. I'll see about looking into improving the watchdog on it and submitting a pull request since Albertas seems pretty busy. If you're not familiar, a watchdog timer basically monitors for a loop condition and if a timeout is reached it resets the device automatically. To keep that from happening you have to keep on feeding the watchdog timeout conditions. Is there a delay between when you do batches of measurements? Can you try a lower number of reads and report back? Like say 50 reads and average and see if it dies in 4 days instead of 2? Also if you have any code that you're using to interact with the sensors that would be super helpful just to make sure it's on the firmware side of things and not an error with the controller.

@impellerturn
Copy link
Author

impellerturn commented Feb 14, 2019

Hi,
i´ve tried bringing my system up yesterday but something with MQTT did not work out. Will look for it on the weekend.
Here is my code to use the sensors. It requires the mosquitto python module along with some standard python libs. Dont have a public repo yet.

soilmoisturereader.zip
Check out the readme.md for instructions how to use.
Best regards

@cheeeeee
Copy link

cheeeeee commented Feb 14, 2019

Okay just fair warning I haven't used python before but everything that I see on your controllers looks good to me. Most errors are handled and you should be getting exceptions reported if there is an error in the controller querying the modbus devices. Try using a lower query rate like I suggested before and see if that changes anything. If it does that might indicate a limit or bug with MQTT. There was a POSSIBLE error with a write protected register in attint441 programming when sleep was called and a reset might not be initiated and an infinite loop would occur. I included that fix with with other request but I have all of 4 weeks of experience with cpp and about 3 weeks of experience writing c so I'm mostly going off of datasheets and research here. Albertas will really need to check it all and program one and see what happens. If what I have doesn't fix it we might have to approach it from a different angle. Just wait and see at this point. Hopefully this works.

I think the current problem might lie here
inline static void reset() { WDTCSR = _BV(WDE);//reset in 16ms while(1); }

This reset function is called by sleep. The walk through is that

  1. the watchdog is enabled
  2. an infinite loop occurs

This is normally totally fine because when the watchdog timer runs out the system resets!
The problem here is that "WDE" the bit that enables the watchdog timer is write protected.
If that bit is never written, then the watchdog is not enabled and an infinite loop locks everything up.
The fix is probably this.

inline static void reset() { cli(); CCP = 0xD8; WDTCSR |= (1<<WDE); sei(); while(1); }

When reset is called now

  1. we clear our interrupt cli(); <--this goes to SREG
  2. send a signal to disable copy protection on WDTCSR with CCP = 0xD8;
  3. enable our watchdog by writing the WDE bit to WDTCSR
  4. enable out interrupt sei(); <--again goes to SREG
  5. now start out infinite loop which will timeout since our watchdog is now enabled.
  6. copy protection will re-enable within 4 instructions cycles.

@Miceuz
Copy link
Owner

Miceuz commented Mar 3, 2019

@cheeeeee reset() in not called from sleep().

Sensor is configured in Safety Level 1.

In this mode, the Watchdog Timer is initially disabled, but can be enabled by writing the WDE bit to one without any restriction. A timed sequence is needed when disabling an enabled Watchdog Timer.

@impellerturn are you putting sensors to sleep?

@impellerturn
Copy link
Author

Hi,
no i do not bring the sensors to sleep.

@Miceuz
Copy link
Owner

Miceuz commented Apr 18, 2021

Sorry, I have totally forgotten this.

My suspicion lies with the powering. How many sensors are powered from a single usb dongle? I wouldn't use USB dongle as a permanent power solution. It can supply only one - two sensors.

@impellerturn
Copy link
Author

There were 3 sensors powered by the usb dongle.
In the first post i've listed a detailed description of the system setup.

As of today i do not have the setup any more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants