|
Forum Index : Microcontroller and PC projects : psram gone help if run out of Heap memory
| Author | Message | ||||
| tenij000 Senior Member Joined: 30/05/2025 Location: NetherlandsPosts: 105 |
was gone try to add text for cells but then i run out of Heap memory ' ============================================================ ' PICO-SPREADSHEET V1.7 (FULL VERSION) ' ============================================================ ' Functies: Auto-Grid, Formulegeheugen, Save/Load, Anti-Crash ' ============================================================ CLS DIM cells(26, 20) DIM formulas$(26, 20) fileName$ = "spreadsheet.csv" ' Startscherm met raster GOSUB ShowGrid DO ' De input verschijnt altijd onder het raster INPUT "Opdracht: ", cmd$ cmd$ = UCASE$(cmd$) IF cmd$ = "EXIT" THEN END SELECT CASE cmd$ CASE "CLEAR" FOR r = 1 TO 20: FOR c = 1 TO 26 cells(c, r) = 0: formulas$(c, r) = "" NEXT c: NEXT r GOSUB ShowGrid PRINT ">> Alles gewist." CASE "SHOW" GOSUB ToonLijst CASE "SAVE" GOSUB OpslaanBestand GOSUB ShowGrid PRINT ">> Opgesl*gen in "; fileName$ CASE "LOAD" GOSUB LadenBestand RecalculateAll GOSUB ShowGrid PRINT ">> Bestand geladen." CASE "HELP" GOSUB ToonHelp CASE ELSE ' Standaard: Verwerk de formule en ververs het grid GOSUB VerwerkFormule GOSUB ShowGrid END SELECT LOOP ' --- RASTER WEERGAVE (MET SLIMME KLEUR-DETECTIE) --- ShowGrid: LOCAL col, row, cVal, cStr$, pad, f$, isFormule, i, charCode CLS ' Print de kolomletters (A t/m E) in geel COLOR RGB(YELLOW), RGB(BLACK) PRINT " "; FOR col = 1 TO 5 PRINT "| " + CHR$(64 + col) + " "; NEXT col PRINT "|" COLOR RGB(WHITE), RGB(BLACK) PRINT "------" + STRING$(60, "-") ' Loop door de rijen (1 t/m 10) FOR row = 1 TO 10 IF row < 10 THEN PRINT " "; PRINT STR$(row) + " "; FOR col = 1 TO 5 cVal = cells(col, row) cStr$ = CleanString$(STR$(cVal)) f$ = formulas$(col, row) isFormule = 0 ' --- CHECK: Is dit een berekening of verwijzing? --- ' 1. Check op wiskundige tekens IF INSTR(f$, "+") > 0 OR INSTR(f$,"-") > 0 OR INSTR(f$,"*") > 0 OR INSTR(f$,"/") > 0 THEN isFormule = 1 ENDIF ' 2. Check op letters (celverwijzingen zoals A1, B2) FOR i = 1 TO LEN(f$) charCode = ASC(MID$(f$, i, 1)) IF charCode >= 65 AND charCode <= 90 THEN isFormule = 1 NEXT i ' Teken de cel-afscheiding in wit COLOR RGB(WHITE), RGB(BLACK) PRINT "| "; ' Bepaal de kleur van de waarde IF isFormule = 1 THEN COLOR RGB(CYAN), RGB(BLACK) ' Formules/Sommen in Cyaan ELSE COLOR RGB(WHITE), RGB(BLACK) ' Gewone getallen in Wit ENDIF PRINT cStr$; ' Vul de rest van de kolombreedte op met spaties (in wit) COLOR RGB(WHITE), RGB(BLACK) pad = 10 - LEN(cStr$) IF pad > 0 THEN PRINT STRING$(pad, " "); NEXT col COLOR RGB(WHITE), RGB(BLACK) PRINT "|" NEXT row PRINT "------" + STRING$(60, "-") PRINT "Typ HELP voor info. Opdracht (bijv. A1=B1+5):" RETURN ' --- SUBROUTINES --- ToonLijst: PRINT "--- ACTIEVE FORMULES ---" LOCAL fnd, rL, cL fnd = 0 FOR rL = 1 TO 20: FOR cL = 1 TO 26 IF formulas$(cL, rL) <> "" THEN PRINT CHR$(64 + cL); rL; " = "; formulas$(cL, rL) fnd = 1 ENDIF NEXT cL: NEXT rL IF fnd = 0 THEN PRINT "(Geen formules gevonden)" RETURN ToonHelp: PRINT "--- HELP OVERZICHT ---" PRINT "A1=10 : Getal invoeren" PRINT "B1=A1*2.5 : Formule invoeren" PRINT "SHOW : Lijst met alle formules" PRINT "SAVE / LOAD : Bestand op de Pico opslaan/laden" PRINT "CLEAR : Alles wissen" PRINT "EXIT : Programma stoppen" PRINT "Druk op Enter om terug te gaan..." INPUT dummy$ GOSUB ShowGrid RETURN VerwerkFormule: LOCAL pPos, tR$, fR$, t$, f$, cX, rY pPos = INSTR(cmd$, "=") IF pPos > 0 THEN tR$ = LEFT$(cmd$, pPos - 1): fR$ = MID$(cmd$, pPos + 1) t$ = CleanString$(tR$): f$ = CleanString$(fR$) ' Controleer op zelf-verwijzing IF INSTR(f$, t$) > 0 THEN PRINT "!! Fout: Circulaire referentie!" PAUSE 2000 ELSE ' Adres bepalen cX = ASC(LEFT$(t$, 1)) - 64 rY = VAL(MID$(t$, 2)) IF cX > 0 AND cX < 27 AND rY > 0 AND rY < 21 THEN formulas$(cX, rY) = f$ RecalculateAll ELSE PRINT "!! Fout: Ongeldig cel-adres!" PAUSE 1500 ENDIF ENDIF ENDIF RETURN OpslaanBestand: OPEN fileName$ FOR OUTPUT AS #1 LOCAL rS, cS FOR rS = 1 TO 20: FOR cS = 1 TO 26 IF formulas$(cS, rS) <> "" THEN PRINT #1, CHR$(64 + cS); rS; ","; formulas$(cS, rS) ENDIF NEXT cS: NEXT rS CLOSE #1 RETURN LadenBestand: LOCAL rD, cD, kommaPos, rgl$, cl$, fr$ ' Wissen voor het laden FOR rD = 1 TO 20: FOR cD = 1 TO 26: formulas$(cD, rD) = "": NEXT cD: NEXT rD OPEN fileName$ FOR INPUT AS #1 DO WHILE NOT EOF(#1) LINE INPUT #1, rgl$ kommaPos = INSTR(rgl$, ",") IF kommaPos > 0 THEN cl$ = LEFT$(rgl$, kommaPos - 1): fr$ = MID$(rgl$, kommaPos + 1) cX = ASC(LEFT$(cl$, 1)) - 64: rY = VAL(MID$(cl$, 2)) formulas$(cX, rY) = fr$ ENDIF LOOP CLOSE #1 RETURN ' --- REKEN ENGINE (SUB & FUNCTIONS) --- SUB RecalculateAll LOCAL c, r, fStr$, fV$ ' Twee passes om kettingreacties (C=B, B=A) op te vangen FOR pass = 1 TO 2 FOR r = 1 TO 20: FOR c = 1 TO 26 fStr$ = formulas$(c, r) IF fStr$ <> "" THEN fV$ = ParseFormula$(fStr$) cells(c, r) = EVAL(fV$) ENDIF NEXT c: NEXT r NEXT pass END SUB FUNCTION CleanString$(in$) LOCAL i, ch$, rs$ rs$ = "" FOR i = 1 TO LEN(in$): ch$ = MID$(in$, i, 1) IF ch$ <> " " THEN rs$ = rs$ + ch$ NEXT i CleanString$ = rs$ END FUNCTION FUNCTION ParseFormula$(f$) LOCAL c, r, cn$, oStr$, vStr$ oStr$ = f$ ' Terugwaarts zoeken voorkomt dat A10 wordt gezien als A1 + "0" FOR c = 26 TO 1 STEP -1: FOR r = 20 TO 1 STEP -1 cn$ = CHR$(64 + c) + CleanString$(STR$(r)) IF INSTR(oStr$, cn$) > 0 THEN vStr$ = STR$(cells(c, r)) oStr$ = ReplaceCell$(oStr$, cn$, vStr$) ENDIF NEXT r: NEXT c ParseFormula$ = oStr$ END FUNCTION FUNCTION ReplaceCell$(br$, ou$, ni$) LOCAL p, res$ res$ = br$: p = INSTR(res$, ou$) DO WHILE p > 0 res$ = LEFT$(res$, p - 1) + ni$ + MID$(res$, p + LEN(ou$)) p = INSTR(res$, ou$) LOOP ReplaceCell$ = res$ END FUNCTION some times on the internet i see pico whit this 16mb extra memmory that gone help |
||||
| lizby Guru Joined: 17/05/2016 Location: United StatesPosts: 3742 |
Peter and others have said that PSRAM will help with heap issues. I am awaiting gear to test. Meanwhile, there's this statement: DIM formulas$(26, 20) String arrays allocate 255 bytes per element. You can free up lots of heap by adding LENGTH. For instance: DIM formulas$(26, 20) LENGTH 20 (or whatever length is appropriate) Strings which are not arrays also allocate 255 bytes, but Peter found a way to alleviate that for strings less than 8 bytes, so Dim SomeShortString$="Example" Length 7 will save you 148 bytes. Edited 2026-03-15 02:25 by lizby PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on FOTS |
||||
| tenij000 Senior Member Joined: 30/05/2025 Location: NetherlandsPosts: 105 |
WeAct RP2350A_V20 Completely replace the original PICO2 Raspberry Pi RP2350 RISC-V Hazard3 520KByte SRAM 4or16MByte QSPI Flas maby this can work like 8euro |
||||
| lizby Guru Joined: 17/05/2016 Location: United StatesPosts: 3742 |
I had thought that module might work, but Mixtes90 pointed out that the QSPI memory is flash, not PSRAM. Have you tried putting LENGTH on your string array? PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on FOTS |
||||
| Mixtel90 Guru Joined: 05/10/2019 Location: United KingdomPosts: 8769 |
Note: It doesn't have PSRAM. It's a "look alike" Pico 2 but with the option of more flash. That will make A:/ bigger. If you want a module in the same footprint as a Pico 2 but with PSRAM then I think there's only the Pimorini Pico Plus 2, which costs appreciably more. There are other alternatives if you aren't looking for the same footprint. . Edited 2026-03-15 03:06 by Mixtel90 Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
| tenij000 Senior Member Joined: 30/05/2025 Location: NetherlandsPosts: 105 |
for now the program works whit out the LENGTH on string array for now works kind of line multiplan but gone thake look at that Pimoroni Pico Plus 2 |
||||
| lizby Guru Joined: 17/05/2016 Location: United StatesPosts: 3742 |
Glad you got it working, but if you didn't add a length to DIM formulas$(26, 20), you really should. DIM formulas$(26, 20) ' takes 26*20*255 characters -> 132,600 bytes But DIM formulas$(26, 20) LENGTH 31 ' takes 16,120 PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on FOTS |
||||
| The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2026 |