Please read the posts in the Announcements section about the current status of Cumulus development now that I have retired

Please read this post before posting

Latest Cumulus release v1.9.4 (build 1099) - Nov 28 2014
Latest Cumulus MX release - v3.0.0 build 3043 Jan 20 2017. See this post for download

RG-11 input debounce

Discussion of this sensor and its uses
dive76
Posts: 21
Joined: Sun Jan 22, 2012 7:37 am
Weather Station: Davis VP2
Operating System: Windows Server 2012 R2
Location: Bangkok

RG-11 input debounce

Postby dive76 » Thu Feb 06, 2014 2:41 pm

Hi, moved house and installed my RG-11 again with new cable length. Capacitor/Resistor trick worked last time but now fails.
Would it be possible to implement a easy software debounce in Cumulus? Something like this (sample switch debounce):

#define CHECK_MSEC 5 // Read hardware every 5 msec
#define PRESS_MSEC 10 // Stable time before registering on
#define RELEASE_MSEC 100 // Stable time before registering off
// This function reads the key state from the hardware.
extern bool_t RawKeyPressed();
// This holds the debounced state of the key.
bool_t DebouncedKeyPress = false;
// Service routine called every CHECK_MSEC to
// debounce both edges
void DebounceSwitch1(bool_t *Key_changed, bool_t *Key_pressed)
{
static uint8_t Count = RELEASE_MSEC / CHECK_MSEC;
bool_t RawState;
*Key_changed = false;
*Key_pressed = DebouncedKeyPress;
RawState = RawKeyPressed();
if (RawState == DebouncedKeyPress) {
// Set the timer which allows a change from current state.
if (DebouncedKeyPress) Count = RELEASE_MSEC / CHECK_MSEC;
else Count = PRESS_MSEC / CHECK_MSEC;
} else {
// Key has changed - wait for new state to become stable.
if (--Count == 0) {
// Timer expired - accept the change.
DebouncedKeyPress = RawState;
*Key_changed=true;
*Key_pressed=DebouncedKeyPress;
// And reset the timer.
if (DebouncedKeyPress) Count = RELEASE_MSEC / CHECK_MSEC;
else Count = PRESS_MSEC / CHECK_MSEC;
}
}
}

User avatar
steve
Cumulus Author
Posts: 26300
Joined: Mon Jun 02, 2008 6:49 pm
Weather Station: None
Operating System: None
Location: On tour in Spain
Contact:

Re: RG-11 input debounce

Postby steve » Thu Feb 06, 2014 3:05 pm

It's not that simple, because that isn't how it works. Cumulus doesn't read the state of the switch, as I said way back when this issue was first discovered. It gets events which tell it when the state has changed. And as was discovered previously, it doesn't always get on-off-on-off notifications, sometimes its gets on-on-off (and possibly other combinations). And as I said previously, I added support for these sensors because it looked like it was going to be straightforward, and as is often the case, the hardware doesn't behave as expected and it turns out to be much more complicated.

I'm sorry, but I don't have the time to look at the possibility of changing Cumulus to work around this at the moment; perhaps one day I will, but to be honest I think that's unlikely.
Steve
-----
Hosting available for Cumulus web sites. See http://sandaysoft.com/forum/viewtopic.php?f=2&t=11876

Please read the posts in the Announcements section about the current status of Cumulus development now that I have retired

AllyCat
Posts: 1004
Joined: Sat Feb 26, 2011 1:58 pm
Weather Station: Fine Offset 1080/1 & 3080
Operating System: Windows XP SP3
Location: SE London

Re: RG-11 input debounce

Postby AllyCat » Thu Feb 06, 2014 3:42 pm

Hi,

dive76 wrote:with new cable length. Capacitor/Resistor trick worked last time but now fails.
What values of R and C have you tried? I seem to remember that some of the values originally discussed were NOT what I would recommend or use. ;)

Also, what length and type of cable are you using, and what type of serial interface (USB adapter, "Real" PC COM port, etc.)?

Cheers, Alan.

bruce45
Posts: 363
Joined: Wed Jan 07, 2009 10:36 pm
Weather Station: wh1081
Operating System: windows 10
Location: Oban Scotland

Re: RG-11 input debounce

Postby bruce45 » Thu Feb 06, 2014 5:22 pm

are you using the rg11 as an extra rain gauge or as a replacement to the tip bucket?

I fitted mine to my spare station which is used to monitor the greenhouse and fitted the resistor and capacitor inside the rg11. its connected to the via a 20 mtr cable and works ok.

dive76
Posts: 21
Joined: Sun Jan 22, 2012 7:37 am
Weather Station: Davis VP2
Operating System: Windows Server 2012 R2
Location: Bangkok

Re: RG-11 input debounce

Postby dive76 » Fri Feb 07, 2014 1:06 am

To Steve: I understand. I am anyway very glad for you making CUMULUS in your free time and very much like it.

To Alan: I am using the R C values from the discussion about a year back. The cable is CAT6 about 25m.
I have tried two configurations:

1.) PC serial port: shows as a result mainly off off off off if no event. and if event I see off on on on off off off. So looks like bounce.
2.) Serial to USB: Events are clear as on off but I get many on events without an tip over a time.

Looking at the simple debouncing I was doing some more literature study but have trouble to transfer it to this problem and the pins on the com port.
images.jpg


Here the signal output is wired between the c and r and this is what I mainly see. In the example dicussed some time back we simply but an R C over the relay contact.
Any idea how to realise it?
You do not have the required permissions to view the files attached to this post.

AllyCat
Posts: 1004
Joined: Sat Feb 26, 2011 1:58 pm
Weather Station: Fine Offset 1080/1 & 3080
Operating System: Windows XP SP3
Location: SE London

Re: RG-11 input debounce

Postby AllyCat » Fri Feb 07, 2014 10:30 am

Hi,

It's difficult to be specific without some real "numbers", and IMHO some of the RC values (or the associated circuits) in that thread were far from "ideal".

dive76 wrote:2.) Serial to USB: Events are clear as on off but I get many on events without an tip over a time.
However, this suggests that the problem is NOT contact bounce but interference and/or badly controlled signal levels. That's compounded because the "official" RS232 (serial COM port) specification uses both positive and negative (lower than "Earth") voltage levels, so one is often using "undocumented" features of the port/interface.

Your circuit diagram is potentially a good starting point, but what voltage is "Vcc", what (technology) is the Inverter/Gate (e.g. (H)CMOS ?), what is it powered from (Vcc/GND ?) and which end of the cable is it (to be) located?

The supply rail to the RG11 is not very suitable because it is (potentially) too high and unregulated. The RG11 does make available a 5 volt regulated rail (on its internal pin connector) which might be more suitable, but if connecting to that, it's important to "Not let the magic smoke escape" as another forum puts it. :)

"Contact Bounce" normally only lasts for a few milliseconds, whilst I believe the RG11 pulse is about 150 ms, so I would use a filter time constant of about 20 ms. Suitable values might be R1 = 470 ohms, R2 = 4k7, C = 4u7 F (none particularly critical) with a (H)CMOS gate/buffer across 5 volt Vcc/GND rails. Ideally a "Schmitt Trigger" type buffer/inveter located at the "Computer" end of the cable (or put a resistor of a few hundred ohms is series with "Out" if located at the RG11 end of the cable).

But that's quite a "Rolls Royce" design; in practice a simple C and one or two Rs should be sufficient provided that their values (and Vcc) are chosen correctly.

Cheers, Alan.

dive76
Posts: 21
Joined: Sun Jan 22, 2012 7:37 am
Weather Station: Davis VP2
Operating System: Windows Server 2012 R2
Location: Bangkok

Re: RG-11 input debounce

Postby dive76 » Fri Feb 07, 2014 11:07 am

Thanks Alan,

How would such a wiring look if you translate it to the RS232 pins and RG-11 pins. We also have 12v available from the power supply in the RG-11. Would this be suitable to be used?
Sorry for many questions.

AllyCat
Posts: 1004
Joined: Sat Feb 26, 2011 1:58 pm
Weather Station: Fine Offset 1080/1 & 3080
Operating System: Windows XP SP3
Location: SE London

Re: RG-11 input debounce

Postby AllyCat » Fri Feb 07, 2014 4:13 pm

Hi,

The RG11 relay contacts are (initially) isolated from Earth (or Ground), so I would wire its COM terminal to the input voltage (e.g. 12 v) as shown in the RG11 User Manual (lower "It's raining" diagram). Then connect the NO (Normally Open) contact via a resistor (typically in the range 1k - 10k) to a "signal" line in the cable (which of course also carries one or more wires connected to Earth).

The "threshold" voltage (i.e. the "decision" level between ON and OFF) is probably between 1 and 3 volts at the computer/USB adapter. So I would connect two more resistors (of similar value to the RG11 end), the first from the cable to the "input" pin, and the second, in parallel with a capacitor (with the correct polarity), between the input pin and (cable) Earth. For a 20ms time constant, the capacitor would be about 10 uF if using 3k3 resistors (proportionally larger for smaller R values and vice versa).

If you have a particularly "temperamental" COM port input, then you might be able to use one of the negative "handshaking" pins on the COM port to create a (slightly) negative OFF level, but be careful if using a Polarised (Electrolytic) filter capacitor.

Cheers, Alan.

dive76
Posts: 21
Joined: Sun Jan 22, 2012 7:37 am
Weather Station: Davis VP2
Operating System: Windows Server 2012 R2
Location: Bangkok

Re: RG-11 input debounce

Postby dive76 » Sun Feb 09, 2014 9:46 am

Thanks Alan, I have tried a different approach first: I have added a 10uf capacitor from DSR pin to ground pin on the com port. This solved my problem and now it looks stable.

AllyCat
Posts: 1004
Joined: Sat Feb 26, 2011 1:58 pm
Weather Station: Fine Offset 1080/1 & 3080
Operating System: Windows XP SP3
Location: SE London

Re: RG-11 input debounce

Postby AllyCat » Sun Feb 09, 2014 10:07 am

Hi,

Glad that you've got it working.

Just a word of warning: Don't put a capacitor (as large as 10uF) directly across the relay contacts. The large current which can flow when the contacts close can potentially damage their contact surfaces (eventually).

In practice, the resistance and inductance of a 25 metres cable may well be sufficient to limit the current surge. But I'd add a resistor of perhaps 100 ohms, which may also prevent any "smoke" if a short circuit accidentally occurs in the cable.

Cheers, Alan.


Return to “Hydreon RG-11 Rain Sensor”

Who is online

Users browsing this forum: No registered users and 2 guests