Monday, January 10, 2011

Servo Driver with Altera Max II CPLD

If you don't do CPLD design often, working with Quartus II is a pain in the rear. It doesn't run natively on Ubuntu and my old PC running Win XP didn't have enough memory to install (Quartus II installer is 3GB and uncompresses itself into your temp dir @ 4 GB and the final installation is 5GB so you are talking 12 GB of free space required. My old lap top HD was 16 GB total...) Also you will probably want model sim if you are going to do any synthesizing.

My goal was to drive a servo from the CPLD using VHDL. I've attached the project and source in case anyone else is pulling their hair out looking for a simple tutorial to work with their new design board. This is all assuming you are using the 50 MHz clock on the dev board with the Max II.

Good Luck!



VHDL Code for PWM output


20 ms signal generator output tck should be routed to the servo drive tck input.

20 ms signal generator


-- Generated by Quartus II Version 10.1 (Build Build 153 11/29/2010)
-- Created on Sun Jan 09 00:51:34 2011
LIBRARY ieee;
USE ieee.std_logic_1164.all;


-- Entity Declaration

ENTITY freq_div IS
-- {{ALTERA_IO_BEGIN}} DO NOT REMOVE THIS LINE!
PORT
(
clk : IN STD_LOGIC;
tck : OUT STD_LOGIC
);
-- {{ALTERA_IO_END}} DO NOT REMOVE THIS LINE!

END freq_div;


-- Architecture Body

ARCHITECTURE freq_div_architecture OF freq_div IS
signal count : INTEGER := 0;
signal x : STD_LOGIC := '0';

BEGIN
process(clk)
begin
if (clk'event and clk = '1') then
tck <= x;
if (count = 1000000) then -- convert 20 ns clk to 20 ms tcks
x <= '1';
count <= 0;
else
x <= '0';
count <= count + 1;
end if;
end if;
end process;
END freq_div_architecture;


Servo Driver


-- Generated by Quartus II Version 10.1 (Build Build 153 11/29/2010)
-- Created on Sun Jan 09 20:59:28 2011

LIBRARY ieee;
USE ieee.std_logic_1164.all;


-- Entity Declaration

ENTITY servo_driver IS
-- {{ALTERA_IO_BEGIN}} DO NOT REMOVE THIS LINE!
PORT
(
clk : IN STD_LOGIC;
tck : IN STD_LOGIC;
en : IN STD_LOGIC;
pwm : OUT STD_LOGIC
);
-- {{ALTERA_IO_END}} DO NOT REMOVE THIS LINE!

END servo_driver;


-- Architecture Body

ARCHITECTURE servo_driver_architecture OF servo_driver IS
signal count : INTEGER := 0;
signal pos : STD_LOGIC := '0'; -- servo position 0 or 90 deg.
signal x, y : STD_LOGIC := '0';

BEGIN
process(clk, tck)
begin
if (clk'event and clk = '1') then
if (tck = '1') then
x <= '1';
pos <= en;
end if;

pwm <= x;
if (x = '1') then
count <= count + 1;
else
count <= 0;
end if;
-- count = 50000; convert 20ns to 2ms = 90 deg.
-- count = 100000; convert 20ns to 1ms = 0 deg.
if ((pos = '1' and count = 50000) or (pos = '0' and count = 100000)) then
x <= '0';
end if;
end if;
end process;
END servo_driver_architecture;

Sunday, December 6, 2009

Red Balloons and Back in Action

It's been a while since my last post. To recap, the table is finished and I'm just putting in the last of the electronics. I'll post some pictures hopefully next week of the setup.

In the mean time if you are interested in the MIT Red Balloon Challenge you can join my team here: http://balloon.media.mit.edu/bigcmos/. We'll need people across the country so Sign up!

Thursday, April 9, 2009

multitouch examples

Webcam just arrived and omegabob was kind enough to send me some filters to play with before I purchased! Thank you sir! I'm hoping I'll now have everything I need for this weekend to get some good blobs. It is easter so we'll see how much time I have to tinker.

I still need to find a place that sells mirrors and experiment with some compliance surfaces, but the good news is VoMTouch has a similar setup to what I am looking to do and has some great videos in this post. I'm using different LEDs than he is, so I'll need to see if I can get a good response out of them before I purchase the final strands. Also, I need to do make some diagrams to see if I can fit everything under a coffee size table (18"-24" tall).

Hopefully I'll have some new pictures and maybe footage up this weekend.

Sunday, April 5, 2009

multitouch phase 1

So I haven't been on here in a while, but I just read this article about multi touch DIY projects and discovered the NUI forums and have started a multi touch screen project using FTIR! The goal is to create a coffee table (18"-24") that has a 50" multi touch screen built in. That is a very short throw for that height table, but I think it is possible.

I decided I didn't want to buy my own LEDs and solder them all together. Recommended from the NUI forums is a company called environmental lights which sells ribbons of IR lights which are perfect for this application. They have 850 nm and 940 nm LEDs so I decided to purchase the IR LED Ribbon Delux Sample Kit to give it a test. As they mention on their site, the 850 have a slight reddish visible glow, but produces brighter IR from what I can tell. The red tint is faint when looking directly at the LEDs, and from along the acrylic it is almost impossible to see. I am leaning towards ordering a whole real of these LEDs in the 850 nm range.

I also stopped at Tap Plastics and picked up some random sized 3/8" and 1/2" acrylic sheets to test with. I didn't realize how many types of acrylic there are! Fortunately very few of them come in sizes over 1/4" so I just grabbed whatever was in the bargain bin. I also picked up an acrylic scraper as the first step to polish the acrylic edges. I also picked up some poly-urethane sheeting to test as a diffuse layer for the projection screen.

Last I hit up home depot and picked up some aluminum "C-channel" or "U-channel" and some sanding/buffing supplies. I noticed that people on the NUI forum (this thread, and this thread) had a hard time finding "C-channel" but there was a great section (in isle 19 hardware) at home depot which had good prototyping materials. I say good "prototyping" materials because the aluminum channels were a bit warped and blemished, but they worked well for my initial testing. In the kit from environmental lights there was some examples of the 1/2" and 3/8" channel which they sell and it was much nicer than anything I found at home depot. It also felt like it might have been anodized because it looked scratch resistant and more robust. Also, the LED strips fit nicely into the 1/2" channel from env lights where as the home depot 1/2" is just a bit small for the special connectors that came in the kit.

After getting home I spent some work cleaning the edges of the acrylic. I ran some tests with and without cleaning the edges and the polished edges produced better blobs. I drilled some of the C-channel to a wood board, I placed one of the LED strips in the channel and then the acrylic on top. After powering the LEDs, I used my video camera (web cam I ordered is still in the mail...) in night vision mode (IR band reject filter mostly removed) and then touched the acrylic. I had to press pretty hard, and you can see the blobs I was able to create below. (Yay for physics!)



























I also tried spraying some acrylic frost on part of one, and scratching the surface (sand paper) to create different surfaces (diffuse layers). Both of them worked, but they scattered the light on any objects close to the surface. I'm going to have to see if this will work with the image detection software (touchlib) once the web cam arrives. I also want to see how I can reduce the amount of force needed on the screen to create the blobs.

I am currently waiting for the web cam and projector I won on eBay to arrive which should happen next week. Once they come in I'll hopefully be able to post some better images.

TODO:
Hook up the web cam and see if the software can recognize my blobs.
Determine where to place mirrors under the table to get the lowest profile table at 50" diagonal with the projector.
Determine a good touch surface to create a zero force effect.
Find a cool use for my new toy....

~cmos

Saturday, November 29, 2008

It Works!

So the API isn't supported but still seems to work.  Found some interesting behavior that only about 8 bytes of data default are read from the buffer on each callback even if you are streaming a bunch of bytes on the serial port.  Seems that this can be fixed by setting the defaults or if you don't care about where it ends, just doing continual reads.

As for the Atmel program, Hyperterminal to the rescue! I now have a program that just copys back whatever is sent over the serial line.  I just modified the example uart program from winavr that writes to the LCD and to the uart (I don't have an LCD hooked up at the moment).  Java app seems to send data fine to the serial port and read it back, even if it is chopped up in 8 byte segments.

Going to work on sending a square wave and triangle wave and just streaming them from the Atmega 16 (based off of a button press? or maybe a command from the java program over the serial port) and graphing the streamed data from the MCU.  Not sure what type of data we will need to stream yet, but will probably write some utils to put 16 and 32 bit values on the line in addition to the 8 bits I am currently streaming.

Writing to the Serial Port

Decided to go with Java for this project (mostly because the tools I'm using are free).

First Roadblock - Apparently the Java support for javax.comm has been EOLed per this thread. I found a link to an older version of the jar file at Rick's Blog, but and it seems to work for Windows XP, but doubt that it will work in future versions of Windows. I found a good reference to get me started understanding how to use the API. Circuit Negma had good information on getting the javax comm libaries working.  If this doesn't work I'll probably either read more on the RxTx website or try to just write my own implementation for Windows. Another HOW TO Serial with RxTx.

It appears that if I am going to write my own implementation I would have to use JNI and write it in C or C++ for windows, here is a thread that describes the win 32 apis. Here is an example from the MSDN. Awesome implementation - http://www.codeproject.com/KB/system/serial.aspx. Another interseting link - http://www.fogma.co.uk/foggylog/archive/140.html.

Monday, November 24, 2008

Coding Environment for the Atmel MCUs

Getting my computer setup with development tools. I decided to go with Eclipse CDT and found a good resource to getting the AVR plugin's setup from the FriendlyARM Blog. I'm also using tortoise.svn with subclipse plugin as my SCM for this project. Hosting the source files on a MyBook World Edition hacked to run apache SSL and the svn mods. Should make it easy if I decide to share this project in the future.

Environment
tortoise SVN 1.5.5 - http://tortoisesvn.net/downloads
Maven 2.0.9 - http://maven.apache.org/download.html
Java 1.6.0_10 - http://java.sun.com/javase/downloads/index.jsp
Eclipse IDE for Java Dev - http://www.eclipse.org/downloads/
- SVN Plugin - http://subclipse.tigris.org/update_1.4.x
- CDT - http://download.eclipse.org/tools/cdt/releases/ganymede
- Maven - http://m2eclipse.sonatype.org/update
- AVR - http://avr-eclipse.sourceforge.net/updatesite

I have found that the CDT and avr plugins are so awesome.  They generate the makefiles and will actually auto discover the type and speed of the MCU and download the files directly to the MCU as well.  Great stuff!