MEAM.Design - MEAM 410/510 - L3 (Strobe)

This lab is intended to familiarize you with the M2 microcontroller and the development environment that we will be using to to write and debug code. Through the exercises below, you will investigate a number of subsystems, including digital I/O, timers, and analog-to-digital conversion. Items in bold should be included in a brief report to be submitted via email (see the last section for details).

Prelab Exercises
(complete by 3:00 p.m. on Wednesday, but you do not need to submit anything!)

0.1 - A Little Background Reading

0.1.1 - Read through the following reference guides for the M2 microcontroller, which can be found by clicking on the MAEVARM link in the menu on the left:

Board pinout & functionality
Custom Header File
System Clocks
I/O Ports (GPIO)

0.2 - Pseudocode

0.2.1 - Write pseudocode for part 2.1.2.

0.2.2 - Write pseudocode for part 2.3.1.

0.3 - Strobo-Schematic

0.3.1 - Sketch a schematic for the circuit that you will use for your stroboscope.


1.1 - Adding Pins

1.1.1 - Examining the M2 board, you’ll see 28 holes in two rows. There are tiny labels next to each hole.

1.1.2 - To gain easy access to the I/O pins, solder two 14-pin short-short headers to the board, as shown below. Notice that the two ends of the header pins are slightly different lengths. You want to solder the SHORTER ends to the M2. To ensure good alignment, push the pins into a solderless breadboard before soldering. Note that cold solder joints are one of the most common sources of frustration - remember to add heat to the pin and pad, then add the solder!

1.2 - Integrated Development Environment

1.2.1 - To develop and download code to the M2 board follow the appropriate link:

If you are using a PC click here (or just follow the instructions below)

1.2.2 - Create a new AVR Studio project (for a PC):

Option 1: Creating a new project in AtmelStudio 6

1. Start AtmelStudio 6.0
2. Click on New Project
3. Select GCC C Executable Project, give your project a name, set the Location, then click Ok
4. Set the device to ATMEGA32U4 and click Ok
5. Within AtmelStudio, build the project (F7, or Build from the Build menu)

Option 2

For this option, you don't need to install AtmelStudio.

1. Download the template code
2. Place your source files (*.c) in atmega/src folder
3. Place your header files (*.h) in atmega/inc folder
4. Navigate command prompt (cmd) to atmega folder and execute:
5. You should see some information about your compiled files and memory usage and the last line should be
[>-----Build Successfully-----<]

1.2.3 - At this point, you should see the development environment with a blank file.

1.2.4 - Add the following (rather boring) function to your code:

int main(void)

This won't do much (actually, nothing at all), but it will allow you to test the uploading process.

1.2.5 - Now, using the USB A-to-mini-B cable from your kit, proceed through the following steps to upload your code to the M2:

1. start Flip 3.4.7
2. click the button that looks like an IC, and select the ATMEGA32U4
3. plug in your microcontroller (if you haven't done so already)
4. hold the onboard button down for about two seconds (until the green LED turns on) then release (the orange LED should now be illuminated)
5. click the button that looks like a USB cable, select USB, then select Open
6. select Load Hex File from the File menu (the hex file usually lives in the default folder within your project folder)
7. click Run to upload your code to the micro
8. to run your code, press the onboard button for less two seconds (the orange LED should now be off)

1.2.6 - This would be a good time to grab the latest version of the m_general.h file from here, and place it next to your main.c file for later use.

Part A1 - My First MAEVARM Code

2.1 - Blink

2.1.1 - Onboard LEDs - Add code to the main routine to flash the red onboard LED at a frequency that you can see. You will need to develop some method to delay the processor (without using the timer subsystem, clock prescaler, or the m_wait() function) so that the flashing is slow enough to see. Include a copy of your commented code, and estimate the frequency at which the LED is flashing.

2.1.2 - Pin output - Modify your code to toggle the output of port B, pin 6 instead of the LED. Using an oscilloscope, measure the frequency of your output signal. What is the actual frequency? What is the duty cycle? Now, adjust your code to set the output frequency around 500 Hz, with a duty cycle close to 50%. Include a copy of your (commented) code.

2.1.3 - System Clock - Now, adjust the system clock prescaler, and observe how the output changes. Does the output frequency change as you would expect? What was the default system clock frequency?

Part A2 - My Second MAEVARM Code

2.2 - Output Compare Timers

In 2.1.1 above, you had to include some sort of waste routine to slow down the blink rate of the LED. We will rarely want to do this, since there will likely be other tasks that we'd like to be attending to in the interim. To free up the processor, we can utilize the timer subsystems to independently control periodic events.

2.2.1 - Using Timer 1, set the output of pin B6 to a frequency of 500 Hz with a duty cycle of 50%. What frequency and duty cycle were you able to obtain? Include a copy of your commented code.

2.2.2 - Modify your routine to output at a frequency of 0.5 Hz with a duty cycle of 20%. What frequency and duty cycle were you able to obtain? Include a copy of your commented code.

2.3 - Analog Conversion

2.3.1 - Digest the information posted in the MAEVARM guides about the Analog Subsystem. To ensure that you can successfully read in an analog value, connect the wiper of a 10k potentiometer spanning a 5V supply to ADC0 (F0) and have one of the onboard LEDs turn off when the voltage is below 2.5V and turn on when it is above 2.5V. Show this to someone in the lab, record their name, and include a commented copy of your code in your report.

2.4 - Submission

2.4.1 - Submit your answers to the questions posed in Part A1 and A2 as a PDF file entitled "510-L3A.PDF" attached to an email to "" entitled "510-L3A".

Part B - M2 Stroboscope
(due IN CLASS)

Combining general-purpose I/O with the timer subsystem on the M2, your task is to create a battery-powered, user-adjustable LED strobe light.

3.1 - Control Inputs

3.1.1 - All stroboscopes must include an analog potentiometer that can be used to adjust the blink frequency from 0.5Hz up to approximately 30Hz (wherever it becomes indistinguishable from solid light).

3.1.2 - If you are in 510 (or if you'd like some bonus in 410), you must also include a bank of 4 DIP switches that can be used to set the duty cycle, where 0000 will correspond to a very low duty cycle and 1111 will correspond to a very high duty cycle.

3.2 - Hardware and Output

3.2.1 - Your system must be battery powered.

3.2.2 - Your system must be portable, and should be relatively robust.

3.2.2 - You should include an easily-identifyable ON/OFF switch.

3.2.3 - The output from your system will be an external LED (or multiple LEDs, but please don't excessively raid the ministore) connected to a pin (or pins) from the microcontroller. You must analyze the current requirements of your system and include whatever circuitry will be necessary to prevent damage to the microcontroller.

3.3 - Delivery

3.3.1 - Label your system with your name (the simple solution would be with a piece of masking tape and a marker).

3.3.2 - Bring your labeled system (complete with a reasonably charged battery) to class. We will test your system that night and it will hopefully be available for you to pick up from the GM lab the next morning.

3.3.3 - Send a copy of your final code to with the email title of "510-L3B".