• Which the release of FS2020 we see an explosition of activity on the forun and of course we are very happy to see this. But having all questions about FS2020 in one forum becomes a bit messy. So therefore we would like to ask you all to use the following guidelines when posting your questions:

    • Tag FS2020 specific questions with the MSFS2020 tag.
    • Questions about making 3D assets can be posted in the 3D asset design forum. Either post them in the subforum of the modelling tool you use or in the general forum if they are general.
    • Questions about aircraft design can be posted in the Aircraft design forum
    • Questions about airport design can be posted in the FS2020 airport design forum. Once airport development tools have been updated for FS2020 you can post tool speciifc questions in the subforums of those tools as well of course.
    • Questions about terrain design can be posted in the FS2020 terrain design forum.
    • Questions about SimConnect can be posted in the SimConnect forum.

    Any other question that is not specific to an aspect of development or tool can be posted in the General chat forum.

    By following these guidelines we make sure that the forums remain easy to read for everybody and also that the right people can find your post to answer it.

FSX Incrementing active frequency

Messages
17
Country
unitedkingdom
Hi Folks,

Having cracked the functionality of my RNAV, I am now reproducing the functionality of my Narco panel COM radios - these have a toggle switch enabling the pilot to change the active frequency rather than standby frequency. I have reproduced this but the quarter frequencies do not increment correctly.

I am effecting this by adding 0.025 decimal to the saved value of COM1 ACTIVE FREQUENCY

The functionality is there but the problem I am seeing is that XXX.X5 can end up as XXX.X6 and sometimes instead of XXX.X7 or XXX.X8 I can get XXX.X9 My guess is that this is becasuse FS stores quarter frequencies as BCD which effectively is a rounded second decimal place (but could be variously rounded up or down) and therefore when I add 0.025 XXX.X3 I get XXX.X55 which can then be rounded to XXX.X6 and so on. Setting the active frequency with the K:COM_RADIO_SET accepts the wrong value.

I rather assume that there is an elegant way of doing it with BCD maths (which I don't yet understand well). Any tips would be much appreciated.

Macros I am using are:

<Macro id="ConvertFrq" Name="ConvertFrq">
(L:COM1 ACTIVE FREQUENCY,MHz) 100 * near 10000 % d 10 % r 10 / int d 10 % r 10 / int d 10 % r 10 / int 16 * + 16 * + 16 * +
</Macro>

and

<Macro id="DecLarge" Name="DecLarge">
(A:COM1 ACTIVE FREQUENCY, MHz) 119 &lt;
if{ 136 (A:COM1 ACTIVE FREQUENCY, MHz) 118 - + (&gt;L:COM1 ACTIVE FREQUENCY,MHz) }
els{ (A:COM1 ACTIVE FREQUENCY, MHz) 1 - (&gt;L:COM1 ACTIVE FREQUENCY,MHz) }
@ConvertFrq
</Macro>

<Macro id="DecSmall" Name="DecSmall">
(A:COM1 ACTIVE FREQUENCY, MHz) 118.5 &lt;
if{ 136.975 (&gt;L:COM1 ACTIVE FREQUENCY,MHz) }
els{ (A:COM1 ACTIVE FREQUENCY, MHz) 0.025 - (&gt;L:COM1 ACTIVE FREQUENCY,MHz) }
@ConvertFrq
</Macro>

The outputs are then set using (&gt;K:COM_RADIO_SET)
 
I rather assume that there is an elegant way of doing it with BCD maths (which I don't yet understand well). Any tips would be much appreciated.

Yes, there is an elegant way, and besides it lets you save a bit of code:

Instead of:

Code:
<Macro id="ConvertFrq" Name="ConvertFrq">
	(L:COM1 ACTIVE FREQUENCY,MHz) 100 * near 10000 % d 10 % r 10 / int d 10 % r 10 / int d 10 % r 10 / int 16 * + 16 * + 16 * + 
</Macro>
Use:

Code:
 <Macro id="ConvertFrq" Name="ConvertFrq">
	(L:COM1 ACTIVE FREQUENCY,Frequency BCD16) 
</Macro>

And that's it.

Tom
 
I have used:-
(>K:COM_RADIO_WHOLE_INC) and (>K:COM_RADIO_WHOLE_DEC)

(>K:COM_RADIO_FRACT_INC) and (>K:COM_RADIO_FRACT_DEC)

these roll over at the end of the range.

Ted.
 
Last edited:
Clarification

Hi Tom & Ted

Tom:- the macro "ConvertFrq" is not the problem, the problem is incrementing the active frequency. However, are you saying that

(A:COM1 ACTIVE FREQUENCY, MHz) 0.025 + (&gt;L:COM1 ACTIVE FREQUENCY,Frequency BCD16)

will work reliably where

(A:COM1 ACTIVE FREQUENCY, MHz) 0.025 + (&gt;L:COM1 ACTIVE FREQUENCY,MHz)

doesn't?

Ted, I AM using K:COM_RADIO_WHOLE_INC etc when the STANDBY frequency is being changed but this does not work on ACTIVE frequencies - I am trying to reproduce the full functionality of the Narco COM 810 radio which gives the pilot the option, by flicking a switch on the radio of tuning the standby frequency OR tuning THE ACTIVE FREQUENCY DIRECTLY.

SO I am effectively trying to create equivalents of:-
K:COM_RADIO_ACTIVE_WHOLE_INC K:COM_RADIO_ACTIVE_WHOLE_DEC
K:COM_RADIO_ACTIVE_FRACT_INC K:COM_RADIO_ACTIVE_FRACT_DEC

My macros IncLarge, IncSmall, DecLarge, DecSmall are attempting to do this, but as I say they aren't working quite right.
 
Tom:- the macro "ConvertFrq" is not the problem, the problem is incrementing the active frequency. However, are you saying that

(A:COM1 ACTIVE FREQUENCY, MHz) 0.025 + (&gt;L:COM1 ACTIVE FREQUENCY,Frequency BCD16)

will work reliably where

(A:COM1 ACTIVE FREQUENCY, MHz) 0.025 + (&gt;L:COM1 ACTIVE FREQUENCY,MHz)

doesn't?

There are two aspects you must take into account when converting numbers into frequencies using K:COM_RADIO_SET

1) That big conversion formula is not really needed because you can let an LVar's internal conversion do the job.

Now, this is wrong:

(A:COM1 ACTIVE FREQUENCY, MHz) 0.025 + (&gt;L:COM1 ACTIVE FREQUENCY,Frequency BCD16)

because you are assigning a Mhz unit-value to a Frequency BCD16 unit-value, giving an unpredictable result.
What you need to do is first assign the value to its typical display unit -Mhz in this case, and then store in the stack the same variable, but with the proper unit -Frequency BCD16 that will be accepted by the event:

(A:COM1 ACTIVE FREQUENCY, MHz) 0.025 + (>L:COM1 ACTIVE FREQUENCY, MHz) (L:COM1 ACTIVE FREQUENCY,Frequency BCD16) (>K:COM_RADIO_SET)


2) When displaying a COM value obtained with this method, you must pay attention to possible formatting issues. It is not the same to show a frequency with 2 decimal places than to show it with 3, because of a rounding factor.When using 2 decimals, writing %((A:COM1 Active Frequency,Mhz) 0.00001 +)%!3.2f! will do the trick.

Besides,when adding or substracting values to the frequency, a floating point factor must be considered as well.
For example, in a subtraction:

(A:COM1 ACTIVE FREQUENCY, MHz) 0.025 - 0.00001 + (>L:COM1 ACTIVE FREQUENCY,MHz)
(L:COM1 ACTIVE FREQUENCY,Frequency BCD16) (>K:COM_RADIO_SET)

The factor correction in red will avoid a floating point offset that could show at some point(s) of the range

And the same for an addition:

(A:COM1 ACTIVE FREQUENCY, MHz) 0.025 + 0.00001 + (>L:COM1 ACTIVE FREQUENCY,MHz)
(L:COM1 ACTIVE FREQUENCY,Frequency BCD16) (>K:COM_RADIO_SET)



Hope this helps,

Tom
 
Factor correction

Hi Tom, many thanks - the factor correction was the key. Next job is to develop the Narco HSI 100. Thanks again.
 
Back
Top