First Program up and running, Almost...

Discussion of issues related to writing ZBasic applications for targets other than ZX devices, i.e. generic targets.
Post Reply
DocJC
Posts: 112
Joined: 16 March 2006, 6:23 AM
Location: Cleveland, OH
Contact:

First Program up and running, Almost...

Post by DocJC »

I guess I make a good Beta Tester, as if I can do it you know you have a Fool Proof system!

I loaded ZBasic V3.4.1 (with IDEV 1.5.11) on my small, slow, netbook to take on a trip, knowing I would have some time, finally, to start working with the new generic compiler.

I wrote my first ZBasic program to flash a Tiny2313's led.

I pulled down the menu and clicked on Compile.

Nothing happened.
OK, I had purposefully NOT copied the license file to see if I would get an appropriate License not found message. I didn't get that.

OK, copy the license to the ZBasic directory, and hit compile again.
Still nothing.

Enabled the Output Box and see:>"C:\Program.... License-valid
> Exit Code 1

I did a quick search of the ZBasicRef.pdf and ZBasicSysLib.pdf and did not locate a list of Exit Codes.

Perhaps I have to used case sensitive input for the pdf search, I'll try that later.

Did a Windows search for *.hex and did not find my file.

I'll have to look further when I'm back out of class, but I'm not yet sure why it didn't compile my program and give me an output message, (Errors, warnings, etc).

I assume the output for the hex file will be the source file's folder?

I guess in summary: Where do I find the Exit Code table and descriptions?

Thanks,

JC

Edit: There is probably a flag for this...

I expected the IDE to automatically append .BAS to my file when I entered the name for my first program.

It did not do so, hence the Compile command didn't do anything.

When I changed the name and included the .BAS identifier myself, then the compiler did its job.

JC
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Re: First Program up and running, Almost...

Post by dkinzer »

DocJC wrote:I pulled down the menu and clicked on Compile.
Does a simple "do nothing" application compile? If not, there is an issue either with the way the compiler is installed or the way that the project files were created. If you'll send me a .pjt and .bas file that do not compile, I can try to reproduce the issue here by following the same steps that you use.
- Don Kinzer
DocJC
Posts: 112
Joined: 16 March 2006, 6:23 AM
Location: Cleveland, OH
Contact:

Post by DocJC »

Hi Don,

When I wrote the program I clicked on Save As and typed in:
Tiny2313 LED Flasher V1
and hit enter.

I did not originally give the file a .bas extension.
The compiler did nothing with the program, it did not even try to compile it, as far as I can tell.

When I went back and gave it a .bas extension, it then compiled the program, and gave me appropriate warning and error messages.

So it all works if the file has a .bas extension.

It would have helped me to spot the problem had it recognized the lack of a .bas extension and told me to add one.

I guess my original expectation was that the IDE would add that extension for me, automatically.

JC
DocJC
Posts: 112
Joined: 16 March 2006, 6:23 AM
Location: Cleveland, OH
Contact:

Post by DocJC »

Yeah! My first Generic uC program compiles and runs.

It simply wig-wags two LEDs on and off, program driven, no Timer/Counters or ISRs used except that used internally by ZBasic for the Delay() function.

Although it compiles, 0 Errors, and runs, it gives me a Task Stack Warning.

>"C:\Program Files\ZBasic\zbasic.exe" --target-device=ZX24 --directory="D:\ZBasic Progs/" "Tiny2313 LED Flasher V2.bas"
Warning(13): task stack for "Main" is too small, 37 bytes needed, 32 bytes available
No errors. Target device: attiny2313, Code: 1104 bytes, RAM: 64 bytes, Persistent memory: 0 bytes
>Exit code: 0

I view this as a pretty simplistic program, non-multi-tasking, only a few lines long, and nothing complex going on.
Why, therefore, does it say that only 32 bytes are available for the Main Task Stack?

I did not expect to see any Main Task Size warnings.

Any thoughts on this?

Thanks,

JC

Code: Select all

'ZBasic Generic Target Compiler
'Tiny2313 LED Flasher
'V 2	Oct. 18, 2011
	
'System Definitions:
option targetdevice ATTiny2313			'Define micro used
option deviceparameter clockfrequency 20000000	'uC clock frequency
	
Sub Main()
	'Define Port Pins I/O:
	call putpin(d.2, zxoutputlow)		'Make it output, and low
	call putpin(d.4, zxoutputlow)		'Make it output, and low

	do
		call putpin(d.2, zxoutputlow)		'Make it output, and low
		call putpin(d.4, zxoutputhigh)		'Make it output, and high
		call delay(0.1)						'100 mSec
		call putpin(d.2, zxoutputhigh)		'Make it output, and high
		call putpin(d.4, zxoutputlow)		'Make it output, and low
		call delay(0.1)						'100 mSec
	loop
end sub
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Post by dkinzer »

DocJC wrote:Why, therefore, does it say that only 32 bytes are available for the Main Task Stack?
Even though it is a relatively simple program, there are still some "system" variables that use up RAM. The .sym file shows this:

Code: Select all

00800060 B freeList
00800062 B comChanData
0080006c B zxd
00800098 B seedPRNG
0080009c B heapLimit
0080009e B heapEnd
008000a0 B _end
The largest component zxd (44 bytes) is the structure holding most of the "system" data. The total of the statically allocated data is 64 bytes, half of the available RAM on a tiny2313. The remaining 64 bytes is used by the task stack and the heap. The default heap size on is 32 bytes, leaving only 32 for the main task stack.

Note that the task stack size estimate includes a "safety margin" of 10 bytes. You can reduce this using the Option TaskStackMargin directive. However, even if you reduce the safety margin to zero, that still leaves you 4 bytes short.

You can also reduce the heap size to leave more available for the main task stack. Your application uses no heap directly so you could safely reduce it to the minimum (4 bytes for the tiny2313) with the Option HeapSize directive.

Lastly, you can reduce stack usage by directly manipulating ports rather than using PutPin().

Code: Select all

Sub Main()
    Register.DDRD = &H14         ' set bits D.2 and D.4 as outputs
    Register.PortD = &H04        ' set D.2, clear D.4
    Do
        Register.PinD = &H14     ' toggle bits D.2 and D.4
        call delay(0.25)         ' 1/4 Sec
    Loop

End Sub
This should have the same effect as the program that you sent me but it uses 6 bytes less stack space and has smaller code size, too.
- Don Kinzer
DocJC
Posts: 112
Joined: 16 March 2006, 6:23 AM
Location: Cleveland, OH
Contact:

Post by DocJC »

Got it!

Thank you for the explaination.

I appreciate your taking the time to explain it to me.

JC
Post Reply