Easy way to spot double scripts or anything to reduce program size easily?

Started by Amateurtje, Jul 09, 2023, 11:14 PM

Previous topic - Next topic

Amateurtje

Hello All,

While I am running out of program space on my 18F46k22 I am asking this question. I suspect that because I am building already a long time on a certain program, it is probably not the most efficient script anymore and maybe even there might be some repetative scripts.

Is there any function in the proton IDE (or others) or in the compiler to recognise this? or even some recognition of repeating scripts during compiling.. Or any other way to easily clean scripts?

Declare Optimiser_Level = 3 is already some time above my program..

Any good ideas?

tumbleweed

I think you're stuck looking through your code and trying to find repetitive code that you can turn into procedures. You have to watch though since this can actually add MORE code if you're not careful.

Usually you can optimize your code yourself by looking at the asm output. You may find some statements that generate a LOT of code that can be reduced by simplifying things, breaking up complex statements, etc. It may make the source code larger, but it can also make code generation easier on the compiler.

If you need a larger device, probably the closest one peripheral-wise to an 18F46K22 would be an 18F47Q10. That'll get you twice the flash (128K), but a little less RAM (K22=3896 bytes, Q10=3359). If you need more RAM there's always the 18F47Q43, but that one has some real differences (like the MSSP has been replaced with separate I2C/SPI peripherals, so if you're using I2C you'd probably have to do it in software). It has some other nice features though.




Amateurtje

Hi Tumbleweed,

Thanks for the answer. That will probably be a big ASM,. I normally never look at that...

While I need more space but also minimum 1 extra Serial port, I could not find a supported chip that meets these requirements.. Therefore I actually selected another chip, the 47Q84. That has more program space and the serial ports but that will take some time before I can use it. Therefore I am looking to try at least to improve my software in the existing chip....

MAybe the 18F47Q43 is a good inbetween chip. I will checp if it is a drop-in chip as the QFN44, while my pcb is designed for that.

Greetz

tumbleweed

I imagine the asm is big, but if you take the time to look you may see some statements that generate a LOT of code... things like array accesses, complex statements, etc. You can usually do a good job of helping the compiler out, and that can make a big difference. Things like arrays can be very expensive in terms of code size, especially if there are a lot of repetitive statements.

There are no device files for the Q83/Q84 except for the 18F27Q84, and that can't be used with Proton... MPASM crashes when you try to assemble for that device. It needs a different assembler (or compiler).
 
The 47Q43 has 5 UARTS and should be pin-compatible with the K22 from what I recall... most of them are. You'll also get twice the RAM (8K)

Amateurtje

I do not know why I missed this chip but it seems to solve a lot of my problems, And is supported at the moment by Positron... That is interesting.. Now the challenge is to get some  :) ..

Let's be honest, it is nicer to build than to shave.... ;D  ;D

Thanks.

trastikata

PIC18F46K22 has 64k memory, which is quite a lot for "normal" program.

Is it strings and/or graphics in your program that take so much FLASH?

Do you have free RAM, it could be used in some cases to free memory space.

Amateurtje

I do not have a big amount of RAM free.




I do have some text for on the display but there is not a lot of strings or graphics... There are some byte arrays for sending and receiving data..

tumbleweed

QuoteNow the challenge is to get some
I see some stock of the PIC18F47Q43-I/MP (QFN) at Newark, Avnet, and Mouser. Not a lot, but some.
Microchip Direct have more coming in Aug.

Amateurtje

I checked mouser and did not see but I am going to check again.. Will Avnet or Newark have originals (and deliver in europe).. I have had some very negative experiences with imitation chips so I am always hesative if it is not an original/official microchip sales point..

PS, Sorry, Sorry, I need the Tqfn44...
PIC18F47Q43-E/PT is what I normally buy but the PIC18F47Q43-I/PT would also be oke for now..

tumbleweed

They're all approved Microchip distributors, but I don't see any stock of the TQFP (PT) parts anywhere, just the QFN (MP) package.

MicrochipDirect doesn't show any coming anytime soon...


Amateurtje

I saw in octoparts that all original approved suppliers had 0 stock, and long leadtimes... Therefore my worries.

Paying 15 to 20 dollar for chineese imitation does not feel right but it looks like that is my only way....


I assume I can get nobody as crazy here to buy a complete tray of PIC18F47Q84-E/PT from me :)

trastikata

Is the board ready? Can't you opt for 16-bit devices, most are still available (last time I checked) and offer enough memory, or the bigger 67k22 ?

Amateurtje

the board is ready.. it is just an evalution on an existing project.. so a drop-in chip is for sure preferred. I also need at least 3 uarts.and, last but not least, I do not like going smaller pitch than a TQF44.. that still solder easily but smaller is a bit a Pa@$ i@  th# #!.. ;)  ;D

PS, I might have 3 chips coming to me in a couple of weeks through a friend. with that, I can at least start writing the code..