0
Offline
Sr. Member
Karma: 0
Posts: 340
Arduino rocks
|
 |
« on: May 18, 2012, 04:38:10 pm » |
The project is just a laser rapidly switching on and off pointed at a spinning mirror. I'm using the Digital > BlinkWithoutDelay example sketch and have the delay set to zero. The problem is the dashes created by the spinning motor are still not short enough. I can either fix this by getting a lower rpm motor or getting the laser to blink faster. Am I already at the limit of the 16MHz clock speed by setting the delay to 0 in the example sketch? 
|
|
|
|
|
Logged
|
|
|
|
|
Manchester (England England)
Offline
Brattain Member
Karma: 277
Posts: 25501
Solder is electric glue
|
 |
« Reply #1 on: May 18, 2012, 05:31:33 pm » |
Am I already at the limit of the 16MHz clock speed by setting the delay to 0 in the example sketch? No, you are using millisecond delay as your delay unit. You can get faster than this. If I were doing this I would use timer 2 to set a PWM frequency, this is steady and can go much faster than the 500 HZ a millisecond toggle will give you.
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Sr. Member
Karma: 0
Posts: 340
Arduino rocks
|
 |
« Reply #2 on: May 18, 2012, 05:46:05 pm » |
I'm now using PWM like you suggested. analogWrite(laserPin, 10); for example makes a nice, short dash but I need the short dashes much closer together and I need to be able to control which dashes are there and not there to make a user defined pattern. Am I correct to say that that is not possible with PWM?
|
|
|
|
« Last Edit: May 18, 2012, 05:57:37 pm by David82 »
|
Logged
|
|
|
|
|
UK
Offline
Tesla Member
Karma: 89
Posts: 6388
-
|
 |
« Reply #3 on: May 18, 2012, 07:37:35 pm » |
What sort of blink timing are you trying to generate i.e. how fast do you need the on/off transitions, and how accurately do you need them timed?
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Sr. Member
Karma: 0
Posts: 340
Arduino rocks
|
 |
« Reply #4 on: May 18, 2012, 08:00:35 pm » |
The device (laser pointed at a spinning mirror) will be about 3-4 ft above a 4ft long flat surface and need to project about 90 dots along, and confined within, that 4ft surface. Each dot must be able to be turned on or off individually. I also need to be able to set the individual spacing of each dot relative to the dot beside it. Some dot pairs will be spread out further apart than others.
PWM is close to being fast enough but I can't control the amount of time on AND the amount off time off like I need. Is the arduino just not good enough to do this?
|
|
|
|
« Last Edit: May 18, 2012, 08:04:39 pm by David82 »
|
Logged
|
|
|
|
|
UK
Offline
Tesla Member
Karma: 89
Posts: 6388
-
|
 |
« Reply #5 on: May 18, 2012, 08:40:43 pm » |
I have no idea. Can you explain all that again please, but this time in terms of the timing requirements? I really don't care how far away the bits are.
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Sr. Member
Karma: 0
Posts: 340
Arduino rocks
|
 |
« Reply #6 on: May 18, 2012, 08:56:45 pm » |
analogWrite(laserPin, 10); for example makes a nice, short dash depending on the rpm of the motor.
the value can be 0-255. If "10" is used, it is on for 10 clicks and then off for 245 clicks. I need it to be on 5 clicks, and off 5 clicks, then repeat. Do you see what I mean?
|
|
|
|
« Last Edit: May 18, 2012, 09:00:43 pm by David82 »
|
Logged
|
|
|
|
|
0
Offline
Sr. Member
Karma: 0
Posts: 340
Arduino rocks
|
 |
« Reply #7 on: May 19, 2012, 12:03:43 pm » |
Am I not clear? Is this a really difficult problem to solve?
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
UK
Offline
Brattain Member
Karma: 138
Posts: 19066
I don't think you connected the grounds, Dave.
|
 |
« Reply #8 on: May 19, 2012, 01:09:41 pm » |
analogWrite(laserPin, 10); for example makes a nice, short dash depending on the rpm of the motor. You know the PWM frequency and the duty cycle, so the pulse length should be a simple calculation.
|
|
|
|
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
Manchester (England England)
Offline
Brattain Member
Karma: 277
Posts: 25501
Solder is electric glue
|
 |
« Reply #9 on: May 19, 2012, 01:42:36 pm » |
It is a matter of synchronising the PWM output to the motor rotation. There are many ways of doing this. One is with a sensor for each rotation, an other is using a phase locked loop to synchronise the motor speed to the PWM frequency.
You can change the PWM frequency to be much faster than the default.
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Sr. Member
Karma: 0
Posts: 340
Arduino rocks
|
 |
« Reply #10 on: May 19, 2012, 02:51:33 pm » |
You guys are misunderstanding the current problem a little. I'm not worried about alignment yet. Let me rephrase it this way; I need to figure out what code would give me the absolute shortest, most frequent pulses on an output pin. Imagine a square wave on an oscilloscope. I need to compress that wave as far as the arduino can handle. I need it to blink/pulse as fast as it possibly can.
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
UK
Offline
Brattain Member
Karma: 138
Posts: 19066
I don't think you connected the grounds, Dave.
|
 |
« Reply #11 on: May 19, 2012, 02:54:10 pm » |
I need to figure out what code would give me the absolute shortest, most frequent pulses on an output pin. Direct port manipulation should get you up to a few mega Hertz. Occasional glitch for timer overflow interrupts, though.
|
|
|
|
« Last Edit: May 19, 2012, 03:03:30 pm by AWOL »
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
0
Offline
Sr. Member
Karma: 0
Posts: 340
Arduino rocks
|
 |
« Reply #12 on: May 19, 2012, 02:56:42 pm » |
That's cool.. I have no idea what the code is for that though.
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
UK
Offline
Brattain Member
Karma: 138
Posts: 19066
I don't think you connected the grounds, Dave.
|
 |
« Reply #13 on: May 19, 2012, 03:04:45 pm » |
Some good search terms though
|
|
|
|
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
0
Offline
Sr. Member
Karma: 0
Posts: 340
Arduino rocks
|
 |
« Reply #14 on: May 19, 2012, 03:13:07 pm » |
I found this http://www.arduino.cc/en/Reference/PortManipulation but the example isn't as helpful as I need it to be.
|
|
|
|
« Last Edit: May 19, 2012, 03:14:41 pm by David82 »
|
Logged
|
|
|
|
|
|