PDA

View Full Version : picbasic +12c508a+soft_stack error



omid_juve
- 16th December 2007, 15:33
Hi
I wrote a simple basic program for my PIC (12c508A) in a Picbasic Pro compiler
but I have this error after compilation "unable to fit variable soft_stack"
please see my program below and tell me the errors as I am beginner in PIC programming .
Thanks


lowinput VAR GPIO.0
overtemprature VAR GPIO.1
overload VAR GPIO.2
outputpin VAR GPIO.3
green VAR GPIO.4
red VAR GPIO.5
count1 var byte
i var byte

OUTPUT outputpin
input lowinput
input overtemprature
input overload
OUTPUT green
OUTPUT red

while i=0
if (lowinput=0) and (overload=0) and (overtemprature=0) then

outputpin =0
High green
Pause 500
Low green
Pause 500

ENDIF


if (lowinput=0) and (overload=1) and (overtemprature=0) then

while count1<2
gosub overloadmode
count1=count1+1
wend
outputpin =1

while count1<7
gosub overloadmode
count1=count1+1
wend

outputpin =0
count1=0
ENDIF

if (lowinput=1) and (overload=0) and (overtemprature=0) then

while count1<5
gosub lowinputmode
count1=count1+1
wend
outputpin =1
count1=0
ENDIF
if (lowinput=0) and (overload=0) and (overtemprature=1) then

while count1<5
gosub overtempraturemode
count1=count1+1
wend
outputpin =1
count1=0
ENDIF
if (lowinput=1) and (overload=1) and (overtemprature=0) then

while count1<5
gosub overtempraturemode
count1=count1+1
wend
outputpin =1
count1=0


endif


wend


overloadmode:
High green
low red
Pause 500

Low green
high red
Pause 500
return

lowinputmode:
High green
low red
Pause 500

Low green
high red
Pause 500
return

overtempraturemode:

High green
high red
Pause 500

Low green
low red
Pause 500

return

end

mister_e
- 16th December 2007, 17:12
you may need to move on a bigger RAM PIC such as PIC12C509. 12C508 have 25 bytes of RAM, while 12C509 have 41 + twice the program space size.

The compiler use between 20 & 22 bytes of RAM itself.. so... no real space for more variables :eek:

Darrel Taylor
- 16th December 2007, 19:57
A 12F might be a good choice. Cheaper too.

However, what you have should fit, with a little modification.


The complex IF statements are creating 3 (T)emp vars, which are word sized. (even though it's only using 1 bit per WORD)
So it's using 6 bytes that it doesn't really need too.

If you change all the IF statements to something like this for the first one, I believe it should fit.


;if (lowinput=0) and (overload=1) and (overtemprature=0) then
if (lowinput=0) THEN
if (overload=1) THEN
if (overtemprature=0) THEN
while count1<2
gosub overloadmode
count1=count1+1
wend
outputpin =1

while count1<7
gosub overloadmode
count1=count1+1
wend

outputpin =0
count1=0
ENDIF
ENDIF
ENDIF


hth,

mister_e
- 16th December 2007, 20:03
i was thinking of a select case and GPIO mask. mmm...

edit: Seems to work

lowinput VAR GPIO.0
overtemprature VAR GPIO.1
overload VAR GPIO.2
outputpin VAR GPIO.3
green VAR GPIO.4
red VAR GPIO.5
count1 var byte
Mask var byte


OUTPUT outputpin
input lowinput
input overtemprature
input overload
OUTPUT green
OUTPUT red

Start:
mask=GPIO & 7
select case mask
case %000 ;if (lowinput=0) and (overload=0) and (overtemprature=0) then
outputpin =0
High green
Pause 500
Low green
Pause 500

case %100 ;if (lowinput=0) and (overload=1) and (overtemprature=0) then
while count1<2
gosub overloadmode
count1=count1+1
wend
outputpin =1

while count1<7
gosub overloadmode
count1=count1+1
wend

outputpin =0
count1=0

case %001 ;if (lowinput=1) and (overload=0) and (overtemprature=0) then
while count1<5
gosub lowinputmode
count1=count1+1
wend
outputpin =1
count1=0

case %010 ;if (lowinput=0) and (overload=0) and (overtemprature=1) then
while count1<5
gosub overtempraturemode
count1=count1+1
wend
outputpin =1
count1=0

case %101 ;if (lowinput=1) and (overload=1) and (overtemprature=0) then
while count1<5
gosub overtempraturemode
count1=count1+1
wend
outputpin =1
count1=0
end select

goto Start


overloadmode:
High green
low red
Pause 500

Low green
high red
Pause 500
return

lowinputmode:
High green
low red
Pause 500

Low green
high red
Pause 500
return

overtempraturemode:

High green
high red
Pause 500

Low green
low red
Pause 500

return

end

Archangel
- 16th December 2007, 20:52
. . . .

The compiler use between 20 & 22 bytes of RAM itself.. so... no real space for more variables :eek:

Hello Mister_E
Could you please explain? This statement appears to me to mean PIC BASIC PRO is an intrepreted code, if not why would the compiler require any of the PIC's ram?
Thank You
JS

mister_e
- 16th December 2007, 21:35
Yeah but the library/compiler need to reserve some variable to work to not interfer with your code... euh.. that's my understanding ;)

support for 12 bit core is limited, and the real explanation can be found at the bottom of the folowiing page
http://www.melabs.com/support/12-bit.htm

so why 20-22... i don't know, seems hungry to me.. but, you have to deal with it.

We already heard something like that for 10F and bring some weird/nasty/dangerous/clever alternate solutions, some who remind...
http://www.picbasic.co.uk/forum/showthread.php?t=4789&

HTH

Darrel Taylor
- 17th December 2007, 00:42
After converting all the IF statements like I suggested above, it did fit in RAM,
and it compiled to 313 WORDS.

mister_e,
Yours fit in RAM too, and compiled to 295 WORDS. (unexpected for Select Case)

You know what that means RIGHT?
Yup, this ain't over yet! :D

172 WORDS

@ DEVICE WDT_OFF
DEFINE NO_CLRWDT 1 ' Don't kick the Dog

lowinput VAR GPIO.0
overtemprature VAR GPIO.1
overload VAR GPIO.2
outputpin VAR GPIO.3
green VAR GPIO.4
red VAR GPIO.5
FlashCount var byte
FlashPattern var byte

TRISIO = %000111

Start:
If (lowinput=0) then
IF (overload=0) then ; lowinput, overload, overtemprature
if (overtemprature=0) then ; 000
outputpin = 0
FlashCount = 1
FlashPattern = %0001 ; ModeOK
GOSUB FlashLEDs
else ; 001
FlashCount = 5
FlashPattern = %0011 ; overtempraturemode
gosub FlashLEDs
outputpin = 1
endif
else ; 010
if (overtemprature=0) then
FlashCount = 2
FlashPattern = %1001 ; overloadmode
gosub FlashLEDs
outputpin =1

FlashCount = 7
gosub FlashLEDs
outputpin =0
else ; 011
; --- Action undefined ---
endif
endif
else
if (overload=0) then
if (overtemprature=0) then ; 100
FlashCount = 5
FlashPattern = %1001 ; lowinputmode
gosub FlashLEDs
outputpin =1
else ; 101
; --- Action undefined ---
endif
else ; 110
if (overtemprature=0) then
FlashCount = 5
FlashPattern = %0011 ; overtempraturemode
gosub FlashLEDs
outputpin =1
else ; 111
; --- Action undefined ---
endif
endif
endif
GOTO Start

FlashLEDs:
REPEAT
green = FlashPattern.0
red = FlashPattern.1
Pause 500

green = FlashPattern.2
red = FlashPattern.3
Pause 500
FlashCount = FlashCount - 1
UNTIL (FlashCount = 0)
return

However, omid_juve,

There are 3 states that are not accounted for

lowinput=0 overload=1 overtemprature=1
lowinput=1 overload=0 overtemprature=0
lowinput=1 overload=1 overtemprature=1

It may be intentional. Maybe they aren't needed. But normally, unchecked states will cause havoc in your program.

If we knew what was supposed to happen in those states, I think mister_e ..., uh I mean, I could probably reduce it further.

omid_juve
- 17th December 2007, 03:55
it a program for 24v to 12v converter that has 3 input 1.over temperature 2.low input 3.overload and we have 3 output that 2 of them is just indicator and one (outputpin)
is the output for controlling the output voltage according to the situation of inputs.
and just the modes that you saw in the program can occur .
thanks for all of your help. my problem is solved .

mister_e
- 17th December 2007, 04:48
You know what that means RIGHT?
Yup, this ain't over yet!
:D yup.. sounds like a challenge... 100% PBP??? Maybe doable... scratch, scratch...mmm...

Darrel Taylor
- 18th December 2007, 02:11
12C508A's bad enough,
you want 100% PBP??? too? :)

Did you know it doesn't even have an overflow flag on timer0?
I didn't, Oi vey!

I had so much fun this time last year with what ended up as the 12-byte cylon scanner,
perhaps I'm a bit over zealous.

The OP is satisfied, and probably wouldn't use it anyways,
So even if the program size was only 83 words, like I have it now,
It'll never be used.

We need a real Optimization contest.
They're just too fun.
<br>

mister_e
- 18th December 2007, 03:16
yup, no eeprom either... so nothing interesting. Think it's like a 16F84A, 16C54... but in 8 pin package :D

There's always place for an optimization contest, next time, no rules (pic, language etc etc )... agreed?

skimask
- 18th December 2007, 13:59
yup, no eeprom either... so nothing interesting. Think it's like a 16F84A, 16C54... but in 8 pin package :D
There's always place for an optimization contest, next time, no rules (pic, language etc etc )... agreed?

Make it tough...use a 10F200...no SOT->DIP adapters allowed, only hand soldering, dead bug style. In fact, no soldering, hand wrap wires around the legs....
and no power supply, hand crank a motor to charge up a cap... :D

Bruce
- 18th December 2007, 14:44
Any chance we can see that 12-byte cylon scanner?

Darrel Taylor
- 18th December 2007, 15:34
Sure,

The 12-byte version is toward the end on page 2.
http://www.sfcompiler.co.uk/forum/viewtopic.php?t=72

Edit: Hey, you were there to. :)
<br>

Bruce
- 18th December 2007, 16:01
Yipes I totally forgot that one. That was way interesting and the end result was really creative.

Nice work DT..;o}

Tim B and I got into one of these a long time back, and here's one he came up with.

Can we beat this without EEPROM?

Standard cyclone thingie moving the LED back & forth with ~1S delay periods.


list p=16F628A
#include "P16F628A.inc"
errorlevel -302 ; suppress message 302 from list file
__CONFIG _CP_OFF & _BODEN_ON & _MCLRE_ON & _WDT_ON & _PWRTE_ON & _LVP_OFF & _INTOSC_OSC_NOCLKOUT

movlw 0x01
movwf PORTB ; Set Portb,0
bsf STATUS,RP0 ; Bank 1
clrf TRISB ; RB all outputs
bcf OPTION_REG,0 ; 1:64 prescaler to WDT
bcf STATUS,RP0 ; Bank 0

Left
sleep ; go to sleep for 64 * 18mS ~1 second
rlf PORTB,F ; rotate bit across portb from lsb to msb
btfss PORTB,7 ; jump to Right after Portb,7 = 1
goto Left

Right
sleep ; go to sleep for 64 * 18mS ~1 second
rrf PORTB,F ; rotate bit across Portb from msb to lsb
btfss PORTB,0 ; jump back to left after Portb,0 = 1
goto Right ; loop until Portb,0 = 1
goto Left ; now rotate back to the left.

End

mister_e
- 18th December 2007, 16:15
:eek: seems to be hardly optimized to me ;)

food for thought... let's see...

Darrel Taylor
- 18th December 2007, 20:25
Tim's compiled to 15 words.

Here's 13 ... :cool: &nbsp; Note: LED's go to VDD

list p=16F628A
#include "P16F628A.inc"
errorlevel -302 ; suppress message 302 from list file
__CONFIG _CP_OFF & _BODEN_ON & _MCLRE_ON & _WDT_ON & _PWRTE_ON & _LVP_OFF & _INTOSC_OSC_NOCLKOUT

clrf PORTB ; PORTB all 0's
bsf STATUS,RP0 ; Bank 1
bcf OPTION_REG, 0 ; 1:64 prescaler to WDT
bcf TRISB, 0 ; set RB0 to output
bsf STATUS, C ; set carry flag for rotation
Loop
btfss TMR2, 3 ; switch Left/Right every 8 times
rlf TRISB,F ; rotate Left across TRISB
btfsc TMR2, 3
rrf TRISB,F ; rotate Right across TRISB
btfsc STATUS, C ; No sleep if output rotated into carry
sleep ; nite nite
incf TMR2 ; Timer2 used for it's 00 value on reset.
goto Loop ; Repeat


EDIT: Rats!
While it works in MPSIM, it's not going to do it on the real thing.
Time for a breadboard.

<br>

Darrel Taylor
- 19th December 2007, 01:36
OK, ignore the last one. That's what I get for using a simulator.

This is 14 WORDS, 1 less than Tim's.
At least it beats him :)


list p=16F88
#include "P16F88.inc"
errorlevel -302 ; suppress message 302 from list file
__CONFIG _CONFIG1, _XT_OSC & _CP_OFF & _BODEN_ON & _MCLR_ON & _WDT_ON & _PWRTE_ON & _LVP_OFF

clrf PORTB ; PORTB all 0's
bsf STATUS,RP0 ; Bank 1
bcf OPTION_REG, 0 ; 1:64 prescaler to WDT
bcf TRISB, 0 ; RB0 output
Loop
sleep ; nite nite

btfss SPBRG,0 ; SPBRG used for it's 00 reset value
rlf TRISB,F ; rotate Left across TRISB
btfsc SPBRG,0
rrf TRISB,F ; rotate Right across TRISB

btfss TRISB, 7 ; At LED7? - go the other way
incf SPBRG,F
btfss TRISB, 0 ; At LED0? - go the other way
incf SPBRG,F

goto Loop ; Repeat

LED's go to VDD.
Tested, working on 16F88, should be the same (except configs) on 16F628A.
<br>

mister_e
- 19th December 2007, 02:48
yup.. hence why i never trust sim...

Bruce
- 19th December 2007, 18:13
Nice work DT.

Here's one at 13 words.


list p=16F628A
#include "P16F628A.inc"
errorlevel -302
__CONFIG _CP_OFF & _BODEN_ON & _MCLRE_OFF & _WDT_ON & _PWRTE_ON & _LVP_OFF & _INTOSC_OSC_NOCLKOUT

clrf PORTB ; clear port
bsf STATUS,RP0 ; Bank 1
bcf TRISB,0 ; RB0 = output
bcf OPTION_REG,0 ; 1:64 prescaler to WDT

Left
sleep ; go to sleep for 64 * 18mS ~1 second
rlf TRISB,F ; rotate bit across portb from lsb to msb
btfsc TRISB,7
goto Left

Right
sleep ; go to sleep for 64 * 18mS ~1 second
rrf TRISB,F ; rotate bit across Portb from msb to lsb
btfsc TRISB,0
goto Right
goto Left ; now rotate back to the left.

End

Darrel Taylor
- 19th December 2007, 19:36
Oh Yeah! Very nice Bruce.

Now that's going to be hard to beat.
If you don't hear from me for a month.
You'll know what happened. :)

skimask
- 19th December 2007, 20:20
Oh Yeah! Very nice Bruce.

Now that's going to be hard to beat.
If you don't hear from me for a month.
You'll know what happened. :)

I just checked on my '628A on my breadboard...about a ba-zillion times...
I set up code/hardware to do nothing but RESET, and put Port B onto a bank of LEDs, Vdd on the other side of the LED.
EACH time, Port B came up ZERO...no LEDs lit up, until I set a TRIS bit for output.
So, my submission...
Coming in at 12 bytes...



list p=16F628A
#include "P16F628A.inc"
errorlevel -302
__CONFIG _CP_OFF & _BODEN_ON & _MCLRE_OFF & _WDT_ON & _PWRTE_ON & _LVP_OFF & _INTOSC_OSC_NOCLKOUT

; clrf PORTB ; clear port - not required on my breadboard, might be different on others
bsf STATUS,RP0 ; Bank 1
bcf TRISB,0 ; RB0 = output
bcf OPTION_REG,0 ; 1:64 prescaler to WDT

Left
sleep ; go to sleep for 64 * 18mS ~1 second
rlf TRISB,F ; rotate bit across portb from lsb to msb
btfsc TRISB,7
goto Left

Right
sleep ; go to sleep for 64 * 18mS ~1 second
rrf TRISB,F ; rotate bit across Portb from msb to lsb
btfsc TRISB,0
goto Right
goto Left ; now rotate back to the left.

End



Somebody else check this out and see what happens.
As I stated, maybe it's my breadboard, maybe it's my 628A (I've only got 1 left), maybe it's the rise time on my PSU.

EDIT: Datasheet says that the port registers come up in an unknown state. Apparently, in this case, I now know my state...

Bruce
- 20th December 2007, 14:50
It might work on one series, but I wouldn't count on it as being reliable across the board.
I have seen various PICs come up with totally random values in port latches at POR, so
you really do need to clear portb latches first if it's to be reliable.

mister_e
- 20th December 2007, 17:11
i'm thinking of something using interrupt.. not sure if it could reduce things to 8-10 words... mmm..

Bruce
- 20th December 2007, 17:44
I had considered that approach too, but more than half of your code space (or more) would
be eaten up with interrupt configuration setup.

Making it "reliable" with less than 13 words is going to be a real task.

mister_e
- 20th December 2007, 21:50
yup, but where is it stated that it has to be reliable, where it is stated that we need to use the same PIC and hardware ? ;)

i still believe it's doable... but with some hair lost :D

skimask
- 20th December 2007, 22:33
It might work on one series, but I wouldn't count on it as being reliable across the board.
I have seen various PICs come up with totally random values in port latches at POR, so
you really do need to clear portb latches first if it's to be reliable.

I don't doubt that at all...
I just checked the CARRY bit, datasheet says unknown on POR, mine come's up cleared every time (at least every time I've check anyways). That shoots that idea down...

Darrel Taylor
- 21st December 2007, 00:21
yup, but where is it stated that it has to be reliable?
I think that's a given. It has to work when you turn on the power.
As for the rest of the rules, well, I'm assuming No EEPROM is the only one. Edit: with a 16F628A

i still believe it's doable... but with some hair lost :D
I'm starting to believe NO.
But I haven't given up yet.

I've got 3 completely different versions at 13 words now.
1 using external circuitry to TMR0
1 using external circuitry to a comparator
and another that simply shaves a word off my 14 word program. (wish I'd done that to begin with)

It seems that no matter what you do to save a word, you end up having to add something to make it work. :(

I'm sure getting some "Quality Time" in with the datasheets though. :) All kinds of stuff I didn't know before.
<br>

mister_e
- 21st December 2007, 01:19
yup all good points.. the only thing i've never dare to mess with is the stack overflow behaviour and ORG... 8 bit stack seems nice... but not sure how bad/good it behave...mmm

:D interesting how a led chaser can be a food for thought :D

skimask
- 21st December 2007, 03:44
yup all good points.. the only thing i've never dare to mess with is the stack overflow behaviour and ORG... 8 bit stack seems nice... but not sure how bad/good it behave...mmm
:D interesting how a led chaser can be a food for thought :D

Something tells me that somebody is about to break the law...
The law of diminishing returns! :D

Does this 'thing' have to have 8 LEDs? Or can it have 16 LEDs?
I'm thinking something along the lines of 2 LEDs per pin, back-to-back, with the common for all running to another pin...don't know what I'm thinking yet...

mister_e
- 21st December 2007, 05:42
Yeah maybe breaking the law, but as i said, i didn't test it...it just looks good in my mind... 8 deep level stack, 8 leds... mmm ;)

skimask
- 21st December 2007, 06:40
Yeah maybe breaking the law, but as i said, i didn't test it...it just looks good in my mind... 8 deep level stack, 8 leds... mmm ;)

Great...now you got me thinking...and I was about ready to sleep...
Flip a bit...recursive call's without return's, slide a bit over...wash/lather/rinse/repeat/STACK OVERFLOW...flip a bit...repeat...

Darrel Taylor
- 22nd December 2007, 00:49
Ladies and Gentlemen!

Please direct your attention to the Center Ring .... http://www.pbpgroup.com/files/clown.gif

12 WORDs
list p=16F628A
#include "P16F628A.inc"
errorlevel -302 ; suppress message 302 from list file
__CONFIG _CP_OFF & _BODEN_ON & _MCLRE_ON & _WDT_ON & _PWRTE_ON & _LVP_OFF & _INTOSC_OSC_NOCLKOUT

Init
clrf PORTB ; PORTB all 0's
rlf STATUS, F ; sets Bank1 and clears carry
bcf OPTION_REG, 2 ; 1:8 prescaler to WDT
comf SPBRG,F ; Make SPBRG all 1's
Loop
btfsc STATUS,C ; no sleep if rotated into carry
sleep

rlf SPBRG,F ; rotate SPBRG left msb to carry
rrf PR2, F ; rotate carry into PR2, lsb to carry
movf SPBRG, W ; put SPBRG into W reg
andwf PR2, W ; and it with PR2
movwf TRISB ; result goes to TRISB

goto Loop ; Repeat

Bwwaaa Haaa Haaa!

Added:
<script language="javascript" src="http://www.pbpgroup.com/files/CylonRotate.js"></script><br>

mister_e
- 22nd December 2007, 12:16
http://www.mister-e.org/Pics/ROFL Woohoo, now if we see this code example somewhere, we will know where it come from ;) PR2, SPBRG... euh in a light 'chaser' ,deuh, doh... hein??? :D

Nice one.... smell of the burned brain-cells, but nice ;o}

Bruce
- 4th January 2008, 18:33
Well, that's going to be tough to beat. Nice work Darrel.

Interesting side note: Using your rlf STATUS,F approach reduced my 13 word version to
only 12 words..;o}


list p=16F628A
#include <P16F628A.inc>
errorlevel -302 ; suppress message 302 from list file
__CONFIG _CP_OFF & _BODEN_ON & _MCLRE_OFF & _WDT_ON & _PWRTE_ON & _LVP_OFF & _INTOSC_OSC_NOCLKOUT

clrf PORTB ; clear port
rlf STATUS,F ; Bank1, clear carry for 1st rotate
bcf OPTION_REG,2 ; 1:8 prescaler to WDT

Left
sleep ; go to sleep for ~1 second
rlf TRISB,F ; rotate 0 from carry into lsb, then left across trisb
btfsc TRISB,7 ; jump to Right once trisb,7 = 0
goto Left

Right
sleep ; go to sleep for ~1 second
rrf TRISB,F ; rotate bit right across trisb
btfsc TRISB,0 ; jump to left once trisb,0 = 0

goto Right ; loop until trisb,0 = 0
goto Left ; now rotate back to the left

end

Darrel Taylor
- 4th January 2008, 19:21
OMG! How HORRIBLE!

That means yours doesn't pause at each end like mine.
Which makes your 12, better than my 12.

http://www.pbpgroup.com/files/sm/cry.gif

Actually, it's awesome,
I'm crying because now I have to spend the next week trying to beat it.
<br>

Bruce
- 4th January 2008, 20:11
Oh I wouldn't call it better since your version is WAY more creative, and your nifty rotate STATUS thing was the only reason mine was reduced.

Man that was some clever & creative problem solving, and that's really what it's all about...;o}