BCI51 Sample Programs and Enhancements |
|
DPB2- and Secure Micro- Related BCI51 Files | Example and sample programs for DPB2. All are written in Systronix compiled BASIC, with I/O drivers in mixed BASIC and assembly code. Includes I/O drivers for all DPB2 peripherals. LCD, ADC, added UARTs and other drivers are here too. Most of these files can be easily modified for use on typical 8051 hardware, not just DPB2 systems. |
Constant Data Table (10 KB ZIP) | The most efficient way to create look-up tables of unchanging values such as waveforms or parameter tables. Click for a detailed description. |
32-bit math library (15 KB ZIP) | Click for description. |
Constant Data Table Example 96 Jun 7
Revised 96 Jun 26 to make the example much more readable and easy
to modify. This example is taken from a real-life, real-time and
mission-critical application. It's an assembly code data table,
with all functions called from BASIC. We used it to control the
profile of a multi-ton piston within a PID loop. We read the value
from the table and use it to load a 12-bit DAC which in turn controls
a servo valve connected to 750 hp of hydraulic pumps which drive
the pistons. You can use it for any situation where you need to
store a large amount of 8- or 16-bit constant data. The example
is simplified somewhat to keep the table size reasonable and make
the code easier to understand and modify. The example uses a simple
equation to generate the table. A worksheet (table1.wk1) is included
to show how to generate the data table from within a spreadsheet
program such as Quattro Pro, Lotus 123 or Excel. In an actual
application the table is probably not easily created by applying
an algorithm - if it were you could just use the algorithm to
generate the values on-the-fly at run time.
Tables are more appropriate when the data is too complex or random to generate algorithmically, or when the algorithm execution is too slow. The example includes a subroutine to initialize a pointer to the start of the table and a subroutine to step the pointer through the table forwards or backwards. There is also a routine to look for and point to a specific value in the table, or the closest value within a programmable range. You can have multiple pointers stepping through the table at different locations at the same time. The example supports two such pointers. The data table can be any size up to available memory. No absolute addresses are used, so it can reside anywhere in the 8051's available code memory space.
The "constant data" is actually stored in code space, which is appropriate since it won't change. This method is MUCH smaller, faster and more efficient than BASIC DATA/READ statements. We generated our equations in a spreadsheet, printed the values which we wanted to control the piston position to a text file, and then used a macro in our text editor to convert them to assembly code DW declarations. There are good comments in the files describing how to do all this.
Include File MATH32.INC and .BAS example program revised 96
Sep 05
Requires BCI51 Pro and willingness to use assembly code This file
includes an external library, MATH32.INC which provides 32-bit
unsigned integer math routines. This does NOT add 32-bit variables
to BCI51. It does provide 32-bit intermediate results which can
be stored in 32-bit working data areas and/or saved to 16-bit
BCI51 BASIC variables. The value of a 32-bit result can range
up to 4,294,967,296! BCI51's 16-bit unsigned integers can range
from 0-65535. For example, you can multiply two 16-bit integers
and get a 32-bit result. Then you can call additional 16- or 32-bit
math routines on that 32-bit result. You can save the low-, mid-
or high 16 bits of the 32-bit result to BCI51 BASIC variables.
So, what use is all this? One common application is in scaling 12- or 16-bit digital values such as from an analog-to-digital converter. You can add gain and offset using these routines. Typically, you will then scale the result back to 16 bits. You can also perform "pseudo-floating point math" using these routines. The example .BAS file shows how to do this. Suppose you are using a 12-bit ADC with a resulting reading of 0-FFF hex (0-4095 decimal). Suppose that this actually corresponds to a voltage range of 0-10 volts, and that you would like to display the voltage as 0-9.999 volts. You can do this by scaling the ADC reading and then treating the voltage as a whole and fractional part. If you multiply the ADC reading by 2442, you will have a value of 0-9,999,999 which is 10 volts mutliplied by a million. The example shows how to split0-9,999,999 into a whole and fractional part and display it as 0.000 to 9.999 volts.