Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 05:01 24 Nov 2024 Privacy Policy
Jump to

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 Kingdom
Posts: 153
Posted: 05:07pm 30 Sep 2011
Copy link to clipboard 
Print this post

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

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)
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?

Thanks, Greg.
 
CircuitGizmos

Guru

Joined: 08/09/2011
Location: United States
Posts: 1425
Posted: 06:52pm 30 Sep 2011
Copy link to clipboard 
Print this post

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 Kingdom
Posts: 153
Posted: 09:58pm 30 Sep 2011
Copy link to clipboard 
Print this post

  CircuitGizmos said   I would imagine that in an interpreter that implementation of constants would use the same amount of RAM as variables.


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: Australia
Posts: 48
Posted: 10:29pm 30 Sep 2011
Copy link to clipboard 
Print this post

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 Kingdom
Posts: 153
Posted: 10:44pm 30 Sep 2011
Copy link to clipboard 
Print this post

That's a good idea, I could even write a SETUP.BAS program to generate the file after asking some questions.
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024