![]() |
Forum Index : Microcontroller and PC projects : Help needed with Appliance Energy Meter
Author | Message | ||||
WhiteWizzard Guru ![]() Joined: 05/04/2013 Location: United KingdomPosts: 2944 |
Is anyone out there using the Appliance Energy Meter Project that has been featured in both SC magazine and also EPE magazine? It is a three-part project by Jim Rowe and Nicholas Vinen. Part 1 was in the July 2018 edition of EPE (I don't know what the SC edition was). A good customer has raised an issue with me that has now gotten me involved in wanting to fix things for him. I am able to re-create the issue he is seeing. Initially we had a problem with a variable named 'SUB' in the library code. ![]() Anyway, our current issue is concerning the fact that the code is still failing to run properly on MMBASIC v5.05.01. Sure the program starts up, we see things on the TFT, but then we get the following error message after a few seconds: [104] Local mins$ LENGTH 5 = LPAD0$(Str$(minutes),2) + ":" + secs$ Error: Not enough memory Obviously an earlier version of MMBASIC was around when the project first appeared. Rather than install the .hex file (with an out-of-date version of MMBASIC) we have installed the Library .bas file (crunching it first with MMEDIT), and then the Main Program (also crunched) after initially installing MMBASIC v5.05.01. I have hooked up an RTC to a BackPack (v2); no main board connected. I tried adding a debug line but then got a load of CPU exception errors on the MM and it basically needed reloading. Is this a sign that the memory is virtually 100% full? Is anyone successfully running this project on a version of MMBASIC that is reasonably recent? I have assumed that it all runs properly if I load the .hex (will try that next just to check!!) Any feedback, clues, or things to try, would be appreciated. ![]() WW |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6283 |
try Local mins$ LENGTH 5 mins$ = LPAD0$(Str$(minutes),2) + ":" + secs$ Jim VK7JH MMedit |
||||
CaptainBoing![]() Guru ![]() Joined: 07/09/2016 Location: United KingdomPosts: 2170 |
to simplify things a bit, forget the LENGTH 5 bit. Geoff mentioned in a post a while back that although supported on simple strings, LENGTH x is ignored - it only takes effect for string arrays. All simple strings default to 255 bytes. |
||||
WhiteWizzard Guru ![]() Joined: 05/04/2013 Location: United KingdomPosts: 2944 |
Hi Jim, Thanks for your idea. I tried it, but ANY change to the Main Program seems to result in the error: CPU exception *7 This then means I have to start all over again so it is taking ages to try eliminate things ![]() Will keep trying things . . . |
||||
panky![]() Guru ![]() Joined: 02/10/2012 Location: AustraliaPosts: 1114 |
WW, Have a look at this - I think the closing bracket is in the wrong place ' your code LPAD0$(Str$(minutes),2) ' I think should be LPAD0$(Str$(minutes,2)) Without the whole program it is a bit hard to determine where the error might be. Does MEMORY give you any indications that you are running out of space? panky ... almost all of the Maximites, the MicromMites, the MM Extremes, the ArmMites, the PicoMite and loving it! |
||||
Turbo46![]() Guru ![]() Joined: 24/12/2017 Location: AustraliaPosts: 1642 |
WW, The articles were in August/September/October 2016 Silicon Chip. They say the MMBasic version is V5.1, I see it is on Geoff's archive page. Why not use the .Hex file if it works? They do say that they had to crunch the library and the program files as you have done to get it to fit - so memory must be very tight. Perhaps later versions of MMBasic have less room for programs? Bill PS. I see there is a series of articles featuring the Micromite coming up in EPE soon but I think you may know more about that. Keep safe. Live long and prosper. |
||||
disco4now![]() Guru ![]() Joined: 18/12/2014 Location: AustraliaPosts: 1003 |
I have downloaded the software from the silicon chip website. I can see a couple of ways to reduce the code size. Not sure if this will solve the memory thing. using MMBasic 5.05.01 1. The ability to add incrementally to the library will now allow the second CFunction to be added to the library after the current library stuff is added. Just take it out of the main code and load it separately and do a LIBRARY SAVE. 2. Just replacing some often used long variable name with short versions as below save 2K and ends up leaving 15% free in lieu of 11%. Loading the CFunction into the library also saves some but I didnt do a before and after. #REPLACE logging_status ls #REPLACE log_interval li #REPLACE log_duration ld #REPLACE eeprom_address ea #REPLACE num_datum nd #REPLACE zero_crossings zc #REPLACE accum_cost_mc acm #REPLACE tariffs ts #REPLACE touchpos tp #REPLACE graph_duration gd #REPLACE count ct The link below is to the utility I use to allow replacement at load time so your code is still readable with long names, but is truncated when loaded to save memory. #Replace directive I don't have the hardware so don't know if it is really working, but I don't get the out of memory error. Latest F4 Latest H7 FotS |
||||
WhiteWizzard Guru ![]() Joined: 05/04/2013 Location: United KingdomPosts: 2944 |
OK - some progress (of sorts!). No matter what I try with v5.05.01, I simply cannot get past the 'Not Enough Memory' error. Not sure if it is uncovering a peculiar bug - or whether it is on the boundary of available memory. I can 'force' the relevant strings to a fixed value (at the point where the code fails) and everything continues. As soon as I revert back to letting the Function being called (that sets the string) then I get the message. Have brought the Function from the Library and put it into Main Prog (to make it easier to debug the issue). Added debug Print statement and all seems ok. Re-named Function just in case it didn't like ending in a numeric; but nothing obvious seemed to work. SO; I reverted back to v5.1 (ThanKs Turbo46 for confirming version) and reloaded Library and Main. Everything works as expected. ![]() So I will email the Authors of this project and see if they can enlighten me further as to why the program fails on the latest MMBASIC. Thanks for your replies that helped me keep going with this annoying issue . . . . ![]() |
||||
Turbo46![]() Guru ![]() Joined: 24/12/2017 Location: AustraliaPosts: 1642 |
WW, I had a peep at the program and it does seem a little bit unusual to me. all of the SUBs and FUNCTIONS are defined at the beginning of the program and the main program starts at line 1173. I guess that's OK. But then at line 1189 there is a SUB defined in the middle of the code? Maybe that should be moved? Bill Keep safe. Live long and prosper. |
||||
WhiteWizzard Guru ![]() Joined: 05/04/2013 Location: United KingdomPosts: 2944 |
@Turbo46 This code from the Library .bas file confused me initilally: FUNCTION PRINTW$(val, NUM) LOCAL INTEGER SUB = 0, EXTRA = 0 IF VAL < 100 THEN SUB = 1 IF VAL < 10 THEN SUB = 2 IF SUB = 0 THEN EXTRA = 1 PRINTW$ = STR$(VAL, NUM-SUB+EXTRA, SUB) END FUNCTION In the 80s (i.e. my days spent learning BASIC on Home Computers), it was drilled into me to ensure to never use variable names which were the same as reserved 'keywords' (i.e. not to use command names for my variable names). This seems so obvious to me. But when I saw the above; I could see immediately why this part of the code failed with MMBASIC v5.05.01. Rather than spend any more time on this one, I will email the authors; after all, I am busy writing the new 'Make it with Micromite' series for EPE magazine. ![]() |
||||
Elybee Newbie ![]() Joined: 17/01/2019 Location: BelgiumPosts: 5 |
Touchscreen Appliance Energy Meter. (EPE july,aug,sept) Bill of materials, Programming The Yunpen EMI filter "YF10T6" doesn't fit on the pcb Board. So i made a small adapter, so i could turn the emi filter 90 degrees. Be sure the line qnd loqd is on the right side. It should be the "YF10T8" i think. The distance between the "load" pins from the “YF10T8” is 7.5 mm witch is ok. You can find the Physical Dimensions(mm) here : http://www.yunpen.com.tw/en/product/PC-Board-Mounting-Filters-YF-T8/PC-Board-Mounting-Filters_YF-T8.html (scroll down and download the pdf file ) The Touchscreen Appliance Energy Meter works fine with me, however i had some problems programming the firmware MMBASIC Micromite_V5.05.01.hex to the MIcromite (with pickit3). After loading SCAppEnergyMeter_Library v1.01.bas and the SCAppEnergyMeter_Main v1.01.bas with the program MMedit, i got nothing sensible on my touchscreen. So I reprogrammed the MM with a former version MMBASIC “ Micromite_5.1.hex” witch you can download from http://geoffg.net/Downloads/Micromite/Archives/. (Micromite_5.1.zip) I also changed some of the code in SCAppEnergyMeter_Main v1.01.bas. FUNCTION PRINTW$(val, NUM) LOCAL INTEGER SUB = 0, EXTRA = 0 IF VAL < 100 THEN SUB = 1 IF VAL < 10 THEN SUB = 2 IF SUB = 0 THEN EXTRA = 1 PRINTW$ = STR$(VAL, NUM-SUB+EXTRA, SUB) END FUNCTION INTO FUNCTION PRINTW$(val, NUM) LOCAL INTEGER wwSUB = 0, EXTRA = 0 IF VAL < 100 THEN wwSUB = 1 IF VAL < 10 THEN wwSUB = 2 IF wwSUB = 0 THEN EXTRA = 1 PRINTW$ = STR$(VAL, NUM-wwSUB+EXTRA, wwSUB) END FUNCTION Everything works fine now !! My special thanks to WhiteWizzard who helped me solving my problems with this very cool project !! I build the meter also with IC 2 “LTC1867” instead of "LTC1863" wich works ok. Eli |
||||
lizby Guru ![]() Joined: 17/05/2016 Location: United StatesPosts: 3378 |
So was the whole of the problem the use of "SUB" as a variable, or is there some other difference between Micromite_5.1.hex and the current release that makes the code not work under 5.5.2 Beta? PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
Elybee Newbie ![]() Joined: 17/01/2019 Location: BelgiumPosts: 5 |
Both, With the "sub" code and firmware Micromite_5.5_1.hex, i only got the word "VAC" on my touchscreen. with "wwsub"" , I got the menu on my touchscreen , but the touching wasn't working properly. So after reprogramming with the older version 5.1_1.hex and the "wwsub"" my Appliance Energy Meter works fine. . |
||||
Elybee Newbie ![]() Joined: 17/01/2019 Location: BelgiumPosts: 5 |
Both, With the sub code and firmware Micromite_5.5_1.hex, i only got the word "VAC" on my touchscreen. with wwsub , I got the menu on my touchscreen , but the touching wasn't working properly. So after reprogramming with an older version 5.1_1.hex and the "wwsub"" my Appliance Energy Meter works fine. |
||||
Elybee Newbie ![]() Joined: 17/01/2019 Location: BelgiumPosts: 5 |
Both, With the sub code and firmware Micromite_5.5_1.hex, i only got the word "VAC" on my touchscreen. with wwsub , I got the menu on my touchscreen , but the touching wasn't working properly. So after reprogramming with an older version 5.1_1.hex and the "wwsub"" my Appliance Energy Meter works fine. |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |