Strange behavior when writing to instrument brightness dataref

Discuss suspected bugs with other users and Sim Innovations Staff

Moderators: russ, Ralph

Message
Author
Pagouti
Posts: 58
Joined: Tue Nov 19, 2019 8:19 pm

Re: Strange behavior when writing to instrument brightness dataref

#11 Post by Pagouti »

Hello Ralph, Keith, SimPassion, …

First of all: thanks for your combined efforts to get me on the track again. Interesting discussion!

I have modified the hysteresis argument. This actually divides the range in small steps: a hysteresis of 0.2 would leave 5 steps. Increasing the hysteresis setting to 0.05 has improved the behaviour of my knobs somewhat, although some jittering remains.

I have soldered a resistor of 2k7 in series with two parallel pots. That would leave about 3.2 Volt over both pots. Because I now need to perform calculations on “val”, I can no longer use the notation “{val}”. Works anyway, albeit that I have had to restore my factor 64.something. Strange, isn’t it? I have also introduced a compensation for the lower voltage over my pots. The jittering is less, but has not disappeared completely.

So far, the code for both potmeters on my dashboard is as follows:

Code: Select all

 -- A5: Draaiknop instrumentverlichting -----------------------------------------------------------------

hw_instrument_brightness_knob = hw_adc_input_add("ARDUINO_MEGA2560_A_A5", 0.05, function(val)
    xpl_dataref_write("sim/cockpit/electrical/instrument_brightness", "FLOAT", math.min(5 * 64.06158264 / 3.3 * val, 1.0))
    print("hw_instrument_brightness_knob_state = " .. tostring(math.min(5 * 64.06158264 / 3.3 * val, 1.0)))
end)


-- A6: Draaiknop dashboardverlichting ------------------------------------------------------------------

hw_panel_brightness_knob = hw_adc_input_add("ARDUINO_MEGA2560_A_A6", 0.05, function(val)
    xpl_dataref_write("sim/cockpit2/switches/panel_brightness_ratio", "FLOAT[4]", math.min(5 * 64.06158264 / 3.3 * val, 1.0))
    print("hw_panel_brightness_knob_state = " .. tostring(math.min(5 * 64.06158264 / 3.3 * val, 1.0)))
end)
At least, I manage to dim my G1000 screens. If I turn slowly, this works. Not as smoothly as with the same knob in the 3D-cockpit, but it works,

The panel brightness knob is a different story. I see its value drop to 0.0 every now and than. I am afraid that this must be a rotten pot. Or AeroBask uses another undocumented dataref to set the panel brightness in its Diamond DA62.

So far, I have not yet been able to replace the pot or add capacitors. The only electronics shop in our neighborhood had to close down.

I have read the article about moving averages. This solution seems very attractive, but I haven’t had time to try this out yet.

Many thanks for the time you have put into solving this problem.

Greetings,

Han

SimPassion
Posts: 5338
Joined: Thu Jul 27, 2017 12:22 am

Re: Strange behavior when writing to instrument brightness dataref

#12 Post by SimPassion »

Pagouti wrote: Tue Dec 19, 2023 12:54 pm .../...

The jittering is less, but has not disappeared completely.

.../...
Hi Han, I guess your pots are wired to 5V VCC, so try to wire them to 3.3V instead and have another try with some script adjustment and let us know if you observe any difference ???

Additionally, could you please, provide the list of each of all components wired to this single board and which of Air Manager input/output type is used for each of them ?

Pagouti
Posts: 58
Joined: Tue Nov 19, 2019 8:19 pm

Re: Strange behavior when writing to instrument brightness dataref

#13 Post by Pagouti »

Hi SimPassion,

I suppose the following remark got lost in the multitude: “I have soldered a resistor of 2k7 in series with two parallel pots. That would leave about 3.2 Volt over both pots.” I used the following code to recreate a range of 0.0 to 1.0 to feed into the dataref "sim/cockpit/electrical/instrument_brightness":

Code: Select all

 … xpl_dataref_write("sim/cockpit/electrical/instrument_brightness", "FLOAT", math.min(5 * 64.06158264 / 3.3 * val, 1.0) …
I have not measured the resulting voltage over the pots. Either 5 Volt is overestimated, or 3.3 Volt is underestimated, because at the high end of the range I see many occurrences of the output value 1.0. But that is a matter of fine-tuning.

I have looked for other occurrences of the dataref "sim/cockpit/electrical/instrument_brightness" in my code. There is none.

I have used nearly all connectors on the Arduino Mega, so ”the list of each of all components wired to this single board and which of Air Manager input/output type is used for each of them” will be a long list! Preparing this list will take a while. Tomorrow I have other obligations to fulfil. I will try to answer this question on thursday or friday. OK with you?

I also want to have a closer look at the code to calculate moving averages that Ralph has supplied. Moving averages might well be an answer to the erratic readings of a potmeter. I am a lousy planner, but will the weekend be fine, Ralph?

Greetings,

Han

SimPassion
Posts: 5338
Joined: Thu Jul 27, 2017 12:22 am

Re: Strange behavior when writing to instrument brightness dataref

#14 Post by SimPassion »

Hi Han, just try one potentiometer only with 3.3V to see how it behaves ...

Pagouti
Posts: 58
Joined: Tue Nov 19, 2019 8:19 pm

Re: Strange behavior when writing to instrument brightness dataref

#15 Post by Pagouti »

Hi Ralph, Keith, SimPassion, …

I have come to the conclusion that one potmeter is entirely defective and the other one has an annoying glitch at its lower end. It is hard to test a system with defective components. It is also pretty pointless to keep other people busy trying to figure out what exactly is wrong. New potmeters will arrive tomorrow. As soon as I have installed these, I will let you know the results.

Greetings,

Han

SimPassion
Posts: 5338
Joined: Thu Jul 27, 2017 12:22 am

Re: Strange behavior when writing to instrument brightness dataref

#16 Post by SimPassion »

No worries Han, it helps you going ahead and we always find source of issue when we start to investigate 👍😉

Pagouti
Posts: 58
Joined: Tue Nov 19, 2019 8:19 pm

Re: Strange behavior when writing to instrument brightness dataref

#17 Post by Pagouti »

Hi Ralph, Keith, SimPassion, …

This afternoon, I received my new potmeters and I have immediately installed them. Amazing! Instrument brightness and panel brightness change perfectly smoothly now! No glitches.

The voltages over both potmeters is slightly above 2 Volt. By applying the proper correction factor, the full range from 0.0 to 1.0 can be fed into the datarefs. I have lowered the hysteresis setting to 0.005. This results in a perfectly smooth change in brightness, from entirely obscure to fully bright. This holds for Instrument brightness as well as for panel brightness.

When still testing with defective potmeters, I have observed a strange interaction between both brightnesses. When the panel brightness was minimal, the panel brightness was also invariably minimal. If I removed the pin of the instrument brightness from the Arduino, both the instrument brightness and the panel brightness would respond to turning the panel brightness knob. These interactions (that I don’t understand at all) fully explain the observed malfunctioning of both defective potmeters.

Nothing more to complain about! Thank for all your advice and your encoragement.

Han.

Post Reply