Menu

Demonstration file will not compile for mega8

2018-01-28
2018-01-29
  • Tony Bolton

    Tony Bolton - 2018-01-28

    Using GCB Great Cow BASIC (0.98.01 2017-10-27) on Linux Mint 18.3

    When I try to compile the PWM demonstration file Mega328p-005.gcb for a mega8 CPU there are a sucession of compiler error messages from irrelevant code in an include file. The issue appears to be a consequence of these lines in PWM.h

    'define the defaults
    ' #define AVRTC0
    ' #define AVRCHAN2

    The demonstration program only uses AVRCHAN3 and the irrelevant #define of AVRCHAN2 causes spurious references to timer registers which happen to exist on a mega328 but do not exist on a mega8. These references have no effect in this program but if applications have other uses for timer 0 there may be unexpected outcomes. The documentation is emphatic that AVRTCx and AVRCHANx MUST be defined so why these defaults are added is not clear, if they are needed elsewhere then appropriate conditionals could be added.

    The workaround is to comment out these references and recompile/install GCB.

    regards CB

     
    • Anobium

      Anobium - 2018-01-28

      Please post your code, also, confirm what version of the compiler you are using.

      Thnk you.

       
  • Anobium

    Anobium - 2018-01-28

    Sorry - my error for not spotting the version information. It was the perfect post... not use to this!

    Would you test the attachment please? I have revised the library to better handle the register/bit for this chip as this condition may not be just limited to the specific chip. The UNdefinition of default constant may have an impact that we do not want. I have added new conditional tests and I have used some newer features of the compiler to improve handing.

    Cheers

    Attached is a revised pwm.h - please take a copy of your old file and replace. You will find this file in your GreatCowBASIC\include\lowlevel folder.

     

    Last edit: Anobium 2018-01-28
  • Tony Bolton

    Tony Bolton - 2018-01-28

    The demonstration program now compiles cleanly and operates as expected. Thanks for the prompt responses.

     
    • Anobium

      Anobium - 2018-01-28

      Pleasure.

      We need to regression test - do have a mega328p where you can test if that still works?

       
      • Tony Bolton

        Tony Bolton - 2018-01-29

        I have tested on a mega328p and the program seemed to work but the assembler code contains fragments like this...

        AVRPWMOFF31:
            lds SysCalcTempA,AVRPWMCHANNEL
            cpi SysCalcTempA,2
            brne    ENDIF19
            in  SysValueCopy,TCCR0A
            cbr SysValueCopy,1<<COM0B1
            out TCCR0A,SysValueCopy
            in  SysValueCopy,TCCR0A
            cbr SysValueCopy,1<<COM0B0
            out TCCR0A,SysValueCopy
        

        The TCCR0x registers are associated with the unused timer 0, while the conditional tests probably prevent execution the unwanted default AVRPWMCHANNEL 2 is wasting rom space.

         
        • kent_twt4

          kent_twt4 - 2018-01-29

          Agreed, multiple instances of TC0 artifacts. The short answer to the problem is if the default TMR0 PWMON/PWMOFF is not being used then just comment out these defines at the top of the pwm.h file and save.

          The longer answer is for us to not use those particular defines unless the default PWMON/PWMOFF has been parsed and flagged during compilation? So move defines to InitPWM sub, and test if flag has been raised by compiler and exit InitPWM before defines?

          InitPWM
              ...
              ...
              ...
             #IFDEF AVR
          ==> Insert conditional test or other method here
                       and exit sub if false
              #define AVRTC0
              #define AVRCHAN2
              #define PWM_Freq 38      'Frequency of PWM in KHz
              #define PWM_Duty 50      'Duty cycle of PWM (%)
          
              #script
          
                if AVR then
                  ICR1temp = int(((chipMHZ*1000) / PWM_Freq) - 1)
                  ...
                  ...
                  ...
          
           
          • Anobium

            Anobium - 2018-01-29

            Sounds like the way to go. The latest copy is in SForge - but, do check with me before you start o ensure you have the latest code base.

            Evan

             
            • kent_twt4

              kent_twt4 - 2018-01-29

              Oops, still on 98 RC6, so that is my problem? I am too disorganized to keep up with all the latest realeases. Need a bigger hard drive to hold them all :-)

               
  • kent_twt4

    kent_twt4 - 2018-01-28

    Tony Bolton, thanks for the feedback.

    Evan, interesting concept. Are you testing whether PWMON/PWMOFF is being used in a system file then so [can skip]? Not in a position right now to try this out myself.

     
    • Anobium

      Anobium - 2018-01-28

      @Kent. I have protect against this error with [canskip] and conditional tests where appropiate.

      We should not remove the default PWM setting at this will impact the defaults, but, we could remap the Constant in a script so these smaller chip do have a default PWM. Or, do we simply update the Help to state this is chip limitation?

      Evan

       
      • kent_twt4

        kent_twt4 - 2018-01-28

        At least from the AVR perspective, Tony brought up a valid point about the extra curricular TC0 code. To my mind the InitPWM sub is there only for the default PWMON/PWMOFF.

        Talking off the top of my head here (which nearly is always bad thing).... :-) But couldn't the condition be inserted to exit the InitPWM sub here? But if the [canskip] works, then I am OK with that too.

          #IFDEF AVR
           ==>If PWMON = False Then exit sub '(loosely speaking here)
            #script
        
              if AVR then
                ICR1temp = int(((chipMHZ*1000) / PWM_Freq) - 1)
                ...
                ...
                ...
        
         
        • Anobium

          Anobium - 2018-01-28

          Could work. :-) Needs testing.

          :-)

           
          • kent_twt4

            kent_twt4 - 2018-01-28

            On further thought, your method is probably best. I don't think adding another constant or more program memory would help things :-)

             

Log in to post a comment.