Search This Blog

Tuesday, September 23, 2014

Mechatronics Project 2

Mechatronics Project 2:

In this project, we had to program the arduino pro mini to control a servo and a stepper motor from user input. Prompting was done with a 2x16 LCD display and user input was done with a resistive touch screen. The user had to be prompted for which motor, rotation angle in degrees, rotation direction, and hold time. All entered values had to be echoed on the display after input and the motors had to return to initial position after the hold time.

The touchscreen is an analog device that uses the arduino's 10bit ADC. It has four contacts, with a breakout board to four pins. A 5V differential is put across two pins and one of the other pins is read by the ADC, while the last pin is left floating. This gives either the x or y position. Then the process is repeated with the pins switched for the other position reading. It requires high value (10k in this case) pull down resistors. A written number pad was placed behind the screen. The pad was then mapped by finding all of the boundaries of the "keys". A function in the code translates pressing on the pad into the corresponding number. Pressure is very important for resistive touchscreens. You have to measure pressure and set a threshold for it to prevent bad readings. Pressure is measured by applying 5V to both sides of both x pins, then measuring one of the y pins with the ADC. Note: most touchscreens have a sensitive side and a not-sensitive side. You have to find the right side.

The 2x16 LCD display has a backpack that translates USART serial commands into characters on the display. This made it a lot easier than the last project. Once I found the data sheet and found the USART functions (I wrote my own first, which took 3 hours, but then found some that ended up being identical...doh), it was pretty easy to control.

The stepper motor was controlled with a stepper motor driver board. This required step commands and a rotation command from digital pins. The current was limited on the stepper to prevent it from getting hot. I also used the enable/disable pin to turn the FETS on/off to lower power consumption. This was driven with a 12V power source. While the stepper driver was capable of microstepping, I did not implement it.

The servo was controlled with hardware 50Hz "fast" PWM generated by the 16bit Timer 1 on the arduino. Servos typically take pulse widths between 1ms and 2ms at 50Hz (20ms period). For my servo, the 0 and 180 deg points were calibrated by finding the number of counts that resulted in pulse widths that resulted in a full 0-180deg swing. Then user input degrees between 0-180 was linearly interpolated from those two end points. This was done because the 1ms-2ms was only ~120deg. Note that the servo cannot be driven with the 8bit timers in "fast" PWM mode with a 16MHz crystal (like this arduino has) because they can't count enough to get down to 50Hz. In "phase corrected" PWM mode, they can get down to 50Hz, but the resolution is very poor. Luckily, each timer has two independent channels, so two servos can be driven off of Timer 1. If you need to drive more servos than that, I would suggest buying a servo control board.

The same 12V power source than ran the stepper motor was input into a 5V regulator circuit (based on an LM7805) to power all of the other electronics.

Pictures:



5V regulator circuit
The software was organized into libraries and a main code. One custom library contained all of the LCD display functions. One contained the USART serial communication functions. One contained all of the touchscreen functions. The main code handled all of the logic (stepping through the user input lists) and motor driving. As with all of the mechatronics projects, I can't post the code until the professor changes the projects.

In addition to the links from the last project, I found the following links helpful:


If you want specific part numbers and datasheets, most of these parts came from this kit:
http://www.jayconsystems.com/educational-kit-advanced.html or their equivalents on sparkfun.

No comments:

Post a Comment