Menu

Programming

Christopher

Once you have assembled your boards you need to program them. To do so you will need the following:

  1. Hardware to interface to the circuit boards.
  2. MPLAB X IDE or something equivalent.
  3. A compiler.
  4. Some code.

Microchip (who make the PIC microcontrollers) will provide all of these, some of them for free to download. Check out www.microchip.com

The Hardware Interface
We used PICKit3 to interface to our boards. This is the one thing that you need to buy. The PICKit3 is a small, fairly inexpensive tool which plugs one end into a USB port on your computer and the other end into your circuit board. Check the Microchip website for the latest tool - they may have a newer version by now. You need something that will program the two microcontrollers we use, the PIC16F1827 and the PIC12F1822.

MPLAB X IDE
Microchip has created a comprehensive IDE (Integrated Development Environment) and give it away for free. An IDE is a program that takes everything you need to program a microcontroller and ties it up into a neat package.
The latest at the time of writing is MPLAB X IDE version 2.

Compiler
Different compilers are available for the PIC microcontrollers. I have only seen C compilers. You need to pick one based on the following:

  1. What code are you compiling? If you are starting from scratch then this doesn't matter. If you are using one of the examples available for download here then you need to check which compiler it was written for (should be in the readme file). Code can be adapted from one compiler to another, but it is easier to stick with the same one.
  2. How much do you want to pay? Free compilers are out there, usually stripped-down versions of paid-for compilers. The free versions don't produce as efficient code, but you probably don't need efficient code for this project.

Code
You can either start writing from scratch, or go along to the "files" page and find yourself some code. There are separate projects for the BMS Master and Module boards. Download a zip file, extract it and look through the readme file to see whether it does what you need.
At a minimum you will need to alter the voltage setpoints to suit your battery pack. You may also need to alter the values for the charger operation. And you will want to add some of your own features of course!

Putting it all Together
Here is an example of what I did. You may decide to use different tools.

  1. Build a PCB (either Master or Module) as per that page in this Wiki.
  2. Buy a PICKit3.
  3. Download MPLAB X from the Microchip website. I am using Linux, and there is a Linux version on the website which works nicely.
  4. Download a compiler - I chose the free version of XC8 from Microchip.
  5. Download one of the zip files of code from the files page of this project. Extract it to where you want it.
  6. MPLAB X Projects are entire directories ending in ".X". Open the project in MPLAB X.
  7. Learn how to use MPLAB X! It is quite complicated, but the documentation is good.
  8. Plug the PICKit3 into the computer and confirm that MPLAB X identifies it.
  9. Power your PCB and plug the PICKit3 into it. You will probably need to make a short cable to help you do this.
  10. If all has gone well then you should be able to "run" the code under MPLAB X. This compiles and downloads the code onto the microcontroller. MPLAB X also has some powerful debugging options.

A useful tool for programming lots of Module boards is the "Programmer to Go" mode in the PICKit3. When you choose this option in MPLAB X it will compile your program into the PICKit3. After that, every time you press the button on the PICKit3 it will program (and verify) any connected device. So you can go along with your PICKit3 programming each of the modules at a rate of about one every 15 seconds. You do need to power the PICKit3 for this mode via the USB connector, I found that a phone charger and a long USB cable worked quite nicely.


Related

Wiki: Home

MongoDB Logo MongoDB