Menu

"Tone" problem

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

    jackjames - 2021-07-23

    I have encountered a problem with the "Tone" statement.
    I needed to create the sound of a two-tone siren, so I got a PIC12F683 clocked at 8MHz to be able to generate these two tones.
    The simplest thing to have two notes of 660 and 466 Hz for a duration of 750 mS was to use the "Tone" instruction.
    I encountered this problem that is generated both with the micro and in emulation with SimulIDE.
    In practice, if I play the two notes with an interval of 750 mS the micro generates only the first tone at 466Hz.
    If I bring the interval to 1500 mS the micro generates the first note at 466Hz for a few minutes, then the normal cycle begins.
    The same problem happens with simulation.

     
  • stan cartwright

    stan cartwright - 2021-07-23

    Toggleled could be LED = not LED.
    Did not know of do forever...loop
    why not do...loop ?
    PS , I thought GPIO was only for AVR chips

     

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

    William Roth - 2021-07-23

    The Tone Duration is in 10 ms units. So for 750 ms that would be a value of 75.
    Try this:

    Do ForEver
           Tone 466, 75
           Toggleled
           Tone 660, 75
           Toggleled
    Loop
    
    Sub Toggleled
         If LED = 1 Then
               LED = 0
         Else
               LED = 1
         End If
    End Sub
    
     

    Last edit: William Roth 2021-07-23
  • William Roth

    William Roth - 2021-07-23

    To simplify toggling of the LED you might try this instead of calling a subroutine:

    Do ForEver
        Tone 466, 75
        LED = !LED 
        Tone 660, 75
        LED = !LED 
    Loop
    
     
  • William Roth

    William Roth - 2021-07-24

    So I tried the above code on a 18F27Q43.

    At first there is a 466 Hz output on the SOUNDOUT Pin. It does not change to 660 Hz after 750 ms. After about 10 minutes or so of outputting a steady 466 Hz , it begins operating as expected.

    It will continue operating as expected as long as power is not removed. The chip can be reset, or even reprogrammed and it operates as expected. But once power is removed it takes 10 min or so to start operating correctly. ... Quite odd

     
  • Anobium

    Anobium - 2021-07-24

    Try adding

    dim TonePeriod as word

     
    • stan cartwright

      stan cartwright - 2021-07-24

      Where is TonePeriod? Actually where is the Tone code? I can't see it looking through GCB folder. It's not an include.
      In Tone help it says "Generate a specified tone for a specified duration in terms of a frequency of a specified Mhz and units of 10ms".
      MHz ?

       
      • William Roth

        William Roth - 2021-07-24

        @Stan

        The code is in ... \lowlevel\sound.h

         
  • William Roth

    William Roth - 2021-07-24

    @ JackJames

    Add this line to your code.

    #Define UseLegacyForNext
    

    This should resolve for now.

     
    • jackjames

      jackjames - 2021-07-24

      I apologize to everyone for being late, but I've been busy on business.
      In fact, inserting the definition "USELEGACYFORNEXT" the program runs well.
      I would like to understand what was going on in the program.
      Taking a first look at the ASM source it seemed all right.

       
      • Anobium

        Anobium - 2021-07-24

        There is a bug in the new FOR-NEXT loop where the loop variable was incorrectly cast.

        Save the errant asm today. Then, tomorrow download the latest patches ( build 1005) then recompile. Then, compare the ASM. You will see the variables are Words not Bytes for two loop variables.

         
        • jackjames

          jackjames - 2021-07-24

          Thank you for your explanation.

           
          • Anobium

            Anobium - 2021-07-25

            I will release v0,.98,07 build 1005 today. It is a mandated update.

            The FOR-NEXT issue identified needs a critical fix.

            Look for the new release today.

             
            • Anobium

              Anobium - 2021-07-25

              This issue impacts PIC/AVR/LGT AM

              Released 0.98.07 ASM

              ;For ToneLoop = 1 to ToneDuration
                movlw 1
                movwf TONELOOP
              SysForLoop1
              ;For ToneLoop2 = 1 to ToneFrequency
                movlw 1
                movwf TONELOOP2
              

              Released 0.98.07 build 1005 ASM

                ;For ToneLoop = 1 to ToneDuration
                movlw 1
                movwf TONELOOP
                clrf  TONELOOP_H   'this was missing
              SysForLoop1
              ;For ToneLoop2 = 1 to ToneFrequency
                movlw 1
                movwf TONELOOP2
                clrf  TONELOOP2_H  'this was missing
              

              The compiler was treating the ToneLoop and ToneLoop2 variables as byte type therefore failing to clear the _H byte.

              Sorry. All sorted.

               
            • jackjames

              jackjames - 2021-07-25

              I downloaded the file to perform a complete new installation.
              This error occurs:

               
              • Anobium

                Anobium - 2021-07-25

                Close the Preferences Editor. :-)

                 
                • jackjames

                  jackjames - 2021-07-25

                  Thanks

                   
  • stan cartwright

    stan cartwright - 2021-07-25

    When did the for-next problem occur? I've never had any problems with for next... if it's a loop of more than 255 I use a word value with the for variable. I'll download the latest gcb as a matter of course.
    In any gcb version, where does it show the build number... when assembling it only says compiler version v0.98.07 2021-05-27. on my current gcb.

     
    • Anobium

      Anobium - 2021-07-25

      @Stan. Read the thread from the start and you will see that the @jackjames reported some very odd behaviour which was properly analysed as a major issue in the compiler.


      Re the version.

      Use the IDE show the version, or, look at the top line of the ASM.

      ;Program compiled by Great Cow BASIC (0.98.07 2021-07-24 (Windows 64 bit) : Build 1005)

       

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

        stan cartwright - 2021-07-25

        Dear Even, I do check the forum regularly and saw the for next "Problem".
        I'll re-read it but after all these years, for next don't work???
        Downloading latest gcb version from Sourceforge is an hour. Maybe they are having problems.
        Had to update gcb to two pc's ethernet and so slow.
        Thanks for the work everyone's done to gcb.
        The RC releases were ok but patches???
        The useful info in the forum gets lost so quickly.
        ps the version can be gcb version..rc 5 or whatever but no easy...for me. way to see what version of gcb I'm using and things change fast.

         

        Last edit: stan cartwright 2021-07-25
  • stan cartwright

    stan cartwright - 2021-07-25

    I always go for the full gcb install... dunno why, I don't use the extras but install anyway.
    I use avr mostly but some pics with built in op amp look tempting. I guess I'll have to use the PPS tool and look up data sheets...maybe stick to avr and use external op amp.
    Whatever's easiest :) Regards, happy user

     
    • Anobium

      Anobium - 2021-07-26

      :-)

       
    • mkstevo

      mkstevo - 2021-07-26

      Personally I try to avoid updating at all costs. I find it takes me so long to get everything working again after updating I would rather do anything than upgrade!

       
      • Anobium

        Anobium - 2021-07-26

        If you are using ANY version of 0.98.07 then it is a mandated upgrade. The FOR-NEXT is critical update.

        And, automate the upgrade. The updates will be coming.

         

        Last edit: Anobium 2021-07-26
        • mkstevo

          mkstevo - 2021-07-27

          I wish I knew how to automate the upgrade. Honestly, it takes me hours.

           
1 2 3 > >> (Page 1 of 3)

Log in to post a comment.