Sunday, October 14, 2007

Motor PWM

For a long time I have had trouble controlling motor speed using a microcontroller. It seemed that either the motor would pull so much current and completely stop everything else, or there wasn't enough power and the motor would crawl, or the transistor used would get extremely hot and burn me.

After alot of playing around I've finally got something that has worked(Although my guess is I'm still doing something dumb). Below is the schematic...I didn't bother posting a video since it would just be a motor going slow and then fast, and the source code is really simplistic as well for the microcontroller.

Some things I found, that may or may not be correct:
  1. Needed two 9V batteries to get enough current to power the motor at full speed and keep the circuit operational. I'm running them in parallel although this may be incorrect. Running with one battery lets me only get about 1/3 of the top speed till the rest of the circuit dies.
  2. Switching and current work together to make transistors become incredibly hot. So for example I tried doing something like switch the transistor on one cycle, off the next cycle, and repeat forever to achieve half power. Bad mistake that resulted in a minor burn, the constant switching with current to drive the motor about blew the transistor. Now I'm switching twice per 10000 cycles, so if I want half power I do 5000 consecutive cycles on, and 5000 consecutive off.
  3. Motors can get stuck, with very negative consequences! If you use really low power the motor will jam until either it's getting enough current to break free or until you rotate it into working. This doesn't seem at all bad, until you realize it sucks in heroic amounts of current trying to turn itself in the meantime. This causes the power on everything else to go out, the transistor to burn up, and even the power source to get overheated. Lesson is, unless it's a stepper motor, it should be going a decent speed to be in use.

Tuesday, October 02, 2007

Mandelbrot Programs

Some old programs I wrote back in college I wanted to post so I wouldn't lose them. They are the result of a full day of tinkering with the mandelbrot set in bizarre ways. There are three programs in the order they were written. The only really dependencies are the math C libraries, X11 windowing system, and /dev/audio is writable. *snip--nm*

mandelWTF -- Randomly changes the mandelbrot set and outputs sound based on the images...don't ask ;)
mandelSound -- Slowly permutes the the mandelbrot set and then generates sound from the inside out

mandelUpdate -- Uses the escape time as a weight, and then updates surrounding 'nodes' based on the new weight.

All source code can be found here. Run make run to see them in action. And for some reason I can't get mandelWTF to work outside of a script, it segfaults....which is just weird.