How to read out COM Frequencies (by Sim Variables, in python)

I tried this conversion and it seemed accurate:

// Converts from binary coded decimal to integer
public static uint Bcd2Dec(uint num) { return HornerScheme(num, 0x10, 10); } 
        
/// Converts from integer to binary coded decimal
public static uint Dec2Bcd(uint num) { return HornerScheme(num, 10, 0x10); } 

static private uint HornerScheme(uint Num, uint Divider, uint Factor) 
{ 
     uint Remainder = 0, Quotient = 0, Result = 0; 
     Remainder = Num % Divider; Quotient = Num / Divider; 
            
     if (!(Quotient == 0 && Remainder == 0)) 
         Result += HornerScheme(Quotient, Divider, Factor) * Factor + Remainder; return Result; 
 }

With COM1 set to 120.95 in the sim, I got 8341.00. After decoding the value using BCD2DEC() function above, I got 2095. Convert to double, divide by 100, add 100.00 and you’ll have the 120.95.

3 Likes