Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.
|
Forum Index : Microcontroller and PC projects : Defining constants in MMBasic
Author | Message | ||||
Greg Fordyce Senior Member Joined: 16/09/2011 Location: United KingdomPosts: 153 |
I am starting to port some PicBasic Pro code to the maximite for my electric vehicle battery management system. One thing that the pbp code uses is lots of constants for various operating parameters. Here's a snippet of the code MaxPackV con 18500 'Maximum pack voltage = 185v 50 Cells (18,500 as 16 bit value) Res 10mv (Max 650v)
AbsMaxCellV con 366 'Abs Maximum permitted cell voltage = (3.66V) (Alarm & Shutdown point) AbsMinCellV con 230 'Abs Minimum permitted cell voltage = (2.30V) (Alarm & Shutdown point) MaxCellV con 360 'Normal Maximum permitted cell voltage = (3.60V) (Charger/Regen cutback point) MinCellV con 240 'Normal Minimum permitted cell voltage = (2.40V) (Controller/Assist cutback point) Being a complied program the compiler simply inserts the values where appropriate when it generates the hex file. Having all the values in one place makes adapting the program for different battery packs much easier. Having looked at MMBasic manual and the GW-Basic book, I don't see any equivalant way of doing this. I am thinking I could just assign them as variables like this; 100 MaxPackV = 185 'Maximum pack voltage = 185v 50 Cells
which should work, but the nice thing about having them as constants is you can't accidentally change them with a programming error. The compiler just won't let you. Maybe some sort of way to lock variables in MMBasic could be implemented, or is there a way to do this that I am missing?
110 AbsMaxCellV = 3.66 'Abs Maximum permitted cell voltage = (3.66V) (Alarm & Shutdown point) 120 AbsMinCellV = 2.3 'Abs Minimum permitted cell voltage = (2.30V) (Alarm & Shutdown point) 130 MaxCellV = 3.6 'Normal Maximum permitted cell voltage = (3.60V) (Charger/Regen cutback point) 140 MinCellV = 2.4 'Normal Minimum permitted cell voltage = (2.40V) (Controller/Assist cutback point) Thanks, Greg. |
||||
CircuitGizmos Guru Joined: 08/09/2011 Location: United StatesPosts: 1425 |
I would imagine that in an interpreter that implementation of constants would use the same amount of RAM as variables. Micromites and Maximites! - Beginning Maximite |
||||
Greg Fordyce Senior Member Joined: 16/09/2011 Location: United KingdomPosts: 153 |
But that doesn't mean it wouldn't be useful. My goal is a "locked" variable that can't be changed inadvertently. Maybe I could use the READ and DATA statements to load the values into variables and then periodical check that they match and report an error if they don't. |
||||
Xiongmao Regular Member Joined: 25/08/2011 Location: AustraliaPosts: 48 |
You could keep the constants in a separate file on the SD card. Open file, read contents, close file. This also has the advantage of keeping multiple sets of constants (multiple files) on hand to choose between. |
||||
Greg Fordyce Senior Member Joined: 16/09/2011 Location: United KingdomPosts: 153 |
That's a good idea, I could even write a SETUP.BAS program to generate the file after asking some questions. |
||||
Print this page |