Well, my previous question https://sourceforge.net/projects/gcbasic/forums/forum/579126/topic/5059645 took a very different turn today. I believe the problem I'm seeing is actually caused by GC Basic, and is not a microcontroller issue. I'd be very interested to learn what the rest of you might think.
Here's the deal. This is a simple project to sweep the ten bars of an LED bar display back and forth. The circuit worked from the get-go--however, it always began with some random LED elements being lit before it settled down into proper action. The circuit is one LED on each of B.0-B7 and one more each on A.0 and A.1 (ten LEDs total). Here's the GC Basic program:
;A program to sweep 10 elements of an LED bar graph.
;In this direct connection circuit, only one LED
;element may be lit at a time to stay under max current.
;********************* Configuration **********************
#chip 16F88, 4 ;PIC16F88 running at 4 MHz
#config mclr=off ;reset handled internally
#config osc=int ;use internal clock
;************************ Constants ************************
#define bitsLow PortB ;low eight bits of display here
#define bitsHigh PortA ;high two bits of display here
;************************ Program *************************
pgm:
dim pattern as word alias patternHigh, patternLow ;LED pattern
do
pattern = 1 ;begin with 1st LED
for i = 1 to 10 ;ten LEDs in display unit
bitsLow = patternLow ;set two ports separately
bitsHigh = patternHigh
wait 100 ms ;pause a bit
rotate pattern left simple ;get set for the next one
next
pattern = 256 ;now sweep backwards
for i = 9 to 2 step -1 ;9th to 2nd element
bitsLow = patternLow
bitsHigh = patternHigh ;set two ports separately
wait 100 ms ;pause a bit
rotate pattern right simple ;get set for the next one
next
loop ;repeat in perpetuity
end
Try it out, and I think you'll see some erratic behavior for the first second or so. Instead of starting with no LED elements lit as expected, there are all sorts of random flashes and whatnot before it settles down.
Check out the start of the assembler code it creates:
;Start of program memory page 0
ORG 5
BASPROGRAMSTART
;Call initialisation routines
call INITSYS
;Automatic pin direction setting
banksel TRISA
clrf TRISA
clrf TRISB
banksel PORTA ;***** Manually added to .asm *****
If I manually add the last line to the assembler code, the project performs perfectly.
I don't know if this is a bug, but it appears to me as though after the TRISA and TRISB registers are set in the automatic pin direction business, that the paging flag really ought to be set back to Bank 0. What do you think?
Obviously, now that I know what's going on, I can fix this myself. But shouldn't Hugh or whoever keeps track of these things be the one to decide if this is a bug and if the "official" version of GC Basic should include a change or not?
Anyway, do any of you experts (I'm basically a one-month old novice) have any comments?
Thanks for listening,
Thomas Henry
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The bank isn't being set properly as gcbasic has a problem working out what bank aliased registers are in so PATTERN and PATTERN_H which follow directly after the automatic pin direction setting don't get a banksel.
There is a post in compiler problems already that relates to this issue -
You could initialise i to zero before setting pattern as a temporary solution.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2012-02-25
Hi,
All four of the commands you list are already automatically inserted into the assembler code by GC Basic. The latter two occur in the INITSYS routine which is the first routine called. The former two then are executed immediately thereafter in the main program code.
So it's redundant to invoke those four again. As I mentioned, the problem is that a manually inserted banksel is needed to get that flag back to where it needs to be. So again, my question is, is that a bug?
For clarity, then, the data direction ports and the ports themselves (the commands you listed) are properly set by GC Basic automatically. What isn't automatic is setting the paging flag to the proper bank afterwards.
And, yes, the Rotate command works for word variables.
Thomas Henry
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2012-02-25
Thanks for the info. Our messages crossed (synchronicity, I guess), so my last comment was actually referring to the previous suggestion.
Yes, this isn't that big of a deal since we know several ways to work around it now. But it would be nice for the compiler to handle this automatically. It would be one less thing to have to remember!
Thanks again, and thanks too for the link. It's comforting to learn someone else had observed this problem earlier.
Thomas Henry
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello all,
Well, my previous question https://sourceforge.net/projects/gcbasic/forums/forum/579126/topic/5059645 took a very different turn today. I believe the problem I'm seeing is actually caused by GC Basic, and is not a microcontroller issue. I'd be very interested to learn what the rest of you might think.
Here's the deal. This is a simple project to sweep the ten bars of an LED bar display back and forth. The circuit worked from the get-go--however, it always began with some random LED elements being lit before it settled down into proper action. The circuit is one LED on each of B.0-B7 and one more each on A.0 and A.1 (ten LEDs total). Here's the GC Basic program:
Try it out, and I think you'll see some erratic behavior for the first second or so. Instead of starting with no LED elements lit as expected, there are all sorts of random flashes and whatnot before it settles down.
Check out the start of the assembler code it creates:
If I manually add the last line to the assembler code, the project performs perfectly.
I don't know if this is a bug, but it appears to me as though after the TRISA and TRISB registers are set in the automatic pin direction business, that the paging flag really ought to be set back to Bank 0. What do you think?
Obviously, now that I know what's going on, I can fix this myself. But shouldn't Hugh or whoever keeps track of these things be the one to decide if this is a bug and if the "official" version of GC Basic should include a change or not?
Anyway, do any of you experts (I'm basically a one-month old novice) have any comments?
Thanks for listening,
Thomas Henry
I always initialize the ports first
dir porta out
dir portb out
set porta=b'00000000'
set portb=b'00000000'
Does rotate work for word variables?
The bank isn't being set properly as gcbasic has a problem working out what bank aliased registers are in so PATTERN and PATTERN_H which follow directly after the automatic pin direction setting don't get a banksel.
There is a post in compiler problems already that relates to this issue -
http://http://sourceforge.net/projects/gcbasic/forums/forum/596084/topic/4618565
You could initialise i to zero before setting pattern as a temporary solution.
Hi,
All four of the commands you list are already automatically inserted into the assembler code by GC Basic. The latter two occur in the INITSYS routine which is the first routine called. The former two then are executed immediately thereafter in the main program code.
So it's redundant to invoke those four again. As I mentioned, the problem is that a manually inserted banksel is needed to get that flag back to where it needs to be. So again, my question is, is that a bug?
For clarity, then, the data direction ports and the ports themselves (the commands you listed) are properly set by GC Basic automatically. What isn't automatic is setting the paging flag to the proper bank afterwards.
And, yes, the Rotate command works for word variables.
Thomas Henry
Thanks for the info. Our messages crossed (synchronicity, I guess), so my last comment was actually referring to the previous suggestion.
Yes, this isn't that big of a deal since we know several ways to work around it now. But it would be nice for the compiler to handle this automatically. It would be one less thing to have to remember!
Thanks again, and thanks too for the link. It's comforting to learn someone else had observed this problem earlier.
Thomas Henry