Understanding the startup code

Thanks all for the great help. Here’s what we did this past few days.

(1) My son Alex fully assembled the robot kit according to all of the instructions and it worked perfectly the first time!!

(2) We learned how to download new firmware to the robot and run it.

(3) We learned how to rebuild source code using the MPLAB software and download it to the robot.

(4) We managed to modify the software to detect all of the various buttons and controls available on the wirleless transmitter. This was fun to do. We learned how to add ‘printf’ statements to see that our code changes were running as we expected.

So, here is where we are stuck. Now that we know how to read the inputs we would like to change how the outputs work. However, we have searched and searched the sample source code and cannot find the code which controls the motors!???

Obviously the motors are working since we can still drive the robot around.

Where can we learn about sending signals to the motor outputs?

One of my concerns with the source code is that, even though it has comments, it assumes that the reader already knows what a whole bunch of acronyms mean.


“/* EIGHTH: Set your PWM output type. Only applies if USER controls PWM 1, 2, 3, or 4. */”

This seems to assume the reader know what a ‘PWM’ is, or how to use it? What does PWM stand for? Where is the documentation that explains what all of these acronyms mean?

There is another comment that reads:

/* SEVENTH: Choose which processor will control which PWM outputs. */

Followed by the line of code:


I really don’t know what this means. What is meant by ‘processor’. What is ‘IFI_PWM’?

I searched all of the code for words like ‘servo’ or ‘motor’ and nothing in the source refers to this.

My questions are as follows:

(1) Where in the provided source is the the code that takes the inputs from the transmitter and sends outputs to the motors?

(2) Is that code not provided? (It appears not to be, in which case how do you provide your own?)

(3) Where is the documentation for all of these acronyms so the beginning programmer can know what all of these things mean? It was easy enough to find the piece of code that processes all of the inputs and, with printf statements, we could reverse engineer which inputs corresponded to which controls on the transmitter. However, where is the documentation we could have read ahead of time about this?

Thanks, we are getting closer all of the time. My first thought was that the provided sample code would contain all of the source for controlling the robot and then we could just start modifying it from there as we learned more. However, even though we have found where all of the inputs can be processed, we can’t seem to find the code that controls sending outputs to the motors and such.

Any help, links, sample code, are appreciated.


John & Alex

Ok, as a follow up to my previous message.

Here is what we just learned how to do. We learned how to completely disable the transmitter by switching from ‘MASTER’ to ‘USER’.

In ‘user_routines.c’ we found this section of code:

Example: The following would generate a 40KHz PWM with a 50% duty cycle
on the CCP2 pin (PWM OUT 1):

CCP2CON = 0x3C;
PR2 = 0xF9;
CCPR2L = 0x7F;
T2CON = 0;
T2CONbits.TMR2ON = 1;

If we uncomment it out and change everything to ‘USER’ then the wireless controller stops working.

Great, this leads to a wide range of questions.

(1) Where is the source code to the logic that runs when ‘MASTER’ is set to true? Is this in firmware and we don’t have the source?

(2) What is ‘CCP2CON’ and why are we setting it to 0x3C? (No documentation)
(3) What is ‘PR2’ and why are we setting it to 0xF9?
(4) What is CCPR2L and why are we setting it to ‘0x7F’?
(5) What is ‘TTCON’ and why are we setting it to 0?
(6) What is ‘T2CONbits.TMR2ON’ and why are we setting it to zero?

I feel like I’m really missing an important step here. Why isn’t the code documented sufficiently to explain what all of these acronyms mean? Especially if this is the simple-sample framework provided for high-school students to get started for the very first time. Is the description contained in a separate document that I haven’t read/found yet?

Where is a framework that provides the C source that automatically controls the ‘user’ outputs translating the inputs from the transmitter to the outputs for the motors?

To give you a frame of reference, I have been programming computers for 30 years, much of that in assembly language, as well as C and C++. I have written a number of best selling computer games as well.

So, I am not struggling with the coding itself, but rather finding the reference information to know what all of the highly specific and targeted semantics mean in context to programming this specific device.

I purchased a number of programming books on the PIC controller but, of course, none of them deal with the semantics of the specifics of this particular robot configuration.

So far, each time I have asked a question your friendly neighborhood technical support person has directed me to a link to a piece of documentaiton I was missing.

However, in this case I can’t find sufficient documentation in the source code to answer these questions, and no PDF file or other documentation comes with the sample source download that explains what all of the acronym’s mean and how to use them.

I feel like I’m just missing one final vital clue and I can be driving the VEX under control of our own source code instead of the default configuration.

Much thanks,

John & Alex

The answer lies with Microchip. Go to www.microchip.com and download the data sheet for the PIC18F8520 micro-controller and the Motor Control related application notes since they include detailed descriptions of the PWM registers. PWM stands for Pulse Width Modulation and it is used to control the power to DC Motors and possibly RC Servos using special hardware registers on the PIC. PWM signals are also used for controlling switching power supplies.

IIRC, the DEFAULT code for the Motors is is the Master Code, which is only available as the .BIN file. VexLabs (AKA IFI Robotics) keeps the “code” Proprietary, since Vex is used for the USFIRST FTC Competitions.

Try the “IFI Documentation for 2004”, found on this page, Robotics - Legacy Documentation

The 2004-2005 IFI Robotics Controllers for USFIRST FRC uses the same Two Microchip PICmicro® PIC18F8520 Processors the Vex Controller uses, and is Programmed in PIC 18 ‘C’. The IFI Controller has more Outputs and Inputs available to the user, but the Concept is the same… Also you can learn more about the Vex Controller (and IFI Controller) at Chief Delphi’s Programming Forum.

File “user_routines.c”, lines 266-295

Some documentation is in the Header Files, “ifi_aliases.h”, “ifi_default.h” and the definitions of the PIC structures in “ifi_picdef.h”.

As Tswift1 mention, get the Microchip PICmicro® PIC18F8520 Processor Documentation and Microchip PICmicro® PIC18F6520/8520 Rev. A1 Silicon/Data Sheet Errata.

Also Vex Controller Info is here, http://www.vexlabs.com/vex-robotics-design-system.shtml.