View Full Version : Can SOIC handle switch bounce?
I have a micro switch working with a 10" long lever for my canopy switch. In trying to get it to open properly with SOIC I kept running into problems with the opening and closing of the canopy getting out of sequence.
Using the logging function of SOIC (SOIC Config?) I noticed switch bouncing and multiple contacts at times. The code is set to set and clear the 0 bit of the offset. I think this is screwing up the sequence.
Is there a way to delay the switch reading for a few milliseconds?
fordgt40
10-20-2009, 03:58 AM
John
It could be that the SIOC code is too fast for the hardware. Try inserting a software delay between reading and resetting the offset. There is an example of the SIOC DELAY function on Nicos` site here
http://www.lekseecon.nl/howto.html
Regards
David
The DELAY function won't help here. I am getting a manual switch bounce. the long lever and torque created is causing the little micoswitch to open and close two or three times when the handle is moved to close the switch.
DELAY will only delay the sim action. I need to have a delay between the time the switch closes and SOIC reads it closed. Otherwise, it is redesign the entire mechanism which, of course, is not easy to get to without removing the ejection seat, side panel, etc.
Ahhhh, such is a sim builder's life. :rolleyes:
Hi John,
The Master Card of OC takes care of de-bouncing, but I assume your switch bouncing is too long stretched in time.
You can either solve that with extra hardware: http://www.electronixexpress.com/t_bounc.htm
or you can solve this in SIOC, with the DELAY function and a sempahore, it goes like this:
Var 1 Value 0 // semaphore
Var 2 Link IOCARD_SW Input xy // connected to your switch
{
IF v1 = 0
{
v1 = 1 // set semaphore
v3 = DELAY v2 50 // assign v2 to v3 after .5 second
}
}
Var 3
{
v1 = 0 // reset semaphore
L0 = v3 // L0 contains the de-bounced input
// ...
}
Regards,
Nico Kaan
Thanks Nico! I will try this tonight.
Okay, let me know the result.
I was wondering, maybe it is even more reliable to take v2 as end result so in Var 3 write:
L0 = v2 // L0 contains the de-bounced input
Nico
CrashEd
10-20-2009, 08:08 AM
Obviously if you can do it in software that would be the easiest route, but if not you could do it in hardware. A simple RC circuit would do it, but you'd need power:
http://www.electronixexpress.com/t_bounc.htm
Depends how handy you are with a soldering iron.
fordgt40
10-20-2009, 01:58 PM
Nico
Thanks, I knew there would be a way of solving this in SIOC.
Regards
David
Okay, let me know the result.
I was wondering, maybe it is even more reliable to take v2 as end result so in Var 3 write:
Nico
OK Nico, I have it working and it seems to help some? i am still getting out of sync but it could be something else. Here is my code snippet. See if i manged to code it the way you were thinking.
I still think I will redesign the switch sometime. It is just too loose with no feel.
// ************************** Canopy ********************************
Var 8000, Value 0 // Initialization
Var 8001, name canopysw, Link IOCARD_SW, Input 7, TYPE I
{
IF V8000 = 0
{
&canopysw = 1
&canopy = DELAY &canopysw 50 // assign .5 delay to canopysw
}
}
Var 8002, name canopy, Link FSUIPC_INOUT, Offset $3367, Length 1
{
V8000 = 0
L0 = &canopy
}
Hi,
Isnt there a mistake in the script, I think it should be like the following :
Var 8000, Value 0 // Initialization
Var 8001, name canopysw, Link IOCARD_SW, Input 7, TYPE I
{
IF V8000 = 0
{
V8000 = 1
&canopy = DELAY &canopysw 50 // assign .5 delay to canopysw
}
}
Var 8002, name canopy, Link FSUIPC_INOUT, Offset $3367, Length 1
{
V8000 = 0
L0 = &canopy
}
another solution is to do the following :
when the canopy switch changes, the V8000 is set to 1 and the fsuipc offset
is written immediately but the following updates of the canopysw are not possible
since V8000 is 1. Only after the delay time the V8000 is reset to 0 allowing further
updates of the canopysw
(Niko, correct me if Im wrong here!)
Var 8000, name canopyUpdate, Value 0 // Initialization
Var 8001, name canopysw, Link IOCARD_SW, Input 7, TYPE I
{
IF &canopyUpdate = 0
{
&canopyUpdate = 1
&canopy = &canopysw
&canopyUpdate = DELAY 0 50
}
}
Var 8002, name canopy, Link FSUIPC_INOUT, Offset $3367, Length 1
John,
Peter is right,
&canopysw = 1
should be
v8000 = 1
like in my example code.
I am a bit surprised about the FSUIPC offset popping up... I thought you hade a problem with a bouncing switch? I don't think you should
mix up these two. Get a 'clean' value for your switch first and then continue with the FSUIPC offset.
What do you want to do with that FSUIPC offset in relation to your switch?
regards,
Nico
Hi Nico & Peter,
Thanks for your expert eyes and SOIC minds helping. The reason I changed the V=8000 to &canopysw was, SOIC's complier kept giving me an error with v=8000. (Command out of place) I checked and I had typed it as Nico suggested, with the changing of Var #s to their named counterparts.
I didn't know if I could mix Var 8000 with names and, I thought maybe that was the problem? When I changed it to &canopysw it worked????
As to what I want to accomplish:
This is a fighter cockpit. Fighters (at least when I flew them) start with the canopy open. I want to be able to load a FSX fighter and have the canopy open during start up and checks.
I then want to move the lever and connect the switch. The canopy should then close. I want the code to detect if the lever is forward (canopy closed) or backward (canopy open) and have SOIC set the FSX canopy to be in sync with my lever.
What I am experiencing is that the FSX airplanes always start with the canopy closed. I guess I could save a flight back in the chocks cold & dark with the canopy open? However, unlike you guys I will fly a dozen different airplanes from the T-6II or T-45 trainers to the F-16 or F18.
I thought the manual cockpit switch and SOIC could handle the syncing of the virtual and real cockpits?
Does this make sense to you?
Aha, now I understand!
I thought you had a typo in the name cancopy... being a 767 pilot I did not know what a canopy is, had to look that up in the english dictionary :-)
It should be possible to synchronise, you could try this code:
Var 8000 name semaphore Value 0
Var 8001 name canopyswitch Link IOCARD_SW Input 7 Type I
{
IF &semaphore = 0
{
&semaphore = 1
v8002 = DELAY &canopyswitch 50 // assign after .5 delay
}
}
Var 8002
{
&semaphore = 0
&canopy = &canopyswich
}
Var 8003 name canopy Link FSUIPC_OUT Offset $3367 Length 1
Nico
BTW it is SIOC not SOIC ... ;-)
Aha, now I understand!
I thought you had a typo in the name cancopy... being a 767 pilot I did not know what a canopy is, had to look that up in the english dictionary :-)
BTW it is SIOC not SOIC ... ;-)
:D Okay class, today's lesson will be a Topsy turby class on "Yanking and Banking" followed tomorrow by a hi-pressure and fiery class on G-forces and Afterburners.
I gotta teach you guys what "real" flying is like, :cool:
Thanks for the code, Nico. I will try it and let you know.
P.S. didn't I tell you I am dyslexic? :mrgreen: Really am!
Well Nico & Peter, thanks to you two I have the canopy switch working. Thanks.
FSX is still being FSX, however. When the airplane is loaded into FSX the canopy is closed. I have to use the shift-e to open it, then my switch will work correctly.
I tried saving a flight with the canopy open. When you load the flight, the canopy is closed. Grurrrrrr!
I don't know how to get the flight to load with an open canopy?
This might be related to the fact that if you start SIOC before you load a fighter flight, the SIOC code has been executed (according to the position of your switch) before the Flight is loaded.
You could try to start SIOC after you have loaded your (saved with open canopy) fighter flight...
Nico
Hi there,
some time ago had made a script which did something regarding the fuel status of a plane.
Some problem that occurred with this is that when I loaded a new plane the fuel tank size
changes and my script needed to get a trigger to recalculate some things. I had this solved
by also reading the planes id on some offset, dont know exatly anymore which offset. But if you like I could find it back. The thing is that in the case the name, or tail number changes that offset changed and without caring of whats the value in it, you can let the script then update the canopy fsuipc offset to align with the state of the canopy switch.
This could also solve the fact if sioc is running before fs is running.
Try and error...thats the way to learn in this case...sioc is powerfull enough to accomodate
clever things ...
Also, in my setup, wideFS starts when the computer starts but wideFS starts SIOC only when
widefs connected to FS. This is a feature of widefs. I think it is something called RunDelay or Run ...
If FS starts, with a fighter with closed canopy, a little later the SIOC is started and the canopy
should take the state of the canopyswitch.
Greetz Peter
Those are good idea Peter & Nico. I could set FSUIPC to start SIOC. However, if I change aircraft without closing and restarting FSX, I would be back where we started.
The offset used for the canopy is a toggle offset. Is there a way to send a one time toggle to the offset right after the aircraft loads and, then run the switch position routine?
Could I just start the canopy routine with a toggle command and then initialize it to the switch position?
Just thinking out loud here. Thanks again for all of your suggestions.
Hi Jmig,
that is exactly what I was trying to explain. Give your different fighters in FS a different plane tail ids
Example
Var 0007, name Lv_PlaneId, Link FSUIPC_IN, Offset $313C, Length 4
{
// assuming one of the airbus setups
&Lv_Plane = 0
// check for twin otter C-GND
if &Lv_PlaneId = 1313287491
{
&Lv_Plane = 1
}
// check for learjet N456
if &Lv_PlaneId = 909456462
{
&Lv_Plane = 2
}
// check for beechcraft baron 58 with N058SN or N058BE
// for the moment we will treat beech baron 58 as the twin otter
if &Lv_PlaneId = 943009870
{
&Lv_Plane = 1
}
}
Var 0008, name Lv_Plane
{
send here the canopy trigger to FS
}
In above script only the four first letters of the plane id are taken into account
and if your plane changes then the Lv_Plane variable will change and here you can trigger
the a change of the canopy
PS : this is a piece of my SIOC script and depending on which plane is loaded the script will
behave different upon the same hardware inputs
Greetz Peter
Hi, I was just looking at the FSUIPC offset table in the project magenta site and noticed
the following offset :
3364 1 FS2004 “Ready to Fly” indicator. This is non-zero when FS is loading, or reloading a
flight or aircraft or scenery, and becomes zero when flight mode is enabled (even
if the simulator is paused or in Slew mode).
Possibly interesting to solve some problems as in the previous post
greetz Peter
Thanks Peter. I have been out of touch with the internet world for the past few days. I will look into this when I get a chance.