Search This Blog

Friday, September 12, 2014

Mechatronics Project 1

I decided to take a mechatronics class at FIT because it would be different and very useful. The class is split into two portions: learning to program an Arduino pro-mini using C and Atmel AVR-Studio, and then learning Matlab/Simulink XPC. We have to use C because "the arduino IDE is too easy".

Project 1 was to make a stopwatch using a 4 digit 7-segment display and the arduino pro mini 328 5V/16MHz. It must count up in increments of 0.01s using interrupts/timing, and have a button for start/stop and reset. I used the FTDI/USB device to program the arduino (with bootloader) through AVR-Studio.

The breadboard circuit shown below was wired. The display has pins for each segment and a common cathode for each digit. There are 330Ohm resistors in series between the arduino and each anode. There is a NPN transistor for each cathode that act as a switch. When an arduino pin drives the base of the transistor high (through a current limiting 10kOhm resistor), they turn on, grounding the cathode, allowing individual digit control. The digits are cycled through rapidly to take advantage of persistence of vision. The button is hooked up to pin 13 on the arduino, which is the one with the onboard LED. This made using it as an input somewhat difficult because the onboard pullup resistor is 20kOhms, which results in a pin voltage of around 1.7V instead of 5V because the onboard LED is drawing current. So I had to drive the voltage on the pin high as the trigger instead of grounding the pin as I would have normally done.

As for code, there is a main loop that contains the button polling routines. There is also an interrupt service routine (ISR) that handles the digit counting and timing via a bunch of volatile variables and if trees. There is a "on" routine that takes care of turning on and off the correct segments for each number 0-9. I can't make the code available since the class is still running. Apparently the more common way to do it is to have the ISR act as a 0.01s timer that calls a separate function that handles the digit counting, which would probably avoid the use of volatile variables.

In addition to the component datasheets, the resources I used are below:

No comments:

Post a Comment