Re: HSI Pulse Range Counter Display - How to manipulate in SIOC?
Hi Nico,
More great news!
I have now, using the following script, managed to initiate and UP or DOWN pulse from just 2 buttons. Previously, we had to use 3, with the third button controlling the UPDOWN_Pin Output. Now, however, this is done automatically upon pressing the button.
This proves that an UP/DOWN count can be initiated immediately upon being commanded to do so, without needing to set the UP/DOWN Pin through some other instruction.
Code:
Code:
Var 0 Value 0
{
&Out = 1
&UPDOWN_Pin = 1 // count down
CALL &Pulses 2 // correct for first OFF/ON pulse at startup
}
Var 99 name Trigger3 Link IOCARD_SW Input 18 Type P
{
IF &Trigger3 = 1
{
&UPDOWN_Pin = 1
CALL &Pulses 10
}
}
Var 98 name Trigger4 Link IOCARD_SW Input 23 Type P
{
IF &Trigger4 = 1
{
&UPDOWN_Pin = 0
CALL &Pulses 10
}
}
Var 1 name Pulses link SUBRUTINE // parameter is number of pulses ...
{
&Out = 0
&PulseUp = DELAY &Pulses 9 // 50 msec for a half pulse
}
Var 3 name Out Link IOCARD_OUT Output 29 // Pulse Pin
Var 11 name PulseUp
{
L0 = &PulseUp
IF L0 > 0
{
&Out = 1
&Finish = DELAY L0 9 // 50 msec for the other half of the pulse
}
}
Var 12 name Finish
{
L0 = &Finish
IF L0 > 0
{
IF L0 > 1
{
L0 = L0 - 1
CALL &Pulses L0 // recursive subroutine call
}
ELSE
{
&PulseUp = 0 // make responsive for another series of pulses.
&Finish = 0 // make responsive for another series of pulses.
}
}
}
Var 55, name UPDOWN_Pin, Link IOCARD_OUT, Output 21 // Count UP or DOWN selector Pin
Var 84, name RangeFlag, Link IOCARD_OUT, Output 17 // Range Flag
Kindest regards,
Jack
Re: HSI Pulse Range Counter Display - How to manipulate in SIOC?
Hi Jack,
Understood. Just change in Var 0:
Code:
&UPDOWN_Pin = 1 // count down
into
Code:
&UPDOWN_Pin = 1 // count up
Programmers often forget to update the commentary parts when they change their code.
Regards,
Nico
P.S. Some people even state that it is better not to comment at all. They claim that it is better to have no comment then a wrong comment... ;-)
Re: HSI Pulse Range Counter Display - How to manipulate in SIOC?
Hi Nico,
All done! What's next on the agenda?:D
Jack
Re: HSI Pulse Range Counter Display - How to manipulate in SIOC?
Hi Nico,
What should I do next? Should I just try and implement the (new) pulse code into the full script, or should I do some more testing (ie: one step at a time) before I run the full thing?
Kindest regards,
Jack
Re: HSI Pulse Range Counter Display - How to manipulate in SIOC?
Hi Jack,
I would first run a test script with just the NewDistance offset (so no Pulses routine at all).
Fly to, over and past a VOR and write the NewDistance value to a 3 digit display.
This will give you information upon which you can base the Control algorithm
regards,
Nico
Re: HSI Pulse Range Counter Display - How to manipulate in SIOC?
Hi Nico,
I have tried that, watching the value of the VOR1 DME change according to offset $0300.
It does indeed work perfectly, so no problems with this offset.
Regards,
Jack
Re: HSI Pulse Range Counter Display - How to manipulate in SIOC?
Hi Jack,
If you are sure about the values coming from NewDistance then try the complete Control script from posts #13 and #14, adapted with the 'inverted Pulses code' and the Var 0 code of post #31
regards,
Nico
Re: HSI Pulse Range Counter Display - How to manipulate in SIOC?
Hi Nico,
How is this:
Code:
Var 0 Value 0
{
&Out = 1
&CurrentD = 0
&Control = 0
&Control = TIMER 1 0 100 // control is called each second
&UPDOWN_Pin = 1 // count up
CALL &Pulses 1 // correct for first OFF/ON pulse at startup
}
Var 100 name Control Link SUBRUTINE
{
L0 = &NewDistance - &CurrentD
IF L0 <> 0
{
&UPDOWN_Pin = 1 // Ensure HSI counts UP
IF L0 > 9
{
L0 = 9 // no more then 9 pulses per second
&CurrentD = &CurrentD + 9
}
ELSE
{
&CurrentD = &NewDistance
}
}
ELSE
{
&UPDOWN_Pin = 0 // We don't want to count up here!
L0 = L0 * -1
IF L0 > 9
{
L0 = 9 // no more then 9 pulses per second
&CurrentD = &CurrentD - 9
}
ELSE
{
&CurrentD = &NewDistance
}
}
CALL &Pulses L0
}
Var 1, name CurrentD
Var 2, name UPDOWN_Pin, Link IOCARD_OUT, Output 21 // Count UP or DOWN selector Pin
Var 4, name Out, Link IOCARD_OUT, Output 29 // Pulse Pin
Var 5, name NewDistance, Link FSUIPC_IN, Offset $0300, Length 2 // FSUIPC VOR1 DME Input Source
Var 43 name Pulses link SUBRUTINE // parameter is number of pulses ...
{
&Out = 0
&PulseUp = DELAY &Pulses 9 // 50 msec for a half pulse
}
Var 11 name PulseUp
{
L0 = &PulseUp
IF L0 > 0
{
&Out = 1
&Finish = DELAY L0 9 // 50 msec for the other half of the pulse
}
}
Var 12 name Finish
{
L0 = &Finish
IF L0 > 0
{
IF L0 > 1
{
L0 = L0 - 1
CALL &Pulses L0 // recursive subroutine call
}
ELSE
{
&PulseUp = 0 // make responsive for another series of pulses.
&Finish = 0 // make responsive for another series of pulses.
}
}
}
Var 84, name RangeFlag, Link IOCARD_OUT, Output 17 // Range Flag
If you can see anything wrong please tell me and I shall correct it right away.
Kindest regards,
Jack
Re: HSI Pulse Range Counter Display - How to manipulate in SIOC?
Hi Nico,
I have tested the new pulses script.
Firstly, for some reason, &pulses must now only be called ONCE instead of TWICE at startup.
This is the exact script I am using:
Code:
Var 0 Value 0
{
&Out = 1
&CurrentD = 0
&Control = 0
&Control = TIMER 1 0 100 // control is called each second
&UPDOWN_Pin = 1 // count up
CALL &Pulses 1 // correct for first OFF/ON pulse at startup
}
Var 100 name Control Link SUBRUTINE
{
L0 = &NewDistance - &CurrentD
IF L0 <> 0
{
&UPDOWN_Pin = 1 // Ensure HSI counts UP
IF L0 > 9
{
L0 = 9 // no more then 9 pulses per second
&CurrentD = &CurrentD + 9
}
ELSE
{
&CurrentD = &NewDistance
}
}
ELSE
{
&UPDOWN_Pin = 0 // We don't want to count up here!
L0 = L0 * -1
IF L0 > 9
{
L0 = 9 // no more then 9 pulses per second
&CurrentD = &CurrentD - 9
}
ELSE
{
&CurrentD = &NewDistance
}
}
CALL &Pulses L0
}
Var 1, name CurrentD
Var 2, name UPDOWN_Pin, Link IOCARD_OUT, Output 21 // Count UP or DOWN selector Pin
Var 4, name Out, Link IOCARD_OUT, Output 29 // Pulse Pin
Var 5, name NewDistance, Link FSUIPC_IN, Offset $0300, Length 2 // FSUIPC VOR1 DME Input Source
Var 43 name Pulses link SUBRUTINE // parameter is number of pulses ...
{
&Out = 0
&PulseUp = DELAY &Pulses 9 // 50 msec for a half pulse
}
Var 11 name PulseUp
{
L0 = &PulseUp
IF L0 > 0
{
&Out = 1
&Finish = DELAY L0 9 // 50 msec for the other half of the pulse
}
}
Var 12 name Finish
{
L0 = &Finish
IF L0 > 0
{
IF L0 > 1
{
L0 = L0 - 1
CALL &Pulses L0 // recursive subroutine call
}
ELSE
{
&PulseUp = 0 // make responsive for another series of pulses.
&Finish = 0 // make responsive for another series of pulses.
}
}
}
Var 84, name RangeFlag, Link IOCARD_OUT, Output 17 // Range Flag
The problem is not the pulsing script at all; it is the calculation for the pulses.
For some reason, after setting a VOR station that is 1.6 miles away (16 pulses), the HSI only went up to 0.9 (9 pulses). Also, when I tuned a non-existant VOR station (in other words, "0" miles away), the script did not count down. So, to summarize, the problems are:
- Script does not count up enough
- Script does not count down at all
The NewDistance variable changes value accordingly, but the rest of the script does not function correctly. It looks fine to myself, and I cannot see what particular bit is casuing the issue.
Just to reiterate, it is no longer a pulsing issue - That works fine. It is the calculation to calculate the number of pulses.
Regards,
Jack
Re: HSI Pulse Range Counter Display - How to manipulate in SIOC?
Hi Jack,
Two problems:
You miss a test on L0 > 0 in Var 100.
The pulse correction in Var 0 must be done before calling control. Maybe you need 2 again now...
Here is the updated script, please test again:
Code:
Var 0 Value 0
{
&Out = 1
&CurrentD = 0
&UPDOWN_Pin = 1 // count up
CALL &Pulses 2 // correct for two OFF/ON pulse at startup
&Control = 0
&Control = TIMER 1 0 100 // control is called each second
}
Var 100 name Control Link SUBRUTINE
{
L0 = &NewDistance - &CurrentD
IF L0 <> 0
{
IF L0 > 0
{
&UPDOWN_Pin = 1 // Ensure HSI counts UP
IF L0 > 9
{
L0 = 9 // no more then 9 pulses per second
&CurrentD = &CurrentD + 9
}
ELSE
{
&CurrentD = &NewDistance
}
}
ELSE
{
&UPDOWN_Pin = 0 // We don't want to count up here!
L0 = L0 * -1
IF L0 > 9
{
L0 = 9 // no more then 9 pulses per second
&CurrentD = &CurrentD - 9
}
ELSE
{
&CurrentD = &NewDistance
}
}
CALL &Pulses L0
}
}
Var 1, name CurrentD
Var 2, name UPDOWN_Pin, Link IOCARD_OUT, Output 21 // Count UP or DOWN selector Pin
Var 4, name Out, Link IOCARD_OUT, Output 29 // Pulse Pin
Var 5, name NewDistance, Link FSUIPC_IN, Offset $0300, Length 2 // FSUIPC VOR1 DME Input Source
Var 43 name Pulses link SUBRUTINE // parameter is number of pulses ...
{
&Out = 0
&PulseUp = DELAY &Pulses 9 // 50 msec for a half pulse
}
Var 11 name PulseUp
{
L0 = &PulseUp
IF L0 > 0
{
&Out = 1
&Finish = DELAY L0 9 // 50 msec for the other half of the pulse
}
}
Var 12 name Finish
{
L0 = &Finish
IF L0 > 0
{
IF L0 > 1
{
L0 = L0 - 1
CALL &Pulses L0 // recursive subroutine call
}
ELSE
{
&PulseUp = 0 // make responsive for another series of pulses.
&Finish = 0 // make responsive for another series of pulses.
}
}
}
Var 84, name RangeFlag, Link IOCARD_OUT, Output 17 // Range Flag
regards,
Nico