Syncing up Arduinos

Advert

Syncing up Arduinos

Home Forums Electronics in the Workshop Syncing up Arduinos

Viewing 25 posts - 1 through 25 (of 45 total)
  • Author
    Posts
  • #216333
    Andy from Workshopshed
    Participant
      @andyfromworkshopshed

      I saw this in MEW 235, and I can't work out why it is needed.

      Advert
      #31815
      Andy from Workshopshed
      Participant
        @andyfromworkshopshed
        #216337
        Emgee
        Participant
          @emgee

          Andy

          A bit more info would help !!!!!!!!

          Emgee

          #216338
          Bob Mc
          Participant
            @bobmc91481

            Hi Andy…

            I wrote the article about using Arduino's …. if you need any information just let me know on this forum.

            ..rgds…Bob McMenemie.

            #216340
            Andy from Workshopshed
            Participant
              @andyfromworkshopshed

              Hi Bob,

              I understood the article on your electronic lead screw idea and understand how the common crystal approach works. But the bit I did not understand is why you needed to do that in the first place.

              Cheers,

              Andy

              #216353
              jason udall
              Participant
                @jasonudall57142

                I too saw this.
                And wondered why two arduino.
                Yes if using two then it provides a sync ( mostly) between the two processors .

                #216354
                Bob Mc
                Participant
                  @bobmc91481

                  Hi Andy… A good question…!

                  The reason why synchronisation of the two Arduino's is necessary is that the two motors (one drives the leadscrew and the other the Spindle), need to have their relative speeds constant, notice the term 'relative' .

                  For example if the required ratio of Spindle speed to Leadscrew speed was 1:4 then for 1 turn of the spindle there would be 4 turns of the leadscrew ; if the pitch of the leadscrew was 1mm then 4 turns would produce a pitch of 4mm on the work.

                  Now if the Arduino driving the leadscrew motor began to increase or decrease its speed relative to the Spindle motor speed, the ratio of 1:4 is altered and the required pitch on the work would no longer be 4mm.

                  It is an unfortunate fact that no matter how good the clock circuits are in any two microprocessor systems they will not keep in sychronisation if they are completely separate systems.

                  The Arduino can only provide a minimum clock pulse period of 1microsec duration, using two Arduino's the clock pulse rates will most certainly alter over time which is the root cause of the problem, and so by using only one clock for the two Arduino's the problem of clock drift is eliminated.

                  It might be thought that the difference in speeds would be so small that it really wouldn't amount to much, however when the work requires long pitches to be made all the errors begin to add up, If you have two Arduino's just try the Blink program with a 500ms delay period for switching the Leds on & off… it won't take long for the two Leds to be out of sync.

                  Hope that helps, if you need any more info I am only too glad to help.

                  rgds..Bob.

                  #216357
                  jason udall
                  Participant
                    @jasonudall57142

                    Thaks for taking the trouble to respond Bob .

                    I still wonder why two arduino .
                    why not one device .
                    3d printers have 4 co-ordinated axis. achived with a single processor.

                    Edited By jason udall on 14/12/2015 16:51:27

                    #216359
                    Andy from Workshopshed
                    Participant
                      @andyfromworkshopshed

                      Cheers Bob, that all makes sense. There's many ways to crack a nut and it's interesting to see other people's approaches.

                      Jason, I believe most Arduino based 3d printer drivers use the faster and more powerful Mega board. That also has more I/O so could drive 3 steppers.

                      Edited By Andy from Workshopshed on 14/12/2015 16:54:19

                      #216369
                      jason udall
                      Participant
                        @jasonudall57142

                        Andy…
                        Many three d printer do indeed use mega.

                        But my favourite arduino is the nano..
                        That has 14 digital I/o
                        3 at least are pwm hardware
                        It also has 8 analog inputs which can also be used as digital inputs.

                        To control stepper motors
                        You will need two bits per motor..ie four outputs..
                        That leaves at least ten pins for” ratio” say.
                        And two analog pins for “speed”..

                        But yes heaven forbid use a mega/ramps/stepper kit.. ?32 for 1A stepper

                        #216373
                        Andy from Workshopshed
                        Participant
                          @andyfromworkshopshed

                          Yes, a single Arduino Uno has enough I/O to handle the motors and still have pins left for control signals. I did like Bob's trick of using an analogue input with a resistor ladder to provide the control input.

                          My favourite Arduino is the Pro Micro

                          I used one in my clock project, controlling a couple of stepper motors directly (4 pins each) and getting the time from an RTC module (2 pins).

                          Topsy Turvy Clock

                          #216374
                          Bob Mc
                          Participant
                            @bobmc91481

                            Hi Jason…. another good question..!

                            Andy has hit the nail on the head in his response.

                            Basically use could have been made of a more powerful processor which would in principle have the capability of providing 2 sets of independent clock pulses from the one processor…. however and unfortunately the Arduino can't do this.

                            I have to admit that although I worked in electronics for many years I was not involved in programming.

                            I decided some time ago that it was rather pointless to start learning programming when I had so many other things to take up my time and interest.

                            the Arduino programming was however much simpler and the open source ideology along with the many forums and articles makes the whole thing less daunting than trying to get to grips with full blown programming.

                            As stated in the article… 'there are I am sure other ways of doing this' … and I have recently been told that one of the Atmel processors is capable of providing the required pulses, but I have not pursued it.

                            My idea in using this system of two Ard'os just kept it simple and easy to understand although wiring up for one clock is not the easiest thing to do.

                            If you are really considering having a go, I would try to do the wiring of the xtal clock circuit done first and test it using the 'Blink' program … if the two Leds keep in sync over a minute or so…you are in business…!

                            The other thing that didn't come out in the article very well was the fact that if there are any overall errors in the leadscrew pitch, this can be accommodated with the system and as stated my leadscrew is just a piece of threaded rod, ….will provide details if you need them.

                            Please remember that this is a 'model engineering project' and although I have produced a number of different threaded items such as a spindle end nut for my Atlas lathe, the spindle motor of 3.1Nm is not really capable of taking deep cuts and an amount of experimentation is needed to determine what it will actually cut, in hindsight I should have fitted the next higher power of stepper motor, something of the order of 5Nm, the drivers I mentioned are capable of powering a motor of that size.

                            Any more info required….. I am only too pleased to help.

                            rgds…Bob.

                            #216376
                            Muzzer
                            Participant
                              @muzzer

                              I had no idea why you would bother synchronising 2 Arduinos and certainly wouldn't have dreamt of connecting the oscillator pins together like that. Actually a fair chance of them not working correctly with this arrangement.

                              What accuracy are the crystals? And what accuracy do you think is required?

                              Normally crystals are so accurate you'd have difficulty measuring them with normal instruments. Sorry to sound negative but it all seems rather bizarre.

                              #216378
                              jason udall
                              Participant
                                @jasonudall57142

                                Thanks
                                So in summary.
                                It was the processing power limitation that indicated dual processor
                                Which in itself required the common processor clock.

                                And the all thread leadscrew …well..metric lead screw is 60degree anyway.
                                And as to the pitch accuracy …how do you think all thread is made?

                                I find if you use a long enough “nut”..many of the worries come to nought
                                High quality ( stainless )seems to be better cut..

                                #216380
                                jason udall
                                Participant
                                  @jasonudall57142

                                  Normal micro crystals are 10’s of ppm

                                  10 micron in a meter?
                                  Btw ever read the step “error” figue for a stepper?
                                  Yes 200 per rev..but are they equally spaced..

                                  Edited By jason udall on 14/12/2015 18:56:26

                                  #216381
                                  jason udall
                                  Participant
                                    @jasonudall57142

                                    Watch crystals. ..
                                    Seconds per week
                                    (1:604800)

                                    #216391
                                    Muzzer
                                    Participant
                                      @muzzer

                                      36 pence to replace the ceramic resonator fitted to some Arduinos with a 30ppm crystal – 0.003%

                                      #216395
                                      Andy from Workshopshed
                                      Participant
                                        @andyfromworkshopshed

                                        On a related note there's a project called the "electronic lead screw" which does something very similar although I think there are rather too many buttons on the control panel.

                                        http://autoartisans.com/ELS/

                                        #216425
                                        frank brown
                                        Participant
                                          @frankbrown22225

                                          .003% sounds very accurate, so I wondered what this would mean in real life. So lets take the spindle as the reference, not disengaging the half nuts and cutting 2" of 40 TPI thread. If the leadscrew is running slow by the .003%, then after the first cut the linear position of the tool would be .003% short of where it should be. i.e. towards the tailstock if cutting towards the chuck. Then running the lathe backwards to get back to the starting position, would also mean that the carriage would run 2" – .003% towards the tailstock which neatly coincides with its starting position. So the error is non accumulative. So the thread will compress by .00006" over 2" this would be extremely accurate!

                                          If the lathe could not reverse, so the half nuts have to be disengaged, then the error is accumulative, both on the cut and the number of spindle rotations for winding the carriage back. So if you can wind the carriage back four times faster then the cutting speed and you need 5 cuts to complete the thread then the total error would be 5 times 1.2 times 2" times .003% , still not a lot. But if the spindle was left running half way through the thread cutting exercise while you have a cup of tea, the errors would become gross.

                                          Frank

                                          #216426
                                          frank brown
                                          Participant
                                            @frankbrown22225

                                            Second thoughts :- switching the motors to reverse could (will) cause all sorts of problems as the run down of an unpowered pair of motors with different mechanical loading would result in them becoming mechanically out of synchronisation, even if the electrical drives pulses are still synced up. Or just switch off the spindle drive and hope that the leadscrew drive remains in sync. right down to zero speed (so it stops) and will remain in sync when the spindle is restarted in the opposite direction. This sounds like a problem that can not be 100% solved, and disengaging the half nuts is the way to go.

                                            Frank

                                            #216471
                                            SillyOldDuffer
                                            Moderator
                                              @sillyoldduffer

                                              Bob's use of a single crystal to drive two oscillators was new to me, but hey it worked!

                                              Using two Arduinos rather than one is apparently easier because of a limitation in the standard Arduino library, which is that the tone() function can only be used on one output at a time. Bob's project needs two outputs.

                                              There are alternatives that don't require board surgery.

                                              It is possible to synchronise two Arduinos using the code below, but they drift apart over time. I tested the code using a Duemilanove and a Mega2560. An oscilloscope shows that the Arduino's start exactly in step but drift apart thereafter. For a nominal 400Hz the Mega2560 outputs 400.7Hz whilst the Duemilanove outputs 400.64Hz. Their 16000kHz crystals are oscillating at slightly different frequencies (16000.30kHz and 16000.48kHz). For Bob's application I doubt this would matter, but his solution fixes that problem.

                                              const int input_sync_pin = 6;
                                              const int output_sync_pin = 7;
                                              const int tone_out_pin = 8;
                                              const int led_pin = 13;

                                              void setup() {
                                              // put your setup code here, to run once:
                                              pinMode( input_sync_pin, INPUT_PULLUP );
                                              pinMode( output_sync_pin, OUTPUT );
                                              digitalWrite( output_sync_pin, LOW );
                                              while ( digitalRead( input_sync_pin ) == HIGH )
                                              {
                                              ; // Waiting
                                              }
                                              // Synchronised now
                                              pinMode( led_pin, OUTPUT );
                                              digitalWrite( led_pin, HIGH );
                                              }

                                              void loop() {
                                              // put your main code here, to run repeatedly:
                                              tone( tone_out_pin, 400 );
                                              }

                                              Connect GND to GND, and pin 7 on one to pin 6 on the other, twice.

                                              Another way is to use one Arduino to produce two tones at the same time. This is possible by installing the third-party library at *LINK*. The library needs a small fix before it will work. After installing the library, find the file "Tone.cpp" and edit it. Change the line reading "#include <wiring.h>" to "#include <Arduino.h>" Don't forget to tell the Arduino IDE to use this library.

                                              The tones produced by this example program are based on the same clock and are closely synchronised.

                                              #include <Tone.h>

                                              Tone t1;
                                              Tone t2;

                                              int f1 = 500; // Hz
                                              int f2 = 1000; // Hz

                                              void setup() {
                                              // put your setup code here, to run once:
                                              t1.begin(6); // Tone1 Output on pin 6
                                              t2.begin(7); // Tone2 Output on pin 7

                                              t1.play(f1);
                                              t2.play(f2);
                                              }

                                              void loop() {
                                              // put your main code here, to run repeatedly:
                                              // Example increases Tone2 by 1000Hz after a second. Resets to 1000Hz when the output is higher than 65kHz
                                              // Tone1 stays at 500Hz. The two tones are output on different pins at the same time.

                                              delay(1000); //mS

                                              f2 = f2 + 1000;
                                              if ( f2 > 65000 )
                                              f2=1000;
                                              t2.play(f2);

                                              }

                                              Microcontrollers like the Arduino offer lots of opportunity to model makers. It's probably heresy but I think a well-built steam engine using an Arduino with sensors to control valve events and boiler pressure etc would be rather more efficient than a mechanical equivalent. I wish my workshop skills were up to it!

                                              Kudos to Bob for having a go.

                                              Regards,

                                              Dave

                                              #216474
                                              Muzzer
                                              Participant
                                                @muzzer

                                                Just get an Arduino Due for £30 or so and be done with it. 54 lines of digital IO plus 12 ADC and 2 true DAC, 32 bit ARM Cortex-M3, 84MHz clock – and the same footprint and pinout as the Uno (with some additional pins obviously). No need to synchronise anything, bags of power. No brainer.

                                                There are quite a few versions of the Arduino around, so choosing the right one seems sensible unless you like cutting the grass with scissors or your hair with a lawnmower.

                                                There are several examples where the leadscrew is synchronised with the spindle like this. There's a post above to another such embodiment. This "electronic leadscrew" approach seems like a pretty versatile concept.

                                                Murray

                                                #216475
                                                Michael Gilligan
                                                Participant
                                                  @michaelgilligan61133

                                                  Bob Mc

                                                  May I just say thanks for the article star

                                                  This discussion about Arduino synch issues is interesting, but the big thing for me is that you have produced something that successfully replaces change-wheels.

                                                  Good on you, Sir.

                                                  MichaelG.

                                                  .

                                                  P.S. for convenient reference **LINK**

                                                  #216488
                                                  jason udall
                                                  Participant
                                                    @jasonudall57142

                                                    I too would like to say to Bob congrats on the project.

                                                    Creative adaption to solve the requirements of syncing the arduino

                                                    As you yourself said there will be other ways of achieving the electronics bit.
                                                    But your solution met your needs and as such may prove inspiring to others.

                                                    #216492
                                                    Andy from Workshopshed
                                                    Participant
                                                      @andyfromworkshopshed

                                                      Definitely inspired me, although it might be the end of 2016 before I get to electronics in the workshop. Got some other projects to complete first.

                                                    Viewing 25 posts - 1 through 25 (of 45 total)
                                                    • Please log in to reply to this topic. Registering is free and easy using the links on the menu at the top of this page.

                                                    Advert

                                                    Latest Replies

                                                    Viewing 25 topics - 1 through 25 (of 25 total)
                                                    Viewing 25 topics - 1 through 25 (of 25 total)

                                                    View full reply list.

                                                    Advert

                                                    Newsletter Sign-up