Programming stuff and Microcontroller stuff

Ok, first question: Is it possible to have a program use a different/more header files than the default UserAPI.h?

Second: Without using more/new header files is it possible to use Trigonometric functions (Sin, Cos, Tan)?

Third: How much memory does the microcontroller have? Got it

Fourth (sort of along with third): How many variables can the microcontroller hold? Got it, but don’t quite understand the specs.

Fifth: How does the optical shaft encoder send feedback? I’ve been getting mixed info some saying that there are 90 holes and the value returned is the number of holes moved. Some has said that the value returned is degrees.

Thanks for any help,
Matt

This would be for Easy C, 1.x , 2.x, or 3.x??

Remember that EasyC is just a Drag and Drop User Interface, that creates a “proper” ‘C’ source Code file and Header File that is “compiled and linked” by the mcc18 compiler using a “makefile”.

I have not tried this yet, So MAKE BACKUPS!!!

It appears that the UserAPI.h is “Hard Coded” into the Easy C Project for EasyC 1.x. and IIRC EasyC 2.x. Not sure about EasyC 3.x (Pro Version). But, the UserAPI.h is just a regular “.h” file, it should be possible to ADD definitions to it, or better yet, Add “#includes” to it that have your custom definitions in it…

Possibly… (Also, Floating Point math on the PIC Processor is REAL SLOW, be very careful, you might get your Vex Controller “running” TOO SLOW)
Sin, Cos, Tan are defined in the math.h file, (in the “h” directory under the mcc18 compiler) and in the library’s clib.lib, clib_e.lib and each of the Micro-Chip specific libraries (in the “lib” directory under the mcc18 compiler)… Depending on how the Linker works, the compiler might complain about not knowing the Definitions of Sin, Cos, Tan etc…, but the Linker still might be able to Resolve the entries in the Libraries and create a “final” output file… Of course, if you have the parameters wrong in the call to Sin, Cos, Tan etc… without the Definitions for the compiler to check, you might get some very strange results…

I would BACK UP, then Edit the UserAPI.h file with “#include <math.h>” right after the “#define user_api_h” line. UserAPI.h is located the “Intelitek\easyC\VeX\UserAPI” directory. IF, the Include files are done CORRECTLY, they will add Nothing to the size of your executable program, unless you “make a call” to a function defined in the Include File or create an Instance of a Data Type from the Include File.

For those who want to know:
Variable Space 1800 bytes + 1024 bytes EE2
Program Space 32K
(from Vex Robotics Design System - Vex Micro Controller Specifications)

Like a lot of life’s answers, It Depends…
First, the Program Space is 32,768 WORDS (16 bits for each word). All your Program Code and STATIC Variables should go in this memory.

Second, 1800 bytes (8 bits per byte) are the RAM, but IIRC some is “reserved” for the Machine “stack”.
The Depends part is CHARs take a Byte, INTEGERs take Two Bytes, SHORT LONGs are 3 Bytes, and LONGs are 4 Bytes. FLOATs (and DOUBLEs) take Four Bytes. (From the MPLAB_C18_Users_Guide_51288j.pdf, PDF page 19, Document page 11) (Also note that EasyC does not let you use all of these types) So the more LONGs and FLOATs you use in your program, the fewer total variables you can have.
(Rules of Thumb: Always use the SMALLEST variable you can get by with, if your loop is 0 to 50, use a Unsigned Char)

Third, The RAM is lost (returns to an unknown state) on power loss, but you can keep upto 1024 Bytes of data stored in the Electronically Erasable, Programmable Read-Only Memory (EEPROM or EE2), so if you run “short” of RAM space, you might be able to use the EEPROM, for storage of STATIC VALUES, you should be able to have the values placed into the main Flash… EEPROM is usually slower to access than the RAM, so there might be a Speed Penalty in your program…

Physically, It connects to the Interrupt bank of the Vex Controller. Logically, both are True! There are 90 Holes in the full 360 Degrees. So 45 Holes would be 180 Degrees and 22-23 Holes would be 90 Degrees…
(from the Inventors Guide for the Vex Robotics Optical Shaft Encoder Kit

Your welcome…

Thankyou very much!
Now I got another zinger for anyone willing to help. Is it possible to create variables on the fly? Such as I receive data from a sensor, which the program then passes along to a new variable it creates, then “stores” it.
Thanks again for any help provided!
Matt

I think you need to have already declared the variable.

Within some limits… Yes, you can… They would be called Local Variables, and can be declared at the Beginning of a block and are destroyed automatically at the end of the the block they are declared in.

Background:
With EasyC 1.x, ALL the EasyC variables are Global Variables
(declared outside the main() function). EasyC 2.x declares them inside the main() function as Local Variables. Using the “User Code” item of the Program Flow under EasyC 1.x, you can add your own ‘C’ Code, but EasyC CAN NOT help you trouble shoot the “User Code” entries.

The best that I can tell about the mcc18 compiler is that it is ANSI compliant, but at the ANSI ISO C89/C90 level, which means that all new variables that are declared, must be done immediately after the beginning of the block. (ANSI ISO C99 and ANSI ISO C++98 don’t have this restriction)

So THIS works… (Example #1)

#include "UserAPI.h"

int test_1 = 0; // EasyC Variable

void main ( void )
{
      while ( 1 )
      {
            auto int foobar=0; // 'User Code' Variable
            test_1 = 27 ;
            foobar = 43 ;
      }
}

And THIS Does Not… (Example #2)

#include "UserAPI.h"

int test_1 = 0; // EasyC Variable

void main ( void )
{
      while ( 1 )
      {
            test_1 = 27 ;
            auto int foobar=0; // 'User Code' Variable
            foobar = 43 ;
      }
}

Because the variable “foobar” is declared at the beginning of the while(1), its scope is to the end brace of the while(1), but no further, if you were to break out of the while(1), the variable “foobar” would then be destroyed, before the end of the program was reached…

(Example #1 is attached, so you can see how the “User Code” item is used)
20070423_MattW_001.zip (1.23 KB)

I’m sorry, I forgot to say thanks. I’ll definately look at it and give it a shot.
Thanks again for all help,
Matt