View previous topic :: View next topic |
Author |
Message |
Shazter
Joined: 04 Jul 2004 Posts: 1
|
Posted: Sun Jul 04, 2004 3:44 pm Post subject: Stack Pointer and Softwarestack overlap |
|
|
Hi
i programmed my first great Programm in Bascom.
I set a Flag in the Timer1 ISR and the Timer1 is my problem .... After a few Timer1 overflows the Simulator say "Softstackpointer and Softstack overlap" ... On the real Hardware is it the same Problem. I increased the Softstack and the Framestack in the Compiler Menu same Problem ...
I hope somebody can help or i must reprogramm all things in AVR GCC
here my Code
Code: |
$sim
$regfile = "m8def.dat"
$crystal = 7372800
$baud = 115200
' ******************************************************************************
' * Variablen , Aliases *
' ******************************************************************************
Dim A As Byte
Dim I As Byte ' Schleifenzaehler
Dim Temp As Byte ' Schleifenzaehler
Dim Red As Byte ' Farbe Rot
Dim Green As Byte ' Gruene Farbe
Dim Blue As Byte ' Blaue Farbe
Dim Yellow As Byte ' Gelbe Farbe
Dim Farbe As Byte
Dim Farbe_old As Byte
Dim Menuzaehler As Byte
Dim Menuzaehler_old As Byte
Dim Testvar As Byte
Dim Ok_flag As Bit
Dim Blink_flag As Bit
Dim R As Byte ' In diese Variablen muss man
Dim G As Byte ' im Hauptprogram die gewünschten
Dim B As Byte ' Ausgabewerte laden
Dim Y As Byte
Dim Z As Word ' Zähler
Dim Ri As Byte ' Hilfsregister
Dim Gi As Byte
Dim Bi As Byte
Dim Yi As Byte
Redlamp Alias Portd.2
Greenlamp Alias Portd.3
Bluelamp Alias Portd.4
Yellowlamp Alias Portd.5
' ******************************************************************************
' * LCD Settings *
' ******************************************************************************
Config Lcd = 20 * 4
' ******************************************************************************
' ******************************************************************************
' * LCD Bargraphzeichen *
' ******************************************************************************
Deflcdchar 0 , 31 , 16 , 16 , 16 , 16 , 16 , 16 , 31 ' "["
Deflcdchar 1 , 31 , 32 , 32 , 32 , 32 , 32 , 32 , 31 ' "="
Deflcdchar 2 , 31 , 1 , 1 , 1 , 1 , 1 , 1 , 31 ' "]"
Deflcdchar 3 , 31 , 31 , 31 , 31 , 31 , 31 , 31 , 31 ' "Full Cursor"
' ******************************************************************************
' ******************************************************************************
' * I/O Settings *
' ******************************************************************************
Config Portd = Output
Config Portc = Input
Portc = 255
Portd = 255
'Config Redlamp = Output
'Config Greenlamp = Output
'Config Bluelamp = Output
'Config Yellowlamp = Output
' ******************************************************************************
' ******************************************************************************
' * RC5 Settings *
' ******************************************************************************
' ******************************************************************************
' ******************************************************************************
' * Timer Settings *
' ******************************************************************************
Config Timer1 = Timer , Prescale = 1
Config Timer2 = Timer , Prescale = 8
' On Ovf2 Tim2_isr
On Ovf1 Tim1_isr
' ******************************************************************************
' ******************************************************************************
' * MAIN LOOP *
' ******************************************************************************
' START
' Enable Timer2 'timer einschalten
Enable Timer1
Enable Interrupts 'interrupts einschalten
' Z = 0
Menuzaehler = 1
Menuzaehler_old = 1
Ok_flag = 0
' R = 0
' Main:
' Incr R
' G = 142
' B = 255
' Y = 255
' Goto Main
'End
Main:
Cls
Gosub Mainscreen
Do
Debounce Pinc.5 , 1 , Down_key , Sub
Debounce Pinc.4 , 1 , Up_key , Sub
Debounce Pinc.3 , 1 , Ok_key , Sub
If Menuzaehler <> Menuzaehler_old Then Gosub Cursorposi
Menuzaehler_old = Menuzaehler
If Farbe <> Farbe_old Then Gosub Bargraph
Farbe_old = Farbe
If Blink_flag = 1 Then
Locate Menuzaehler , 1
Lcd " "
Else
Locate Menuzaehler , 1
Lcd "*"
End If
Loop
End
'Main:
'Cls
'Gosub Mainscreen
'Main2:
'Do
'Gosub Bargraphgreen
'Incr Green
'If Green = 17 Then
' Gosub Test
' End If
' Loop
' Test:
' Do
' Decr Green
' Gosub Bargraphgreen
' If Green = 0 Then
' Return
' End If
' Loop
' Return
' ******************************************************************************
' ******************************************************************************
' * Timer 1 ISR (8,89ms) *
' ******************************************************************************
Tim1_isr:
If Ok_flag = 1 Then
Toggle Blink_flag
End If
Return
' ******************************************************************************
' ******************************************************************************
' * Timer 2 ISR (34,72µs) *
' ******************************************************************************
' Tim2_isr:
' If Z = 0 Then 'Gewünschte Ausgabewerte an
' Ri = R 'Hilfsregister übergeben
' Gi = G
' Bi = B
' Yi = Y
' Z = 255
' End If
' Z = Z - 1
' If Ri > 0 Then 'R > Port B.0
' Redlamp = 1 'bei R = 51 wird hier
' Else 'Port B.0 51 mal auf 1
' Redlamp = 0 'und 205 mal auf 0 geschaltet
' End If 'das ergibt bei 5V Ub im Mittel
' Ri = Ri - 1 ' ca. 1 V
' If Ri = 255 Then Ri = 0
' If Gi > 0 Then 'G > Port B.1
' Greenlamp = 1
' Else
' Greenlamp = 0
' End If
' Gi = Gi - 1
' If Gi = 255 Then Gi = 0
' If Bi > 0 Then
' Bluelamp = 1 'B > Port B.2
' Else
' Bluelamp = 0
' End If
' Bi = Bi - 1
' If Bi = 255 Then Bi = 0
' If Yi > 0 Then
' Yellowlamp = 1 'B > Port B.2
' Else
' Yellowlamp = 0
' End If
' Yi = Yi - 1
' If Yi = 255 Then Yi = 0
' Hier könnten eigentlich noch weitere Kanäle eingefügt werden
' Return
' ******************************************************************************
' ******************************************************************************
' * Bargraph *
' ******************************************************************************
Bargraph:
Temp = 0
Locate Menuzaehler , 2
For I = 1 To Farbe
Lcd Chr(3)
Next I
Temp = Farbe + 2
Locate Menuzaehler , Temp
For I = Farbe To 14
If Farbe = 0 Then
Locate Menuzaehler , 2
Lcd Chr(0)
Exit For
End If
Lcd Chr(1)
Next I
If Farbe = 16 Then
Return
End If
Locate Menuzaehler , 17
Lcd Chr(2)
Return
' ******************************************************************************
' ******************************************************************************
' * LCD Bargrah Screen *
' ******************************************************************************
Mainscreen:
For A = 1 To 4
Locate A , 2
Lcd Chr(0)
For I = 1 To 14
Lcd Chr(1)
Next I
Locate A , 17
Lcd Chr(2)
Next A
Locate 1 , 1
Lcd "*"
Return
' ******************************************************************************
' ******************************************************************************
' * Down KEY *
' ******************************************************************************
Down_key:
If Ok_flag = 1 Then
Select Case Menuzaehler
Case 1:
Incr Red
Farbe = Red
Case 2:
Incr Green
Farbe = Green
Case 3:
Incr Blue
Farbe = Blue
Case 4:
Incr Yellow
Farbe = Yellow
End Select
Else
Menuzaehler_old = Menuzaehler
Incr Menuzaehler
End If
Return
' ******************************************************************************
' ******************************************************************************
' * UP KEY *
' ******************************************************************************
Up_key:
If Ok_flag = 1 Then
Select Case Menuzaehler
Case 1:
Decr Red
Farbe = Red
Case 2:
Decr Green
Farbe = Green
Case 3:
Decr Blue
Farbe = Blue
Case 4:
Decr Yellow
Farbe = Yellow
End Select
Else
Menuzaehler_old = Menuzaehler
Decr Menuzaehler
End If
Return
' ******************************************************************************
' ******************************************************************************
' * OK KEY *
' ******************************************************************************
Ok_key:
Toggle Ok_flag
Return
' ******************************************************************************
' ******************************************************************************
' * Cursorposi *
' ******************************************************************************
Cursorposi:
Select Case Menuzaehler
Case 0 : Menuzaehler = 1
Case 1:
Locate Menuzaehler_old , 1
Lcd " "
Locate Menuzaehler , 1
Case 2:
Locate Menuzaehler_old , 1
Lcd " "
Locate Menuzaehler , 1
Case 3:
Locate Menuzaehler_old , 1
Lcd " "
Locate Menuzaehler , 1
Case 4:
Locate Menuzaehler_old , 1
Lcd " "
Locate Menuzaehler , 1
Case 5 : Menuzaehler = 4
End Select
Return
' ****************************************************************************** |
|
|
Back to top |
|
|
rprosser
Joined: 17 Jun 2004 Posts: 8 Location: Christchurch NZ
|
Posted: Wed Jul 21, 2004 10:58 am Post subject: |
|
|
I copied your program & it ran OK.
However the "$regfile = " statement should be the first statement in the program, if it is not, a different chip may be selected by the compiler - dependent on the "Chip Settings" menu & possibly earlier history.
Otherwise I can't find anything wrong. |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Sat Jul 24, 2004 2:46 pm Post subject: |
|
|
Remove the $SIM when trying in real hardware.
-increase the HW stack to 40 bytes
-incease the SW stack to 40 bytes _________________ Mark |
|
Back to top |
|
|
jakim
Joined: 29 Aug 2004 Posts: 8 Location: Estonia
|
Posted: Sun Aug 29, 2004 2:57 pm Post subject: |
|
|
I have the same problem. My program is very small but when il try to simulate the code it stops after few debounce in and out of the menus. I allready increased the Hwstack size and the software stack size in the compiler chip menu but it still stops! Is there anything do to or is it just simulator error or compiler error?
My code for atmega16 (selected in chip options before compile)
Dim A As byte , Ts As byte , Bs As byte,
Toide Alias Pind.0 'power button'
Meny Alias Pind.1 ' menu button'
Down Alias Pind.2
Up Alias Pind.3
C Alias Pind.4 ' exit menu button'
A = 0
Ts = 0
Bs = 0
Do
Alg:
Debounce Toide , 1 , Pr , Sub
Waitms 200
Loop
Pr:
Incr A
If A = 1 Then
Cls
Lcd "toide sees"
Set Portb.1
Goto Menu_0
End If
If A = 2 Then
Cls
Lcd " toide väljas"
Reset Portb.1
A = 0
Goto Alg
End If
Menu_0:
Cls
Lcd " press MENU to Treble "
1:
Debounce Meny , 1 , Treble , Sub ' kirjutatakse kiri "treble" menu vajutamisel sisenetakse menüüsse
Debounce Down , 1 , Menu_1 , Sub ' down nuppu vajutamisel liigub järgmise menüüni"bass"
Debounce Toide , 1 , Pr , Sub 'toide vajutamisel väljub menüüst ja läheb voolude menüüsse
Goto 1
Treble:
Cls
Lcd "[treble]"
Debounce Up , 1 , Trbl_up , Sub
Debounce Down , 1 , Trbl_dn , Sub 'up nupu vajutamisel läheb edasi treble upima
Debounce C , 1 , Menu_0 , Sub 'down nupu vajutamisel läheb edasi treble downima
Debounce Toide , 1 , Pr , Sub
Waitms 300
Goto Treble
Trbl_up: 'rohkem kõrgeid funktsioonid
If Ts = 12 Then
Cls
Lcd "Treble allready maximum!"
Goto Treble
End If
Ts = Ts + 3
Cls
Lcd "Treble" ; Ts ; "dB"
Goto Treble
Trbl_dn: ' vähem kõrgeid fumktsioonid
If Ts = 0 Then
Cls
Lcd "Treble allready minimum!"
Goto Treble
End If
Ts = Ts - 3
Cls
Lcd "Treble" ; Ts ; "dB"
Goto Treble
Menu_1:
Cls
Lcd "Bass"
Debounce Up , 1 , Treble , Sub
Debounce Meny , 1 , Bss , Sub ' kirjutatakse kiri "bass" menu vajutamisel sisenetakse menüüsse
' down nuppu vajutamisel liigub järgmise menüüni"sisendid"
Debounce Toide , 1 , Pr , Sub
Goto Menu_1
Bss:
Cls
Lcd "[Bass]"
Debounce Up , 1 , Bss_up , Sub
Debounce Down , 1 , Bss_dn , Sub 'up nupu vajutamisel läheb edasi bass upima
Debounce C , 1 , Menu_0 , Sub
Debounce Toide , 1 , Pr , Sub
Waitms 300
Goto Bss 'up nupu vajutamisel läheb edasi bass downima
Bss_up:
If Bs = 15 Then
Cls
Lcd "Bass allready maximum!"
Goto Bss
End If
Bs = Bs + 3
Cls
Lcd "Bass" ; Bs ; "dB"
Goto Bss
Bss_dn: ' vähem kõrgeid funktsioonid
If Bs = 0 Then
Cls
Lcd "Bass allready minimum!"
Goto Bss
End If
Bs = Bs - 3
Cls
Lcd "Bass" ; Bs ; "dB"
Goto Bss |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Tue Aug 31, 2004 10:09 pm Post subject: |
|
|
You need to increase the HW stack when using interrupts without the NOSAVE option. Notice NOSAVE is only for people that know what they do/change inside the ISR !!!
When you have a lot of nested GOSUB, then you also need to increase the HW stack.
I advise to start with a value of 40. You can always decrease it. _________________ Mark |
|
Back to top |
|
|
jakim
Joined: 29 Aug 2004 Posts: 8 Location: Estonia
|
Posted: Sun Sep 12, 2004 9:49 am Post subject: |
|
|
I found that if i use return at the end of the sub instead of goto label the program works fine and no overlap. How can that explained? |
|
Back to top |
|
|
philm
Joined: 14 Jul 2004 Posts: 138 Location: Australia
|
Posted: Sun Sep 12, 2004 11:13 am Post subject: |
|
|
When you enter a sub, the return address is pushed onto the hardstack.
When the program hits a return, the return address is poped of the hardstack.
If you exit a sub using "goto", the return address is never poped. When you do this a few times, the hardstack grows down into softstack area, then into frame area, then into data area. |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
|
|