Search found 219 matches

by SHughes_Fusion
Thu Oct 29, 2015 11:57 am
Forum: Compiler
Topic: Tips for optimising bank switching?
Replies: 27
Views: 10179

Re: Tips for optimising bank switching?

Wow - I've just found one thing that really should go in the 'how to optimise your code' FAQ. I have a 'Program Globals.bas' in which I define all variables which need to be global rather than sub / function temporary. I've moved *all* variable definitions in to that - I had quite a few which I'd st...
by SHughes_Fusion
Thu Oct 29, 2015 9:45 am
Forum: Compiler
Topic: Compiler Const bug?
Replies: 15
Views: 7058

Re: Compiler Const bug?

Unfortunately neither of those work-around work in my scenario. I'm writing this const directly to EEPROM so using a LongInt would over-write data in another location. Using an integer value is also not ideal - for initial testing I'm using a whole number but I may need to tweak these defaults to us...
by SHughes_Fusion
Thu Oct 29, 2015 8:25 am
Forum: Compiler
Topic: Tips for optimising bank switching?
Replies: 27
Views: 10179

Re: Tips for optimising bank switching?

Thinking back, when I used to use the BKND compiler for the PIC12/16 series, that had the ability to specify which bank a particular variable was stored in. Does Swordfish offer a similar function? I guess that ideally the compiler would intelligently work out where to put variables to minimise bank...
by SHughes_Fusion
Wed Oct 28, 2015 4:42 pm
Forum: Compiler
Topic: Tips for optimising bank switching?
Replies: 27
Views: 10179

Tips for optimising bank switching?

The program I'm working on currently implements two serial buffers, one for receive and one for transmit. I was rather surprised when I increased the sizes from 16/64 bytes to 32/128 bytes that my code size also increased - by 133 words! After comparing the before and after .asm files it appears the...
by SHughes_Fusion
Wed Oct 28, 2015 1:32 pm
Forum: Compiler
Topic: Compiler Const bug?
Replies: 15
Views: 7058

Re: Compiler Const bug?

I wonder if the issue is something as simple as the fact the compiler is assuming any integer const will be negative and sets the MSB regardless? The fault persists even with a simple Const as Integer = 3.0 declaration yet Const as Integer = -3.0 works as expected. I've PM'd David, hopefully it is s...
by SHughes_Fusion
Wed Oct 28, 2015 10:34 am
Forum: Compiler
Topic: Compiler Const bug?
Replies: 15
Views: 7058

Re: Compiler Const bug?

I don't see where is the incorrect behaviour. If you want that compiler generate integer arithmetic, you need to tag your expression with correct type (this is what you have done using AS WORD). Erm... So you think if I use Public Const ReadyThreshold1 As Integer = 3.0 * TemperatureMultiplier and t...
by SHughes_Fusion
Wed Oct 28, 2015 10:17 am
Forum: Compiler
Topic: Compiler Const bug?
Replies: 15
Views: 7058

Re: Compiler Const bug?

I think you'll find that using unsigned types vs signed types almost always produces smaller code if you can get away with it. How about in mixed expressions? Some values need to be signed - basically, I'm re-writing a PID routine that previously used floats. It seems that any const which would res...
by SHughes_Fusion
Wed Oct 28, 2015 8:45 am
Forum: Compiler
Topic: Compiler Const bug?
Replies: 15
Views: 7058

Re: Compiler Const bug?

To follow up on this, I've tried declaring this as an integer, a word and with no specific type. All three options end up with different compiled size with the 'no declaration' option being the biggest by 6 bytes. This const is only used in one place - it is written to EEPROM as a 'default' configur...
by SHughes_Fusion
Wed Oct 28, 2015 7:55 am
Forum: Compiler
Topic: Compiler Const bug?
Replies: 15
Views: 7058

Re: Compiler Const bug?

ReadyThreshold1 is actually -32576... That's "192 with the MSB set", turning it into a negative number Drop the 'as integer' from the declaration and it works. It'll convert it to an int when it uses it. I'm not so confident to do that - from an earlier post you'll see that in a similar situation t...
by SHughes_Fusion
Tue Oct 27, 2015 4:20 pm
Forum: Compiler
Topic: Compiler Const bug?
Replies: 15
Views: 7058

Compiler Const bug?

I've found an oddity with consts in the compiler. Not sure if this is a bug or something that is counter-intuitive... If you enter the following code: Public Const TemperatureMultiplier = 64 // All temperatures are multiplied by 64 to allow the use of a signed integer rather than floats Public Const...
by SHughes_Fusion
Wed Oct 21, 2015 3:23 pm
Forum: Compiler
Topic: How to avoid rounding errors when outputting floats?
Replies: 2
Views: 2294

Re: How to avoid rounding errors when outputting floats?

Maybe worth going to fixed point, I'll investigate. I actually only need 2dp, I'd gone to three to try and understand what was happening. I've found a sort of fix. If I add 0.006 that seems to give the expected results - after all, 123.125 should really output 123.13 if you are rounding to the neare...
by SHughes_Fusion
Mon Oct 19, 2015 8:31 am
Forum: Compiler
Topic: How to avoid rounding errors when outputting floats?
Replies: 2
Views: 2294

How to avoid rounding errors when outputting floats?

I'm hitting an issue when outputting a float that the result appears to be suffering from rounding errors. A value of 123.125 will output correctly, however, 123.12 will output as 123.119. I'm guessing this will be due to the way numbers are represented, but I'm wondering is there any way to avoid t...
by SHughes_Fusion
Fri Oct 16, 2015 1:37 pm
Forum: Compiler
Topic: Odd compiler behaviour
Replies: 2
Views: 2057

Re: Odd compiler behaviour

Thanks for trying, Jerry. All assumptions seem valid and your code compiles for me as well. It must be just one of those odd things - I couldn't find a way to replicate it without posting my whole code so I've done a work-around and moved the routine to copy the suffix in to a sub and that works fin...
by SHughes_Fusion
Fri Oct 16, 2015 11:03 am
Forum: Compiler
Topic: Odd compiler behaviour
Replies: 2
Views: 2057

Odd compiler behaviour

I've got two functions which do the same thing but on different data types: Sub SendData(Suffix As String, Data As Word) FTextAddress = @TStr // Initialise pointer to start of the string FTextIn = Suffix(0) // Put the suffix as the first characters FTextIn = Suffix(1) FTextIn = GH_ETB // Send end of...
by SHughes_Fusion
Mon Oct 05, 2015 8:39 am
Forum: Compiler
Topic: How are consts allocated a type?
Replies: 3
Views: 2558

Re: How are consts allocated a type?

Thanks, Jerry, that is all I could find as well. I can't easily post the full code and can't seem to replicate it by cutting it down. I think it must just be one of those cases where the compiler does something odd which isn't repeatable. This was a sort of 'compound' constant. I had one constant I'...