Show Posts
Pages: [1]
1  Forum 2005-2010 (read only) / Development / PWM timer and Arduino CPU load on: April 19, 2009, 06:41:08 pm
Hello,

I'm working on a project that requires fast analogWrites... I'm looking into using a DAC eventually, but for now I'm just using the PWM features of the arduino.

I found that to get even mediocre performance for my app I needed to play with the timers... no big surprise there... but I'm wondering if the way I'm doing it might impact anything else?  Is there an advantage to choosing, say, DIV8 over DIV1 in terms of how much processing power the PWM timer will use?  My main concern is that if I choose DIV1 over DIV8 unnecessarily, I'll be spending 1 out of every 4 clocks tending the PWM, or something silly like that...
Code:
#define TIMER_CLK_STOP            0x00      ///< Timer Stopped
#define TIMER_CLK_DIV1            0x01      ///< Timer clocked at F_CPU
#define TIMER_CLK_DIV8            0x02      ///< Timer clocked at F_CPU/8
#define TIMER_CLK_DIV64            0x03      ///< Timer clocked at F_CPU/64
#define TIMER_CLK_DIV256      0x04      ///< Timer clocked at F_CPU/256
#define TIMER_CLK_DIV1024      0x05      ///< Timer clocked at F_CPU/1024
#define TIMER_PRESCALE_MASK     0x07    //Total guess at this value...
void setup() {

  TCCR1B = (TCCR1B & ~TIMER_PRESCALE_MASK) | TIMER_CLK_DIV1;

}
2  Forum 2005-2010 (read only) / Interfacing / Re: Switching Laser Module With Arduino on: March 02, 2010, 08:13:42 am
I've switched a 100mW laser diode via arduino before... was making a laser harp...

And, you're somewhat right to be concerned; you likely won't blow anything up, but depending on your driver design, you might have a non-zero turn on time.

The drivers for bigger diodes include feedback and thermal compensation circuitry to prevent you from frying the diode; this will generally keep you from doing bad things to it, but all that circuitry takes power to turn on and off, resulting in a non-zero turn on time.  And it completely prevents you from adding a smoothing cap to the driver power supply, cause that'll change the turn on time from msecs to secs

Some drivers are designed to take a TTL input to switch the diode; in those drivers, all the circuitry is left hot when the laser is off so you get very fast on times.

If you can't find a suitable driver (I bought mine off ebay for $20), Sam's Laser FAQ (Google is your friend) has many reverse engineered driver designs.

And finally, what others have posted is right; your 100mW laser will likely only engrave or burn.  And that's if you focus it really well, on dark colored material.  An adjustable focus rig and patience would be required to cut any appreciable thickness of material.  My advise is to pick up a 1W or higher IR diode on ebay... you can get those for ~$20 without any of the extra stuff you need.  You'll need a lot of extra stuff though, like:

C mount diode housing (preferably with heatsink)

IR-compatible collimating lens (plastic, not glass, people!  glass blocks most IR light)

diode driver (your 100 mW driver won't even cascade the IR diode; it'll light dimly as an IR LED, but it won't lase with that driver)

IR laser safety goggles!!!  The good news is that your eye isn't very good at focussing the IR wavelengths you'll use.  The bad news is that 1W is enough to do plenty of damage anyways, so play it safe.

IR viewing card (rat shack has these for ~$5)

And if you want the ultimate in safety, a glass aquarium to block the IR light (test with the viewing card + safety goggles) - use it as a cutting hood to block any IR reflections.

I can't stress it enough, even looking at the pinpoint of a 100mW laser focussed strongly enough can be blindingly bright, protect yourself!!!
3  Forum 2005-2010 (read only) / Interfacing / Re: Laser X-Y-Axis control on: May 08, 2009, 10:45:04 am
rocketgeek IS right - and you can find kits on ebay for $200+ with the driver circuits, closed-loop control, and mounts.  If you don't like ebay, catweazle (MediaLas in EU) sells a basic kit for ~$250.  

Galvos made for laser use are generally rated in PPS (points per second) - which is measured by how quickly the galvos can draw a standard image (the ILDA test image) without distortion or cornering.  Many things affect the PPS, most notably, the inertial moment of the motor (which includes shaft and mirror weight), the size of the projected image, and the galvo amplifier.  Galvo amplifiers are categorized into two types, open-loop (such as the simple op-amp amp I'm using) and closed-loop, which uses some method to measure the galvo position and changes the control signals accordingly (it's like a really complicated cruise control)

8,000 PPS would be enough for beam effects
The symbol tech galvo I'm using is typically rated 8-12KPPS (depending on driver - they come wired as a full-deflection galvo and are rated at 6KPPS for that use - going from +10V to -10V and back over and over again)

12 KPPS is regarded as the bottom end for any animations or vector drawings.  Expect rounded corners and less than stellar lines.  They'll be straight, they just may not end up exactly where you wanted them

30,000 PPS is where you start getting accurate enough for good animations and laser light shows.  Any closed loop galvo should be able to hit 24-30KPPS easily.

However, a bit of a warning: the ILDA test image is not the end-all be-all of galvo tuning; just because it can draw the image well at 30,000 PPS doesn't mean it can function at 30,000 PPS for your application...


I assumed anyone posting in this thread was already aware of that though, and that the goal was to accomplish the same with cheaper / more commonly available materials.

That said, I

4  Forum 2005-2010 (read only) / Interfacing / Re: Laser X-Y-Axis control on: May 06, 2009, 08:00:55 am
Oh I agree totally - but that's not what he did, and I think it's impressive that he got the results he did with those mirrors.

It'd be a different story if his throw distance was longer though... the seconday reflection probably isn't too far off the main line at that distance...

BTW, I hear cheap paint stripper and acetone can take the back off a regular mirror and convert it to a front-surface...

I've also seen people fashion laser mirrors of this sort out of stainless steel.  Most hobby stores and some home improvement stores sell this as an adhesive-backed 1" strip.  I'm guessing it's probably between a true FS mirror and the typical crappy hobby mirrors most of us can get our hands on, in terms of beam quality.  It's practically impossible to cut without the right tools (stainless steel is harder than steel, so you need tungsten carbide or diamond bits and saws) The trick would be to solidly mount it to a flat surface, and use high-grit wet-dry to polish it to a mirror finish.
5  Forum 2005-2010 (read only) / Interfacing / Re: Laser X-Y-Axis control on: May 06, 2009, 07:06:15 am
Yeah, I did some searching... found a guy that glued a bunch of mirrors off a disco ball to a fan.  Looked like he used bent paperclips and then manually adjusted each mirror.  It's probably only in focus at the distance he adjusted for, I would imagine... but he shows a 16x16 pixel display running off an arduino with a laser pointer (projection size: maybe 3"x2")

He says it's doable, just tedious...

It's the second project down on this page:

http://heim.ifi.uio.no/haakoh/avr/
6  Forum 2005-2010 (read only) / Interfacing / Re: Laser X-Y-Axis control on: April 20, 2009, 06:32:04 am
Just a quick note about the lock in and dead zones...

I was reading the excellent "ELM - Home Built Laser Projector" post (google if you're curious) and his home-built galvos suffer from the same problem... they're driven in a similar manner (minus the position detecting segment of his amplifier stage)

He helpfully includes this diagram:

http://elm-chan.org/works/vlp/pdout.png

We're just using the torque section here... no PD on our galvos, remember...

But the cyan and gray bars still apply - there's a center zone where the torque is high enough to lock to a central position (this is in my 0-45 zone), and a mid-range zone where the torque is low enough to cause galvo lock at incorrect positions.  

This is where the force of the centering spring + dynamic friction stop the stator movement, then it takes a larger torque to get the mirror moving again... this is actually a desireable effect to get nice clean lines out of the scanner, but too much causes position errors.

This tells me a few things about this galvo:

It's going to be very timing dependent.  The direction of motion and magnitude of motion for each point will greatly impact the accuracy and final position of the galvo during a single analogWrite command

It's going to be hard to correct for this in software with an 8-bit value - with more granularity, it would be easier to dynamically "jerk" the galvo into position based on a derived model of it's properties

And finally, to create a driver for this galvo that takes advantage of the properties of movement of the galvo, I would set the output range in the +30 - +60 offset range.  This should minimize drift error and still give a useable range... if -10v - +10v = -180 - +180, then +30 - +60 should = 3.33v - 6.67v, giving an op-amp circuit of offset 3.33v and gain of 0.67.

To change the basic gain op-amp amplifier design above to include offset, compute RB and RA as before (G = (RA + RB) / RA)... then using RA as one leg, create a voltage divider to set the offset at 3.33v (i.e. compute a value RC to connect to 5V such that 5V / 3.33V = RA / RC)
7  Forum 2005-2010 (read only) / Interfacing / Re: Laser X-Y-Axis control on: April 19, 2009, 06:41:29 pm
Sorry if I'm digging up an old thread here...

This is absolutely possible with an arduino and analogWrite...

I've only made an X scanner, an X/Y scanner should be possible by using two PWM pins and this method.

First, the glory of a working picture:



This was taken during the day, ISO-800, smoke from a cigarette, 100mW red laser

Hook-up details:

Get it working quick:

Use any single-supply op-amp (I used the LM324 from rat shack as I had it lying around... overkill as I'm not using 3 of the op-amps)  and hook it up in voltage following mode:
INV1OUT (pin 1): Galvo control wire
INV1- (pin 2): wire directly to INV1OUT
INV+ (pin3): connect to arduino pin 9
Vcc (pin4): +5V
GND (pin11): GND

You really ought to add a signal-levelling cap between GND and INV+ pins, as close to the chip as you can get it (soldered piggyback would be my preference)... but I got decent results with and without.  With, your beams should look slightly sharper as the mirror won't wiggle with the PWM output.  I'd use a small value as you don't want to filter out the high-end too much.  For no good reason at all, I chose a small ceramic cap marked _22_ for mine.

I used galvos pulled from old supermarket scanners.  There must be a million of those things lying around, you can always find them on ebay.  They were made by Symbol Tech and are usually labelled as servos or some such... you can usually find them on eBay for around $30 as pulls from old equipment...

The galvo has a four-wire connector, Blue, Red, Yellow/white, Black.

I wrote Symbol a couple years ago to get info about the connector (there's zilch online in terms of official specs)... as I recall, it's max rating is 12V (I've read others quote 14V).  You apply a bias current to the black/red wire pair, and a variable voltage to the other pair.  The direction and magnitude of that voltage determines the mirror swing.

I connected Blue and Black to ground, Red to +5V, and Yellow/white to the INV1OUT pin.

then analogWrite(9, value) should position the galvo!

Two big issues with the above:
a) the galvo is way underpowered for it's rating
b) the PWM on the arduino is timed ~ 490Hz by default

a) is solved by using a 9V adapter / battery to power your arduino, and feeding the motor off of it.  To adjust the signal, connect Vcc of the op-amp to 9V instead of 5V, and add a Gain=1.8 to the op-amp.  Basically, that means you need two resistors with a value ratio of 1 : 0.8.  Connect the higher one from INV1- to GND, and replace the connection between INV1OUT and INV1- with the smaller resistor.  Not sure how much value matters, but lower is probably better.  The LM324 is current-limited to 40mA sink internally so you can't really fry your arduino with it, feel free to play around with the resistor values some.  If you pick too high of a ratio, you'll get clipping at the extreme +/- end of the range.

b) requires a little timer hacking.  The PWM timer on the arduino is adjustable... I used the following code to set mine fast enough:

Code:
#define TIMER_CLK_STOP            0x00      ///< Timer Stopped
#define TIMER_CLK_DIV1            0x01      ///< Timer clocked at F_CPU
#define TIMER_CLK_DIV8            0x02      ///< Timer clocked at F_CPU/8
#define TIMER_CLK_DIV64            0x03      ///< Timer clocked at F_CPU/64
#define TIMER_CLK_DIV256      0x04      ///< Timer clocked at F_CPU/256
#define TIMER_CLK_DIV1024      0x05      ///< Timer clocked at F_CPU/1024
#define TIMER_PRESCALE_MASK     0x07    //Total guess at this value...
void setup() {
  TCCR1B = (TCCR1B & ~TIMER_PRESCALE_MASK) | TIMER_CLK_DIV1;
}

These galvos are really non-ideal for graphics, but the work good for beam effects.  They have a wicked non-linear response; my testing seems to indicate there's a lock-in zone around dead-center (with a LOT of wiggle on it!) and two dead zones on each side half-way to full deflection  - your mileage may vary.  Circuit tuning your op-amp with some basic filters will certainly help, too.

Problems with my current implementation:
I'm only feeding the galvo 0 - +9v signal, I should be feeding it -10v - +10v, or at least -9v - +9v.  Theoretically, you could fix this with a differential PWM driver, a second op-amp, and connect the - side to the blue wire on the galvo... but that would probably require hacking some of the hardcore PWM code in the arduino to generate the proper wave-form...
8  Forum 2005-2010 (read only) / News / Re: New! Integrated ATMEGA Arduino Xbee (50% savings) on: September 01, 2009, 07:08:01 am
Wow this looks like a great product.

Can't wait for you to have some stock!

My monthly arduino budget is a little more than one of these, I'll definitely be shopping with you ASAP!
9  Forum 2005-2010 (read only) / Uno Punto Zero / Re: internal pullup resistors & digitalWrite on: March 03, 2010, 07:49:37 am
yeah - don't enable pullups by default, please!  I have a lot of carrier boards that might do bad things to an arduino if that happened...
10  Forum 2005-2010 (read only) / Uno Punto Zero / Re: Library handling on: March 03, 2010, 07:47:12 am
I love the idea of a #library in arduino...

Here's my thoughts at random to the above thread...

I like the idea of early checking for libraries... and especially having dependencies in a .properties file... there have been breaking changes to arduino in the past that required me to rewrite libraries, and this might've addressed some of the issues I had...

I think its definitely important to leave the libraries themselves pure c/c++ - this should be a sketch-only precompile.  It's made to fix specific confusing issues with using libraries in Arduino, not with including files into the C language.

I think it's a great time to add more library management to the UI as well... install / import library is a good start.  Edit library would be another one - using Arduino to edit library files has required a lot of copy and paste with notepad for me in the past...
11  Forum 2005-2010 (read only) / Uno Punto Zero / Re: PWM variable frequency added to the PWM function. on: March 03, 2010, 07:41:55 am
Good idea.  You can do it hacking the timers, but the code is messy, and apparently can affect other things if you're not careful.

That's probably the main reason it wasn't included; unintended consequences... each pair of PWM pins is tied to a timer that controls the PWM frequency... and millis(), micros(), and other functions depend on TIMER0 being a specific frequency... still, this could all be noted in the documentation about how to use it...
Pages: [1]