Menu

LongINT & uLongINT

Help
JB
2024-12-04
2025-05-15
1 2 > >> (Page 1 of 2)
  • JB

    JB - 2024-12-04

    Hello,
    this is a question about ( LongINT & uLongINT )

    what is needed to use the advance variable type with the PIC18F14K22 :
    Compiler Version: 2024.10.17 (Windows 64 bit) : Build 1441) Program Memory: 31/8192 words (0.38%) RAM: 4/512 bytes (0.78%) OSC: IRC, 64Mhz (Internal oscillator) Chip: 18F14K22

    on the help document it's refer for "Developers Only" libraries

    I'm trying to write a counter that start at 0 and stop at 9999999999. (10 digits) no fraction
    after convert it to UPC-A barcode ready to calculate the checksum.

    I reviewed the video showing the progress to date from Evan "GCBASIC: Floats progress to date using build 1344" Feb 29, 2024

    And for sure, this is a lot of work for Evan and his team.
    my guess is maybe soon libraries will be available to use directly into GCBasic IDE.

    Thanks

     
  • Anobium

    Anobium - 2024-12-04

    Let me answer.

    In Pref Editor, select the compiler tab and select 'Enable Single Advanced Variable Support'. This will tell the compiler to handle these advanced variables.

    Now you need to edit USE.INI and change floatcapability = 4 The help in your USE.INI will explain why you need = 4

    But, as shown in the Help:

    with respect to used advanced variables - please use Singles in your program as these have been tested. The other types are documented for completeness and should be used by developers in libraries.

    We tested 'singles' not 'LongInt'. See https://github.com/GreatCowBASIC/Demonstration_Sources/tree/main/AdvancedVariableSolutions/SingleVariableType_Solutions for the extent of this testing. It was extensive.


    Can you point me to 'on the help document it's refer for "Developers Only" libraries'. I should review and update as needed.


    Certain methods will need to ne written in your own solution. Example, HSerPrint does not yet support LongInt. You need to write the new sub to handle the new range of -9999999999999990 to 9999999999999990. Simple base the new subs on existing work.

    So, you have some supporting subs/functions with the basics all working.

    Because we tested 'singles' you may/will have issues. Most issues have work arounds.

    I just tested a for-next loop. It failed but there is a workaround.

    #chip PIC16F886
    #option explicit
    
    #DEFINE USART_BAUD_RATE 9600
    #DEFINE USART_TX_BLOCKING
    #DEFINE USART_DELAY OFF
    
    dim myLongInt as LongInt
    
    for myLongInt = 0 to 9999
    
        HSerPrint ByteToHex(MYLONGINT_A)
        HSerPrint ByteToHex(MYLONGINT_B)
        HSerPrint ByteToHex(MYLONGINT_C)
        HSerPrint ByteToHex(MYLONGINT_D)
        HSerPrint ByteToHex(MYLONGINT_E)
        HSerPrint ByteToHex(MYLONGINT_U)
        HSerPrint ByteToHex(MYLONGINT_H)
        HSerPrint ByteToHex(MYLONGINT)
        HserPrintCRLF
    
    Next
    

    A do-loop will give you a loop with an increment.

    Do
    
        HSerPrint ByteToHex(MYLONGINT_A)
        HSerPrint ByteToHex(MYLONGINT_B)
        HSerPrint ByteToHex(MYLONGINT_C)
        HSerPrint ByteToHex(MYLONGINT_D)
        HSerPrint ByteToHex(MYLONGINT_E)
        HSerPrint ByteToHex(MYLONGINT_U)
        HSerPrint ByteToHex(MYLONGINT_H)
        HSerPrint ByteToHex(MYLONGINT)
        HserPrintCRLF
        myLongInt++
    
    Loop
    

    The root cause to the issue above is unknown to me. It could ( most probably ) compare at the end of the for-next loop. Therefore, a missing handler for SYSCOMPLESSTHAN / Longint which would require resolving.


    Ask questions. I can help answer.

     
  • JB

    JB - 2024-12-04

    Hello Evan,
    Thanks for all the info's I'll start testing

    as for the 'on the help document ', it's on the HTML Help document as show here.

     
    • Anobium

      Anobium - 2024-12-05

      That makes sense. As we have tested on Singles. Thanks for clarification.

       
  • JB

    JB - 2024-12-05

    Here's some code
    I read the USE.INI, since the test use single I left as is (floatcapability = 1)

    Code # 1 : the first value is displayed ok (5.0) all other display "Error"

    #chip 18F14K22 , 64
    #option explicit
    #DEFINE SYSDEFAULTCONCATSTRING 0
    #include <SoftSerial.h>
    
        ; ----- Config Serial UART for sending:
        #define Ser1_BAUD 9600     ;LCD117 baudrate must be defined
        #define Ser1_TXPORT PORTA  ; I/O port (without .bit) must be defined
        #define Ser1_TXPIN 4       ; portbit  must be defined
        #define Ser1_INVERT OFF     ; Polarity inverted On/Off
        #define Ser1_TXDELAY 1    ; Tx delay
        ;#define Ser1_TXDELAYms 10    ; Tx delay (min:1/1.3ms)
        ;#define Ser1_TXDELAYus 300    ; Tx delay (min:300/400us)
    
    
    dir porta.5 out
    Dim UPC as Single
    pause 500
    ser1Print "?f" ; Lcd Clear
    pause 500
    
      for UPC = 5 TO 9
       Ser1Print (SingleToString(UPC))
       pause 1500
       ser1Print "?f" ; Lcd Clear
     NEXT
    

    Code # 2: All separate value are displayed ok (1.0,2.0,3.0,4.0)

    #chip 18F14K22 , 64
    #option explicit
    #DEFINE SYSDEFAULTCONCATSTRING 0
    #include <SoftSerial.h>
    
        ; ----- Config Serial UART for sending:
        #define Ser1_BAUD 9600     ;LCD117 baudrate must be defined
        #define Ser1_TXPORT PORTA  ; I/O port (without .bit) must be defined
        #define Ser1_TXPIN 4       ; portbit  must be defined
        #define Ser1_INVERT OFF     ; Polarity inverted On/Off
        #define Ser1_TXDELAY 1    ; Tx delay
        ;#define Ser1_TXDELAYms 10    ; Tx delay (min:1/1.3ms)
        ;#define Ser1_TXDELAYus 300    ; Tx delay (min:300/400us)
    
    
    dir porta.5 out
    Dim UPC as Single
    pause 500
    ser1Print "?f" ; Lcd Clear
    pause 500
    
     UPC = 1
       Ser1Print (SingleToString(UPC))
       pause 1500
       ser1Print "?f" ; Lcd Clear
     UPC = 2
       Ser1Print (SingleToString(UPC))
       pause 1500
       ser1Print "?f" ; Lcd Clear
     UPC = 3
       Ser1Print (SingleToString(UPC))
       pause 1500
       ser1Print "?f" ; Lcd Clear
     UPC = 4
       Ser1Print (SingleToString(UPC))
       pause 1500
       ser1Print "?f" ; Lcd Clear
    

    Code # 3: when using Long all value are displayed ok (5.0,6.0,7.0,8.0,9.0)

    #chip 18F14K22 , 64
    #option explicit
    #DEFINE SYSDEFAULTCONCATSTRING 0
    #include <SoftSerial.h>
    
        ; ----- Config Serial UART for sending:
        #define Ser1_BAUD 9600     ;LCD117 baudrate must be defined
        #define Ser1_TXPORT PORTA  ; I/O port (without .bit) must be defined
        #define Ser1_TXPIN 4       ; portbit  must be defined
        #define Ser1_INVERT OFF     ; Polarity inverted On/Off
        #define Ser1_TXDELAY 1    ; Tx delay
        ;#define Ser1_TXDELAYms 10    ; Tx delay (min:1/1.3ms)
        ;#define Ser1_TXDELAYus 300    ; Tx delay (min:300/400us)
    
    
    dir porta.5 out
    Dim UPC as Long  ;Single
    pause 500
    ser1Print "?f" ; Lcd Clear
    pause 500
    
      for UPC = 5 TO 9
       Ser1Print (SingleToString(UPC))
       pause 1500
       ser1Print "?f" ; Lcd Clear
     NEXT
    

    Thanks again Evan for your time.

     
  • Anobium

    Anobium - 2024-12-05

    OK. Interesting.

    First thing I need you to do it to change from the LCD to a serial terminal. We cannot debug on an LCD. Secondly, I need to change to hardware serial - this is required to rule any issues in the software serial routines. These two changes will also permit me to replicate the same setup, and, more importantly this will minimise the number of libraries used. Once you have the hardware serial working then you can revert/test on software serial.

    So, the string 'ERROR' comes from function FN_SINGLETOSTRING. Something is not correct.

    Changing the code as follows .. works.

    #DEFINE USART_BAUD_RATE 9600
    #DEFINE USART_TX_BLOCKING
    #DEFINE USART_DELAY OFF
    
    Dim UPC as Single
    
    for UPC = 5 TO 9 step 1
        HserPrint (SingleToString(UPC))
        HserPrintCRLF
    NEXT
    

    Comment out the HserPrintCRLF and it fails!! That is odd. So, something is getting walked over in memory is my guess.

    Please confirm you get the same results. Then, we escalate to the rest of the Singles dev team.

     
    • JB

      JB - 2024-12-05

      Here's the Terminal results:
      look's the UPC is not increasing value.

       

      Last edit: JB 2024-12-05
      • Anobium

        Anobium - 2024-12-05

        Please read the rest of the post. Incrementing is not the issue.

        And, please next time post the GCB as an attachment. I would be guessing else.

         
  • Anobium

    Anobium - 2024-12-05

    Trying to isolate the issue... So, it not the conditional test ( if statement ).

    This tests additional, compare and SingleToString().

    // This is a for next loop that works.
    UPC = 5
    Do
        UPC = UPC +1
        If UPC = 999999 Then Exit Do
    Loop
    HserPrintCRLF
    HSerPrint SingleToString(UPC)
    

    When using the GCBASIC Float Calculator ( it may be within your GCSTUDIO install) is that the basic maths are all working, I can see is that 5 is correctly converted to 40a00000 (float format) etc.

    Dim UPC as Single
    
    For UPC = 5 to 9
        HSerPrint SingleToString(UPC)
        HserPrint SingleToHex(UPC)
        wait 1 s
    Next
    

    Remove the second HSerPrint and the 'error' happens.


    I need help to resolve. The GCBASIC Float Calculator needs sorting out. The inputs do not trim() {it is hard to determine any spaces}, and it is case sensitive.

    @angel-spartan - is this something you can rewrite quickly?

     
  • Anobium

    Anobium - 2024-12-05

    The attached works.

     5.0
     6.0
     7.0
     8.0
     9.0
    

    But, change the attached code from #DEFINE USART_DELAY OFF to #DEFINE USART_DELAY 0 ms then the error happens.

    Something is not right. The basics work as shown in the attached code. But... ??? I do not know what gets broken.

     
  • Anobium

    Anobium - 2024-12-05

    It looks like the allocation to the RAM for the advanced variables is issue with respect to BANKED and ACCESS RAM. In all our testing we never came across this issue and we did a lot of testing.

    Consider the comparison of the two files. One with #DEFINE USART_DELAY OFF and the other with #DEFINE USART_DELAY 0 ms. The compare shows the address of the variable spanning the BANKED and ACCESS memory address ( proven by the BANKSEL ).

    Need some way of preventing the spanning of the ACCESS memory address. As the ASM in the compare assumes a contiguous memory section, either ACCESS or BANKED.

    :-(

     
  • Anobium

    Anobium - 2024-12-05

    I have resolved here. It is memory allocation. Variables crossing the boundary was not thought of ( I guess when Microchip write AppNote AN575 ).

    So, I am thinking of some clever way to allocate memory in a better manner to resolve this.

     
  • Anobium

    Anobium - 2024-12-05

    Please add this to your program.

    This will force these key variables to be created in shared RAM. This is assumption made in the AppNote.

    The reason for +16 from the start of the RAM address is because GCBASIC creates the system shared variables in that RAM space.

      #script 
        SysULongIntTempA_ADDRESS = CHIPSHAREDRAM + 16
        SysULongIntTempB_ADDRESS = INT(SysULongIntTempA_ADDRESS + 8 )
        SysULongIntTempX_ADDRESS = INT(SysULongIntTempB_ADDRESS + 8 )
    
      #endscript
    
        dim SysULongIntTempA as ulongint at SysULongIntTempA_ADDRESS
        dim SysULongIntTempB as ulongint at SysULongIntTempB_ADDRESS
        dim SysULongIntTempX as ulongint at SysULongIntTempX_ADDRESS
    

    If you want to. Edit system.h and add the code above at line 171. It will work there. And, as this is the fix the system.h will be updated with this script.

    Phew.

     
  • JB

    JB - 2024-12-06

    added the code to system.h
    first run 5 times UPC no change
    all run after got only 1 loop UPC same value.

    I switched UPC to Long and it's working all 5 loops.

    #chip 18F14K22 , 64
    #option explicit
    
    #DEFINE USART_BAUD_RATE 9600
    #DEFINE USART_TX_BLOCKING
    #DEFINE USART_DELAY OFF ;0 ms
    dir porta.3 in
    
    Dim UPC as Single
    main:
    pause 300
    hserPrint ("Ready Press Key")
    hserPrintCRLF
     Do Until porta.3 = 0
     Loop
     pause 100
    
    for UPC = 5 TO 9
        HserPrint (SingleToString(UPC))
        HserPrintCRLF
    Next
    
    Goto main
    
     
    • Anobium

      Anobium - 2024-12-06

      This making mor sense - to me.

      This is all above memory management - it is about moving 'standard' variables out of shared RAM to banked RAM.

      Try this following in your program.

      Dim SINGLENUM as Word at 104
      Dim SYSARRAYTEMP1 as Word at 108
      Dim COMPORT at 112
      Dim HSERPRINTCRLFCOUNT at 113
      Dim PRINTLEN at 114
      Dim SERDATA at 115
      

      Do you want to a new copy of the compiler. It shows more info in the ASM.
      The build 1445 now shows if a variable is in Shared RAM.
      All the advanced variables need to be in Shared RAM - this is resolvable by checking the bank in the compiler ( that is not going to happen quickly ). So, make space by moving the variable locations using the AT modifier.

      New ASM layout - show the Shared/Access RAM = (SA) usage.

      ;Set aside memory locations for variables
      ;  Shared/Access RAM = (SA)
      COMPORT                          EQU     112          ; 0x70
      HSERPRINTCRLFCOUNT               EQU     113          ; 0x71
      PRINTLEN                         EQU     114          ; 0x72
      SERDATA                          EQU     115          ; 0x73
      SINGLENUM                        EQU     104          ; 0x68
      SINGLENUM_E                      EQU     107          ; 0x6B
      SINGLENUM_H                      EQU     105          ; 0x69
      SINGLENUM_U                      EQU     106          ; 0x6A
      SINGLETOSTRING                   EQU     491          ; 0x1EB
      STRINGPOINTER                    EQU       2          ; 0x2 (SA)
      SYSARRAYTEMP1                    EQU     108          ; 0x6C
      SYSARRAYTEMP1_H                  EQU     109          ; 0x6D
      SYSARRAYTEMP2                    EQU       3          ; 0x3 (SA)
      SYSBYTETEMPA                     EQU       5          ; 0x5 (SA)
      SYSBYTETEMPB                     EQU       9          ; 0x9 (SA)
      SYSBYTETEMPX                     EQU       0          ; 0x0 (SA)
      
       
  • Anobium

    Anobium - 2024-12-06

    Now we know this a memory allocation issue. But, the real probable cause is in the used of the addressing of access and banked RAM in the generated ASM.

    Are you able to spend some time trying to get to the the bottom of this? Where is the address going wrong in the ASM?

    Using the exact program. You 'diff' the ASM to see the different when you comment out the last line. Uncommented.. it works....

    Exact program is important. As if you add more code, you will have to control more RAM locations until the advanced vars work. Then, you can back off one byte variable. Using this exact program means we have the same program.. exactly the same.

    #chip 18F14K22
    #option Explicit
    
    
    #DEFINE USART_BAUD_RATE 9600
    #DEFINE USART_TX_BLOCKING
    #DEFINE USART_DELAY OFF
    
    Dim UPC as Single
    
    for UPC = 5 TO 9
        HserPrint (SingleToString(UPC))
        HserPrintCRLF
    Next
    
    Dim SINGLENUM as Word at 104
    Dim SYSARRAYTEMP1 as Word at 108
    Dim COMPORT at 112
    Dim HSERPRINTCRLFCOUNT at 113
    Dim PRINTLEN at 114
    // Dim SERDATA at 115
    

    I need to know exactly where it the addressing goes wrong to resolve properly.

     

    Last edit: Anobium 2024-12-06
  • JB

    JB - 2024-12-06

    loop from 5.0~9.0 with (Dim SERDATA at 115)
    loop from 5.0~5.0 with (//Dim SERDATA at 115)

    #chip 18F14K22
    #option Explicit
    
    #DEFINE USART_BAUD_RATE 9600
    #DEFINE USART_TX_BLOCKING
    #DEFINE USART_DELAY OFF
    
    Dim UPC as Single
    
    for UPC = 5 TO 9
        HserPrint (SingleToString(UPC))
        HserPrintCRLF
    Next
    
    Dim SINGLENUM as Word at 104
    Dim SYSARRAYTEMP1 as Word at 108
    Dim COMPORT at 112
    Dim HSERPRINTCRLFCOUNT at 113
    Dim PRINTLEN at 114
     Dim SERDATA at 115
    
     

    Last edit: JB 2024-12-06
    • Anobium

      Anobium - 2024-12-06

      Remove another byte until is breaks....

       
  • JB

    JB - 2024-12-06

    Single, can it work with whole number as 10 digits (99999 99999)

     

    Last edit: JB 2024-12-06
    • Anobium

      Anobium - 2024-12-06

      This is totally different question to the GCBASIC memory issue.

      9999999999 is stored in IEEE 754 format as 0x501502f9 which is an approximation of the number and this has a level of rounding. If you then convert 0x501502f9 back to decimal then you get 10000000000.

      Use GBASICs Float Converter to see this in action or try the same calc in https://www.h-schmidt.net/FloatConverter/IEEE754.html

       
  • JB

    JB - 2024-12-06

    removed byte one by one ,
    only with all the byte uncommented it's working

    Dim SINGLENUM as Word at 104
    Dim SYSARRAYTEMP1 as Word at 108
    Dim COMPORT at 112
    Dim HSERPRINTCRLFCOUNT at 113
    Dim PRINTLEN at 114
    Dim SERDATA at 115
    
     
    • Anobium

      Anobium - 2024-12-06

      Not sure I understand. Did the issue reappear?

      If yes, compare that ( broken asm ) with the previous working asm.

       
  • JB

    JB - 2024-12-06

    I'm confuse on where to look at .
    is this you looking for,
    Dim SERDATA at 115 = SERDATA EQU 115 ; 0x73
    //Dim SERDATA at 115 = SERDATA EQU 2 ; 0x2

     
  • JB

    JB - 2024-12-06

    (Dim SERDATA at 115 )
    ;Set aside memory locations for variables
    COMPORT EQU 112 ; 0x70
    HSERPRINTCRLFCOUNT EQU 113 ; 0x71
    PRINTLEN EQU 114 ; 0x72
    SERDATA EQU 115 ; 0x73
    SINGLENUM EQU 104 ; 0x68
    SINGLENUM_E EQU 107 ; 0x6B
    SINGLENUM_H EQU 105 ; 0x69
    SINGLENUM_U EQU 106 ; 0x6A
    SINGLETOSTRING EQU 491 ; 0x1EB
    STRINGPOINTER EQU 2 ; 0x2
    SYSARRAYTEMP1 EQU 108 ; 0x6C

    (//Dim SERDATA at 115 )
    ;Set aside memory locations for variables
    COMPORT EQU 112 ; 0x70
    HSERPRINTCRLFCOUNT EQU 113 ; 0x71
    PRINTLEN EQU 114 ; 0x72
    SERDATA EQU 2 ; 0x2
    SINGLENUM EQU 104 ; 0x68
    SINGLENUM_E EQU 107 ; 0x6B
    SINGLENUM_H EQU 105 ; 0x69
    SINGLENUM_U EQU 106 ; 0x6A
    SINGLETOSTRING EQU 491 ; 0x1EB
    STRINGPOINTER EQU 3 ; 0x3
    SYSARRAYTEMP1 EQU 108 ; 0x6C

     
1 2 > >> (Page 1 of 2)

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.