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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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)
...
...
...
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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 :-)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
@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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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)
...
...
...
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
Please post your code, also, confirm what version of the compiler you are using.
Thnk you.
The GCB particulars were clearly stated in the first line of the post.
The code is this https://github.com/Anobium/Great-Cow-BASIC-Demonstration-Sources/blob/master/PWM%20Solutions/AVR%20Command%20Usage%20Examples/Mega328p-005.gcb
Changed cip version attached.
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
The demonstration program now compiles cleanly and operates as expected. Thanks for the prompt responses.
Pleasure.
We need to regression test - do have a mega328p where you can test if that still works?
I have tested on a mega328p and the program seemed to work but the assembler code contains fragments like this...
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.
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?
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
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 :-)
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.
@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
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.
Could work. :-) Needs testing.
:-)
On further thought, your method is probably best. I don't think adding another constant or more program memory would help things :-)