Unless I'm misunderstanding something, which is always possible, I think I've found an anomaly with Proton's floating point routine.
From page 51 of the manual...
Float type variables may theoretically hold a value from -1e37 to +1e38, but because of
the 32-bit architecture of the compiler, a maximum and minimum value should be
thought of as -2147483646.999 to +2147483646.999 making this the most versatile of
the variable family types.
However, I'm finding that numbers greater than 8388607 (2^23 -1) change to zero. This makes me wonder if there is something amiss with that part of the floating point routine which deals with the number exponent.
Before reporting this formally as an anomaly, could someone try out this code and see if they obtain the same results as myself? That is numbers greater than 8388607 become 0. Also, if I'm doing something stupid, please let me know!
Code:
Device = 18F25K22
Xtal = 64
Declare All_Digital = true
'Calculated Baudrate = 115108 @ Xtal 64MHz, Error = -0.08%
Declare Hserial_RCSTA = 144 ; Enable continuous receive
Declare Hserial_TXSTA = 36 ; Enable transmit, BRGH = 1
Declare Hserial_Clear = On ; Clear overflow automatically
Declare Hserial_SPBRG = 138 ; Baud Rate Generator Low Byte Value
SPBRGH = 0 ; Baud Rate Generator High Byte Value
BAUDCON.3 = 1 ; Enable the 16 bit Baud Rate Generator
;-------------------------------------------------------------------------------
Dim TestVar1 As Float = 8388600.0
Dim TestVar2 As Float = 0
Main:
HSerOut ["TestVar1 = ",Dec3 TestVar1,13,10]
TestVar2 = TestVar1/100
HSerOut ["TestVar2 = ",Dec3 TestVar1,13,10,13,10]
TestVar1 = TestVar1 + 1
DelayMS 1000
GoTo Main
End
' **** Added by Fuse Configurator ****
' Use the Fuse Configurator plug-in to change these settings
Config_Start
FOSC = HSMP ;HS oscillator (medium power 4-16 MHz)
PLLCFG = On ;Oscillator multiplied by 4
PRICLKEN = On ;Primary clock enabled
FCMEN = OFF ;Fail-Safe Clock Monitor disabled
IESO = OFF ;Oscillator Switchover mode disabled
PWRTEN = OFF ;Power up timer disabled
BOREN = SBORDIS ;Brown-out Reset enabled in hardware only (SBOREN is disabled)
BORV = 190 ;VBOR set to 1.90 V nominal
WDTEN = Off ;WDT is always enabled. SWDTEN bit has no effect
WDTPS = 32768 ;1:32768
CCP2MX = PORTC1 ;CCP2 input/output is multiplexed with RC1
PBADEN = On ;PORTB<5:0> pins are configured as analog input channels on Reset
CCP3MX = PORTB5 ;P3A/CCP3 input/output is multiplexed with RB5
HFOFST = On ;HFINTOSC output and ready status are not delayed by the oscillator stable status
T3CMX = PORTC0 ;T3CKI is on RC0
P2BMX = PORTB5 ;P2B is on RB5
MCLRE = EXTMCLR ;MCLR pin enabled, RE3 input pin disabled
STVREN = On ;Stack full/underflow will cause Reset
LVP = On ;Single-Supply ICSP enabled if MCLRE is also 1
XINST = OFF ;Instruction set extension and Indexed Addressing mode disabled (Legacy mode)
Debug = OFF ;Disabled
Cp0 = OFF ;Block 0 (000800-001FFFh) not code-protected
CP1 = OFF ;Block 1 (002000-003FFFh) not code-protected
CP2 = OFF ;Block 2 (004000-005FFFh) not code-protected
CP3 = OFF ;Block 3 (006000-007FFFh) not code-protected
CPB = OFF ;Boot block (000000-0007FFh) not code-protected
CPD = OFF ;Data EEPROM not code-protected
WRT0 = OFF ;Block 0 (000800-001FFFh) not write-protected
WRT1 = OFF ;Block 1 (002000-003FFFh) not write-protected
WRT2 = OFF ;Block 2 (004000-005FFFh) not write-protected
WRT3 = OFF ;Block 3 (006000-007FFFh) not write-protected
WRTC = OFF ;Configuration registers (300000-3000FFh) not write-protected
WRTB = OFF ;Boot Block (000000-0007FFh) not write-protected
WRTD = OFF ;Data EEPROM not write-protected
EBTR0 = OFF ;Block 0 (000800-001FFFh) not protected from table reads executed in other blocks
EBTR1 = OFF ;Block 1 (002000-003FFFh) not protected from table reads executed in other blocks
EBTR2 = OFF ;Block 2 (004000-005FFFh) not protected from table reads executed in other blocks
EBTR3 = OFF ;Block 3 (006000-007FFFh) not protected from table reads executed in other blocks
EBTRB = OFF ;Boot Block (000000-0007FFh) not protected from table reads executed in other blocks
Config_End
;**** End of Fuse Configurator Settings ****
;----------------------------------
I'm using Proton 3.5.8.4 on Windows 10.
Thanks,
Bob