Go Down

Topic: controlling voltage alternation lasers (Read 173 times) previous topic - next topic

dylangeorge

Oct 08, 2020, 04:18 pm Last Edit: Oct 08, 2020, 04:19 pm by dylangeorge
Hi all,

I'm trying to control the alternation output of two lasers. A working example - Laser 1 - on for 45us off for 5us then Laser 2 - on for 45us and off for 5us then Laser 1 back on for same times in as loop until I press stop.

The lasers require a modulation voltage of 5V, I have done this with a NI Daqmx board + Labview before but would like to find a cheaper way to allow more access to people who can't afford a daq board.

Basically I need some guidance on how to do this codewise, which ardunio/microcontroller to buy that supports the alternation frequency (1000kHz) and is cheap.

Thanks,


Semtex9


TheMemberFormerlyKnownAsAWOL

Quote
Basically I need some guidance on how to do this codewise, which ardunio/microcontroller to buy that supports the alternation frequency (1000kHz) and is cheap.
Have we got our powers of ten mixed up?
Please don't PM technical questions - post them on the forum, then everyone benefits/suffers equally

jremington

#3
Oct 08, 2020, 10:38 pm Last Edit: Oct 08, 2020, 11:14 pm by jremington
It would take about ten lines of code to do that with a $2 eBay Arduino Pro Mini, less than the cost of a good cup of cappuccino. Very crudely, you could try something like this. If the timing is critical, there are better solutions.

Code: [Select]

digitalWrite(pin, 1); //turn on laser
delayMicroseconds(45); //wait
digitalWrite(pin, 0); //turn off
delayMicroseconds(5); //etc.
...

dylangeorge

Thanks for your suggestions. I'll have a try with an arduino mini. Timing is critical yes. Would combining a arduino with AD9833 DDS work? Or am I just complicating it?

DrDiettrich

I'm trying to control the alternation output of two lasers. A working example - Laser 1 - on for 45us off for 5us then Laser 2 - on for 45us and off for 5us then Laser 1 back on for same times in as loop until I press stop.
What's Laser 1 doing while Laser 2 is on? Shouldn't it be 55┬Ás off?

dylangeorge

#6
Oct 09, 2020, 02:49 pm Last Edit: Oct 09, 2020, 02:50 pm by dylangeorge
Yes, my description should have been clearer, one lasers would be off while other is on. So both would be off for 55us at different times.

jremington

digitalWrite() is slow so for precise timing use direct port access. These instructions set and clear port output bits in a single machine cycle, 62.5 ns on a 16 MHz Arduino.

Code: [Select]
PORTD |= (1<<4); //set bit 4, port D
PORTD  &= ~(1<<4); //clear bit 4, port D


Otherwise, set up a timer with PWM to toggle the bits automatically.

DrDiettrich

Slow digitalWrite() does not matter as long as turn on and off are delayed by the same time.

jremington

#9
Oct 09, 2020, 06:54 pm Last Edit: Oct 09, 2020, 06:54 pm by jremington
Slow digitalWrite matters for the on/off cycle period, given the delayMicroseconds granularity.

DrDiettrich

No problem if the time base is a hardware timer, not a software loop. delayMicroseconds() is somewhat precise but can not take into account the runtime of any code in between two calls.

A very stable solution would generate a sequence of PWM pulses and distribute every other pulse to the other laser. The switch point can be determined by polling or ISR or (foolproof) by an external flip-flop.

Go Up