Menu

"Tone" problem

jackjames
2021-07-23
2021-07-28
<< < 1 2 3 > >> (Page 2 of 3)
  • Anobium

    Anobium - 2021-07-27

    What are the changes you make ?
    Remind which OS.


    An insight.

    To build all the distributions of Great Cow BASIC, and, now the updates are fully automated here.

    • R2Build. Software that can execute 100s of steps in sequence, from simple ini file updates to complex database changes.
    • OS Command files. Using R2Build I have 11 small batch files that do things at the OS level like rename all files to lower case (needed for the Linux build).

    I will gladly share the tools I use, and, the processes to help.

     
    • mkstevo

      mkstevo - 2021-07-27

      The update automatically overwrites a lot of the .ini and .bat files that I then have to try and remember which files I need to change back again to return the NSDSP programmer and Geany to working order.

      Right now at home I'm using Windows 10 but at work I'm still on my iMac. I don't have any inclination to start on updating the Mac version again. Especially as I no longer have a Mac at home.

       
  • stan cartwright

    stan cartwright - 2021-07-27

    Yeah source forge eventually does download gcb but takes ages... never did before.

     
    • mkstevo

      mkstevo - 2021-07-27

      The download took a few seconds for me?

       
  • stan cartwright

    stan cartwright - 2021-07-25

    Do you think it has taken so long to find errors in gcb because no one uses the commands.
    I would think, as a beginner, that sound would be interesting...but then you got to have a "speaker"...so too much bother.
    Can't do much with a ucontroller unless you connect it to something.
    GCB does that easyish.
    We aren't all pic users. I'm liking logic green technology....the name sounds cool and it's zippy with gcb.

     
  • Anobium

    Anobium - 2021-07-26

    Do you think it has taken so long to find errors in gcb because no one uses the commands.

    No. FOR-NEXT is use extensively. The issue was deep in the compiler and we did not pick up on testing earlier this year.

     
  • William Roth

    William Roth - 2021-07-26

    @Stan

    A bit of history. "For next" had issues for a very long time. But these would not show up when stepping with a value of 1, which is the most common usage. However, when stepping with other values (2 for example) the for next loop could become endless as overflows were not being handled correctly in certain cases. This was all fixed in one of the release candidates.

    However there was a typo in a section of the new for next code. This typo was responsible for the issue that JackJames had with the Tone code. Under somewhat rare circumstances this typo caused a variable used with for next not to be cast correctly . This problem did not show up under testing before release of the code. It has been fixed now in the latest build.

    The latest build is: 0.98.07 2021-07-24 : Build 1008

    https://sourceforge.net/projects/gcbasic/files/Release%20Candidates/Patches

    This should be considered a "Critical Update" and as a minimum going forward. Yes, updating may cause some time and inconvenience. However, without this update the generated ASM is likely to be incorrect and certain programs or libraries may not operate as expected.


    If you care to see an example of the original for next issue try this code:

     #Define uselegacyfornext
    
      Dim CntA as byte
    
    For CntA = 0 to 255 step 2
          Hserprint CntA
          HSerprintCRLF
     Next
    

    The for next will loop endlessly.
    Remove the #define and it will execute correctly

    Edited link to point to the patch to update to Build 1008

     

    Last edit: William Roth 2021-07-28
  • stan cartwright

    stan cartwright - 2021-07-26

    You explain the problem well @William Roth.
    Never heard off #Define uselegacyfornext

    It's the sort of thing the user would have seen.. ie an overflow.
    The fact that gcb didn't do something else when compiling like a check is an obvious oversight but can see now how it got this far without being noticed.
    My reference to tone was who uses it?
    There's some dma stuff on the forum which looks interesting but probably hard to understand pic stuff.
    I got to get into pics more but find it easier to use avr cos they come on boards with lots of pins and the usb which you only get with pic dev boards which cost more.
    I hope that avr support.. like the lgt328 is kept up as it's great for a lot of stuff and is now sorted and consistent .
    Don't get me wrong. I think the pic stuff is brill.. but sometimes over my head.
    The idea of a pic with an op amp built in seems a good idea but in practice I bet it's not trivial to set up. So I'd go for a discrete op amp and a bit of extra circuitry.
    Still think gcb is really good software.

     
  • stan cartwright

    stan cartwright - 2021-07-26

    So the for next problem is the step... which is sorted.
    so for count1=0 to 255 step 3 would work but
    for count1=0 to 255 step 6 wouldn't.
    edit is that what the problem was and did it apply to word value counters as well?
    I wouldn't understand how it was resolved but did it test if the step value /255 or /65535 was an exact number ie no remainder? Just a thought.

     

    Last edit: stan cartwright 2021-07-26
    • Anobium

      Anobium - 2021-07-27

      @Stan.

      The problem was for all variable types. The problem is described with the solution here, see https://sourceforge.net/p/gcbasic/discussion/596084/thread/59d24215/#b174 (same post as Bill Roth shared)

      The solution was not as simple as shown on the post above but is gave me insight to resolve.

      The original code was simple and covered most cases. But, as the URL above discusses the loops are unacceptable. There is a trade off. The legacy code is smaller ( in this example ) using90+ words of program memory to do all the additional checking.

      More example code. If you try this on an UNO you will see the issue.. just uncomment #DEFINE USELEGACYFORNEXT to see the continuous loop.

      #chip 18F26K22, 4
      #OPTION Explicit
      
      '#DEFINE USELEGACYFORNEXT
      
      
        'USART settings
        #define USART_BAUD_RATE 9600
        #define USART_TX_BLOCKING
        #define USART_DELAY 10 us
      
        dim count1 as Byte
      
        HSerPrintCRLF 2
        HSerPrint "Count step 3"
        HSerPrintCRLF
        For count1 = 0 to 255 step 3
          HSerPrint str(count1)
          HSerPrint ","
        Next
      
        HSerPrintCRLF 2
        HSerPrint "Count step 6"
        HSerPrintCRLF
        For count1 = 0 to 255 step 6
          HSerPrint Str(count1)
          HSerPrint ","
        Next
      
        HSerPrintCRLF
        wait 10 ms
        Do
        Loop
      
       
  • stan cartwright

    stan cartwright - 2021-07-26

    This for next error wouldn't have become apparent without sloppy. deliberate programming.
    When you think about it it's obvious it could happen... just one of those things that never happens.
    Well it never happened to me.. luck?

     
    • William Roth

      William Roth - 2021-07-27

      Posted by Stan

      This for next error wouldn't have become apparent without sloppy. deliberate programming.
      

      This is simply not true. And, likely based upon how you personally presume a program should be constructed . A perfectly well constructed program could fail under the right conditions. I provided one example.

      A For Next has a start value an end value and a step value. Many times we use constants for these since we know where to start, where to end and what the step value should be. But this is not always the case. If these are variables that could change then the compiler needs to be able to handle these in a proper manner without generating final code that is unpredictable.

      I can think of several cases where the original for next could fail without "sloppy programming". Perhaps you should educate yourself a bit more before making such off-hand comments.

      Perhaps reading this thread might help you.

      https://sourceforge.net/p/gcbasic/discussion/596084/thread/59d24215/#b174

      William

       
  • mkstevo

    mkstevo - 2021-07-27

    I seem to have scuppered a previously working program.

    I have a For - Next loop which has a negative step value. The value is passed as a parameter into the subroutine. I'm getting an error which states:

    Error: Missing closing double quote in Table source:221 '" 
    Current/C1_16f1829_3.04.gcb (651): Error: For-Next 'step' must 
    be Integer variable
    
    Sub DoCountDownSub(Start As Word, Reduce As Byte)
    
      If Start > 9999 Then
         Let Start=9999
      End If
    
    
      For LoopCnt=Start to 0 Step - Reduce
          ShowValuesSub(LoopCnt)
          ...
          'Rest of loop here
      Next
    

    Ignoring the Table error for a second, should I be creating the step variable as a separate byte variable within the subroutine and then setting that variable to the value of my parameter or should I be able to use the byte value parameter directly as I was doing previously?

     
  • Anobium

    Anobium - 2021-07-27
    For LoopCnt=Start to 0 Step - Reduce
    

    The variable Reduce needs to an integer as the error states.
    'Reduce As Integer' is needed with the FOR-NEXT routines.


    If someone can figure out how NOT to have an integer then I would be grateful for the help. But, as you are using a variable the type must be an integer.

     
    • mkstevo

      mkstevo - 2021-07-27

      Hmm. I think I've missed the point somewhere.

      Are you saying that my 'Byte' parameter should be changed to an 'Integer' parameter?

      I've never used an integer in GCB. Bytes, Words, Longs yes. Integers? No!

       
      • mkstevo

        mkstevo - 2021-07-27

        Re-writing the parameter so that it reads:

        Sub DoCountDownSub(Start As Word, Reduce As Integer)
        

        Isn't the answer.

        Nor is:

        Sub DoCountDownSub(Start As Word, Reduce As Integer)
        
        Dim ReduceVar As Integer
        Let ReduceVar = Reduce
        
          If Start > 9999 Then
             Let Start=9999
          End If
        
        
          For LoopCnt=Start to 0 Step - ReduceVar
        
         
        • Anobium

          Anobium - 2021-07-27

          Please use this as a workaround

          I negate the ReduceVar then use that negated value.

          #chip 16f1829
          #option Explicit
          
          dim vari as Byte
          dim stepvar as Byte
          
          DoCountDownSub ( vari, stepvar )
          
          Sub DoCountDownSub(Start As Word, Reduce As Integer)
          
          Dim LoopCnt as Word
          
          Dim ReduceVar As Integer
          ReduceVar = -Reduce
          
            If Start > 9999 Then
               Let Start=9999
            End If
          
          
            For LoopCnt = Start to 0 Step ReduceVar
          
            Next
          
          End Sub
          

          There is something not correct in the compiler. It is probably just an errant message but I will have to investigate to resolve. I did ask people to test the FOR_NEXT changes as these changes were extensive - never enough testing :-(

           
          • mkstevo

            mkstevo - 2021-07-27

            That compiles, thanks for your thoughts.

            {Further comments deleted as, again, they might have come across as snarky. Apologies once more.}

             

            Last edit: mkstevo 2021-07-27
        • mkstevo

          mkstevo - 2021-07-27

          Answering my own confusion here.

          {I had some other comments regarding use of constants here. I later removed those comments as it has been suggested that although the program compiled it might not have worked as intended.}

          I tried leaving the program as it was, adding the legacy directive:

          Sub DoCountDownSub(Start As Word, Reduce As Byte)
          
          
          
            If Start > 9999 Then
               Let Start=9999
            End If
          
          #Define UseLegacyForNext
          
            For LoopCnt=Start to 0 Step - Reduce
          

          This resulted in a successful compile.

           

          Last edit: mkstevo 2021-07-27
          • Anobium

            Anobium - 2021-07-27

            Answering my own confusion here. The value for the 'Step' must be a fixed constant now. Not a parameter (of any type), not a variable (of any type), a fixed value constant.

            No! Like I said in this post https://sourceforge.net/p/gcbasic/discussion/596084/thread/a56563e36f/#c0fb/747c/4310/d6f8

            Your analysis is incorrect.

            Please look at https://sourceforge.net/p/gcbasic/discussion/596084/thread/a56563e36f/#c0fb/747c/4310/d6f8

             
            • mkstevo

              mkstevo - 2021-07-27

              Deleted.

              Although I was trying to help with my replies, I don't think they helped at all.

              My efforts in trying to locate the cause of the problem may have been interpreted as criticism. That was not my intention and I apologise.

               

              Last edit: mkstevo 2021-07-27
              • Anobium

                Anobium - 2021-07-27

                You analysis is correct. Using constants is not the resolution. It is a theory but analysis show it is another cause.


                The issue is the NEGATing of the value '-Reduce'. This is causing the variable Reduce to be treater as a BYTE. This has nothing to do with the new FOR-NEXT code as the negate happens before the FOR-NEXT section of the compile is called.

                  For LoopCnt = Start to 0 Step -Reduce
                  Next
                

                Proof (I have added debug but this shows this to be the case. This casts '-Reduce' to an integer.

                  For LoopCnt = Start to 0 Step [INTEGER]-Reduce
                  Next
                

                As the negate causes the variable to be a byte the ASM generated contains no step variable decrement step code (just increment step code).

                This needs fixing.

                 
  • mkstevo

    mkstevo - 2021-07-27

    The table error is easily fixed, though a little fussy.
    The error refers to:

    Error: Missing closing double quote in Table source:221 '" 
    

    I have a lookup table for the alphabet which maps ascii codes to some values which cross reference a first (alphabetic) table into the numeric values needed to show that character on four seven segment LED displays driven by four 74HC595.
    221 is a value which lights the top two vertical segments, to give the effect of a double quote. My table is (or was) correct, the quote symbol is 'Rem'ed out by the preceeding single quote.

    I can replace the double quote with the phrase 'Double Quotation mark' so it can soon be repaired, though it is a little odd that a remark should be attempted to be compiled?

    Table Alphabet As Byte
    255 '  Space
    255 '! Space
    221 '" 
    255 '# Space
    255 '$
    255 '% Space
    255 '& Space
    223 ' 
    198 '( Square bracket
    240 ') Square bracket
    255 '* Space
    255 '+ Space
    127 ', Single decimal point
    191 '- Dash in the middle of the display
    127 '. Single decimal point
    237 '/ Two offset vertical bars 'i
    192 '0
    249 '1
    164 '2
    176 '3
    153 '4
    146 '5
    130 '6
    248 '7
    128 '8
    144 '9
    255 ': Space
    255 '; Space
    167 '< 'c'
    183 '= Two dashes, one at the bottom, one in the middle
    179 '> 'c' inverted
    172 '?
    255 '@ Space
    136 'A
    128 'B
    198 'C
    192 'D
    134 'E
    142 'F
    194 'G
    137 'H
    207 'I
    241 'J
    137 'K
    199 'L
    200 'M
    200 'N
    192 'O
    140 'P
    152 'Q 'q'
    206 'R
    146 'S
    135 'T
    193 'U
    193 'V 'U'
    193 'W 'U'
    137 'X 'H'
    145 'Y
    164 'Z looks like a 'two'
    198 '( Square bracket
    219 '\ Two offset vertical bars i'
    240 ') Square bracket
    220 '^ 'n' in top portion of display
    247 '_ Dash at the bottom of the display
    253   '
    163 'a 'o'
    131 'b
    167 'c
    161 'd
    134 'E
    142 'f
    144 'g
    139 'h
    239 'i
    241 'j
    139 'k
    207 'l
    171 'm
    171 'n
    163 'o
    140 'p
    152 'q
    175 'r
    146 'S
    135 't
    227 'u
    227 'v 'u'
    227 'w 'u'
    137 'x 'H'
    145 'y
    164 'z looks like a 'two'
    198 '{ Square bracket
    207 'l Two vertical bars to the left of the display 
    240 '} Square bracket
    254 '~ Dash at the top of the display
    End Table
    
     
    • Anobium

      Anobium - 2021-07-27

      We have the same issue in the major tables in the compiler. This is not resolvable as the double is the string delimiter.

      Your method to resolve is the way to resolve.

       
      • mkstevo

        mkstevo - 2021-07-27

        Thanks. Though it had been working without issue previously.

         

        Last edit: mkstevo 2021-07-27
<< < 1 2 3 > >> (Page 2 of 3)

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.