Welcome to the Cumulus Support forum.

Latest Cumulus MX V3 release 3.28.6 (build 3283) - 21 March 2024

Cumulus MX V4 beta test release 4.0.0 (build 4017) - 17 March 2024

Legacy Cumulus 1 release v1.9.4 (build 1099) - 28 November 2014 (a patch is available for 1.9.4 build 1099 that extends the date range of drop-down menus to 2030)

Download the Software (Cumulus MX / Cumulus 1 and other related items) from the Wiki

RG-11 input debounce

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

RG-11 input debounce

Post by dive76 »

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: 26702
Joined: Mon 02 Jun 2008 6:49 pm
Weather Station: None
Operating System: None
Location: Vienne, France
Contact:

Re: RG-11 input debounce

Post by steve »

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
AllyCat
Posts: 1124
Joined: Sat 26 Feb 2011 1:58 pm
Weather Station: Fine Offset 1080/1 & 3080
Operating System: Windows XP SP3
Location: SE London

Re: RG-11 input debounce

Post by AllyCat »

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: 365
Joined: Wed 07 Jan 2009 10:36 pm
Weather Station: wh1081
Operating System: windows 10
Location: Oban Scotland

Re: RG-11 input debounce

Post by bruce45 »

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 22 Jan 2012 7:37 am
Weather Station: Davis VP2
Operating System: Windows Server 2012 R2
Location: Bangkok

Re: RG-11 input debounce

Post by dive76 »

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: 1124
Joined: Sat 26 Feb 2011 1:58 pm
Weather Station: Fine Offset 1080/1 & 3080
Operating System: Windows XP SP3
Location: SE London

Re: RG-11 input debounce

Post by AllyCat »

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 22 Jan 2012 7:37 am
Weather Station: Davis VP2
Operating System: Windows Server 2012 R2
Location: Bangkok

Re: RG-11 input debounce

Post by dive76 »

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: 1124
Joined: Sat 26 Feb 2011 1:58 pm
Weather Station: Fine Offset 1080/1 & 3080
Operating System: Windows XP SP3
Location: SE London

Re: RG-11 input debounce

Post by AllyCat »

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 22 Jan 2012 7:37 am
Weather Station: Davis VP2
Operating System: Windows Server 2012 R2
Location: Bangkok

Re: RG-11 input debounce

Post by dive76 »

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: 1124
Joined: Sat 26 Feb 2011 1:58 pm
Weather Station: Fine Offset 1080/1 & 3080
Operating System: Windows XP SP3
Location: SE London

Re: RG-11 input debounce

Post by AllyCat »

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.
Post Reply