18F1320 and Math routines

Coding and general discussion relating to the compiler

Moderators: David Barker, Jerry Messina

Post Reply
MarkW
Posts: 73
Joined: Fri Oct 27, 2006 8:09 pm

18F1320 and Math routines

Post by MarkW » Mon Oct 30, 2006 1:57 pm

I wanted to play with the floating point routines and wrote the simple program below. When I compile it I get two errors:

"Program variable allocation exceeds Swordfish Special Edition (SE) maximun"
"Program variable allocation exceeds device maximun"

Will the SE version allow me to use the math routines if I get a different PIC (I got the smallest one I could find at the time to play with) or will I still have a limit imposed by the SE version?

Thanks,
Mark


Device = 18F1320
Clock = 8

Include "USART.bas"
Include "Math.bas"
Include "convert.bas"

// alias to port pin...
Dim LED As PORTB.0

Dim fpA As Float
Dim fpB As Float
Dim fpC As Float

// main program...

OSCCON = %01110000 '8 MHz

'Wait for osc to get stable
While OSCCON.2=0
Wend

'Set up UART
SetBaudrate(br9600)

fpA = 10.0
fpB = 3.0


Low(LED)
Repeat
fpC = fpA/ fpB
USART.Write(FloatToStr( fpC), 13, 10)
Toggle (LED)
DelayMS (100)
Until false

End

JackOfVA
BETA Tester
Posts: 16
Joined: Tue Oct 03, 2006 9:04 pm
Location: Clifton, VA USA
Contact:

Post by JackOfVA » Mon Oct 30, 2006 7:22 pm

Mark:

I compiled your test program for an 18F4620, and the compiler reports that it requires 295 RAM bytes, which is over the 200 byte cap in the SE version.

I think you are not going to be able to run much (any?) floating point in SE.

You might experiment by setting the DEVICE to 18F4620 and see what the compiler statistics show as you try various FP routines.

Jack
Jack, Clifton VA

User avatar
David Barker
Swordfish Developer
Posts: 1214
Joined: Tue Oct 03, 2006 7:01 pm
Location: Saltburn by the Sea, UK
Contact:

Post by David Barker » Mon Oct 30, 2006 8:04 pm

The SE version will handle floating point, even on a 18F1320. The routine that's using most of the RAM resources is FloatToStr(). It has to do a lot of work in order to convert the FP number into a string. Take a look at the module implementation to see what I mean.

If you remove the line that performs the FloatToStr() conversion, you will see the RAM usage fall considerably.

As you can see, the program will now compile - you can use (limited) FP math with the SE version, you just won't be able to display any FP with the current FloatToStr() implementation...

MarkW
Posts: 73
Joined: Fri Oct 27, 2006 8:09 pm

Post by MarkW » Mon Oct 30, 2006 10:05 pm

Thanks for the replys. After using PicBasic Pro for the past couple of years and working with integers I was just wanting to see what its like to have FP numbers. I have never actually needed FP in any past projects but it might make some things a lot easier in the future. Thanks again.
Mark

Post Reply