Difference between revisions of "Setup AVR Development Environment"

From molecubes
Jump to navigation Jump to search
 
Line 1: Line 1:
This page will help you setup the programming environment for designing the low level firmware of individual Molecube actuators. After finalizing and compiling the actuator program, the resulting binary files will be transferred to the ATmega324P/644P processors embedded into the interface boards of the actuator Molecubes. These processors are responsible for physically executing commands issued by the controller Molecube, according to the list of commands given in the [http://molecubes.svn.sourceforge.net/viewvc/*checkout*/molecubes/trunk/specs/hardware_protocol_definition.xls hardware protocol definition] document.  
+
This page will help you setup the programming environment for designing the low level firmware of individual Molecube actuators. After finalizing and compiling the actuator program, the resulting binary files will be transferred to the ATmega324P/644P processors embedded into the interface boards of the actuator Molecubes. These processors are responsible for physically executing commands issued by the controller Molecube, according to the list of commands given in the [https://github.com/VictorZykov/molecubes/tree/master/specs/hardware_protocol_definition.xls hardware protocol definition] document.  
  
 
==Recommended Order of Installation==
 
==Recommended Order of Installation==

Latest revision as of 21:20, 5 September 2019

This page will help you setup the programming environment for designing the low level firmware of individual Molecube actuators. After finalizing and compiling the actuator program, the resulting binary files will be transferred to the ATmega324P/644P processors embedded into the interface boards of the actuator Molecubes. These processors are responsible for physically executing commands issued by the controller Molecube, according to the list of commands given in the hardware protocol definition document.

Recommended Order of Installation

  1. Install Microsoft Visual Studio with all updates.
  2. Install WinAVR-20070525 preferably to the default location C:\WinAVR. Unfortunately, the most recent WinAVR version does not appear to be immediately compatible with our Molecubes firmware. Any help making our code compatible with the most recent WinAVR version is most welcome.
    NOTE: On one occasion, WinAVR installation resulted in emptying the "Path" environment variable. For safety, we recommend backing up the contents of "Path" variable prior to installation and then restoring it after WinAVR has been installed.
  3. Extract AVRLib (slightly modified from the original version to support ATmega324P and ATmega644P) in WinAVR directory so the avrlib root is located at C:\WinAVR\avrlib.
  4. Set the following 2 environment variables:
    AVR = C:\WinAVR\bin
    AVRLIB = C:\WinAVR\avrlib
  5. Install AVR Studio 4.13 (build 528) with service packs: AVR Studio 4.13 SP1 (build 557) and AVR Studio 4.13 SP2 (build 571). This Integrated Development Environment is supplied with drivers for the AVRISP mkII in-system programmer. Once you connect the programmer to the USB port of your computer, the drivers will be installed automatically.
  6. Download the AVR project files from GitHub, and open AVRProject.dsw with Visual Studio. The project should compile now.

Minor Corrections Introduced into AVRLib:

Line 34 of avrlib/make/avrproj_make changed to:
all: $(TRG).elf $(TRG).bin $(TRG).hex $(TRG).ok

Minor #ifdef additions to add in support for ATmega324P and ATmega644P processors throughout uart2.c and timer.c.

In-System Programmer

AVRISP mkII works great, and it costs less than $40 at Digikey.


Recommended Programming Sequence

Avr programming step1.JPG
Step 1: Update your local repository files. Start Microsoft Visual Studio and open the "AVRProject" project and build it (by pressing F7). If AVR tools have been installed successfully, the project should compile.
Avr programming step2.JPG
Step 2: Sroll down to line 25, and find a block of #define items. By commenting in and/or out the individual lines in this block, we configure the AVR firmware contents and functionality. When programming any particular Molecube AVR controller, observe the type of the target Molecube and which part of a robot it is installed into: these can be either North or South half for Actuator, Triplet or Duet half for Controller and Battery (these are distinguished by the number of circuit boards installed in a given half). Gripper only has one ATmega324p controller installed. In the first block of lines, select one item matching your firmware target. Keep device address allocation to 0x00 unless you mean to change it and fully realize the consequences. Some of the modules may need to go through the initialization routine, such as servo angle measurement calibration or gripper position calibration. Servo calibration routine is necessary for all new actuators, gripper initialization is optional. If either of these procedures is required, un-comment the corresponding line and compile the project. If you program the robot with one of these initialization routines, keep in mind that this routine will need to be removed from the robot's memory before it can be a part of a Molecube assembly. So, if you are going through the final round of programming before assembling the modules into a Molecube assembly, comment out any initialization routines. Build your solution once the necessary selections have been made (by pressing F7).
Avr programming step3.JPG
Step 3: Connect AVRISP-MKII to your computer with a USB cable. Attach the target robot to the power supply module or a battery module. Connect AVRISP-MKII to the target Molecube processor board. Before switching on the power on the Molecube power bus, we recommend testing the resistance between the communication line and the high voltage line. Having an accidental short circuit between these two lines has the potential of permanently damaging all communication buffers of Molecubes connected to the communication bus. Resistance between the communication bus and 14..24 VDC bus should be at least 15-20 kOhm. The communication bus terminals are innermost on the Molecube electrical interconnection interface (any of the four radially spaced pins closest to the LED), and the 14..24 VDC bus terminals are the farthermost.
Avr programming step4.JPG
Step 4: Once the resistance between COM and +18V has been confirmed above 15 kOhm, switch on the power, and the formerly red LED of the AVRISP-MKII should change to green. If not, check the wiring between AVRISP-MKII and the Molecube circuit board.
Avr programming step5.JPG
Step 5: Start AVR Studio and click the "Con" button to display the "Connect" dialog. In the "Select AVR Programmer" window, select "AVRISP mkII", type of connection "USB", and click "Connect".
Avr programming step6.JPG
Step 6: In the Main tab of the ISP mode dialog, click "Settings", and set the ISP clock frequency to 250 kHz, click "Write". Select the processor type (AImega324P), and you should be able to read the processor signature.
Avr programming step7.JPG
Step 7: In the "Fuses" tab, make sure that the fuses are set as shown, otherwise, re-program the fuse settings. CAUTION!!! Wrong fuse settings can render the processor defunct, be very careful when programming fuses.
Avr programming step8.JPG
Step 8: Now we need to specify to the AVR Studio, which of the binary files it should place into the flash memory of the processor. In the "Flash" section of the "Program" tab, choose the "main.hex" file, by navigating to ..\trunk\software\actuator\basic_io\main.hex in the Molecubes SVN repository. Check the date when this file has been created, and make sure that this is the file that you have just built using the Visual Studio. Click Program, and observe the programming progress. CAUTION!!! If you had the calibration procedure included into the build, the module will start moving immediately after being programmed.