586,657 active members*
3,360 visitors online*
Register for free
Login
Page 1 of 2 12
Results 1 to 20 of 28
  1. #1
    Join Date
    Oct 2006
    Posts
    735

    Brushless c code example with snap amp

    Looking to get my first servo spinning and activated properly.

    And was hoping to get a few simple C code examples to activate it and jog around abit with Kcnc.

    I have 2 snap amps. Servo is connected to Channel 8 of snap 0

    Using CHA_DIFFPLUS_0 and CHA_DIFFMINUS_0 for encoder A signal connected
    and CHA_DIFFPLUS_1 CHA_DIFFMINUS_0 and for encoder B signal connected
    and using CHA_DIFFPLUS_2 (Bit 68) for the I signal (signal that pulses once per revolution)

    servo is connected to axis 0 out0,out1 & out2

    Servo has a 8000 pulse per rev encoder.

    For some reason when I run the phasefind program, my servo does not spin 2 full rotations as the description says, also does not always spin past where I know the rotation pulse I would be, so a little confused about that. Can get it to spin longer if I increase the ignore parameter


    In anycase hope this is pretty simple configuration and once past this example can replicate for the other axis and run some tuning


    I have had a dynomotion board running another machine with Kanalog running a 4 analog moog drives. Had a lot of help (and guess I've forgotten alot) of how to set things up in the 2 years since I did that.

    b

  2. #2
    Join Date
    Oct 2006
    Posts
    735
    Also, forgot about the configuration and flash screens

    So would like to confirm that these settings would be correct for my setup

    Channel 0 would be configured for snap 0

    Encoder input

    3 phase brusheless

    Wouls be Input channel 8. Since I'm using cha_diffplus_0

    And output channel 8 as well

    And that would be downloaded to the k and eventually repeated for the other axis with changes to input and output channels, 10 for the second of snap 0 and then 12 & 14 for snap 1

    Hope that sounds correct
    B

  3. #3
    Join Date
    May 2006
    Posts
    4047
    Hi Bill,

    That all sounds correct. But we need to get the Phase Finding working first.

    It should rotate ~two full turns both ways. Please post what it reports that could provide clues.

    There are basically two requirements for this to rotate properly. #1 energizing current in the coils should cause the motor to rotate (sort of like a stepper motor rotates open loop), #2 the index pulse must be detected at the right place.

    I like your idea to increase the ignore. Change from 300 to 300000000 (add 6 zeros). That should cause the motor to rotate forever. Does it?

    change

    int k=0,i,dk=1,WhichSnap,WhichClamp,WhichClampEnable,i gnore=300,kpos[Ncycles],zmark,m=0;

    to
    int k=0,i,dk=1,WhichSnap,WhichClamp,WhichClampEnable,i gnore=300000000,kpos[Ncycles],zmark,m=0;

    Regards
    TK
    http://dynomotion.com

  4. #4
    Join Date
    Oct 2006
    Posts
    735
    Hello

    I have changed the code to list the ignore parameter to console.. and yes I have done ignore to 3000 or so. And in that case the console scrolls down the ignore number till it repeats 0 for a while then re-countes (I have the other paramter that resets the ignore to 3000 as well.

    When I do this the servo rotates nice and smooth many rotations back and forth

    does not always reverse direction at the point in the rotation where I know the phase signal is Not sure if it should..

    If I reduce the ignore down to the stock 300 it rotates perhaps a 1/4 turn one way then maybe a half the other way.

    Here are a couple of the report results.. Hopefully this looks right.



    .

    REPORT ignore 300
    ------
    0 Position = -920 PhaseAngle = 0.332000
    1 Position = -1610 PhaseAngle = 0.673000
    2 Position = -952 PhaseAngle = 0.321000
    3 Position = -311 PhaseAngle = 0.001000
    4 Position = 362 PhaseAngle = -0.340000
    5 Position = 1026 PhaseAngle = -0.667000
    6 Position = 1695 PhaseAngle = -1.001000
    7 Position = 2303 PhaseAngle = -1.310000
    Counts per rev = -690
    Counts per cycle = -2023
    Counts per cycle (rounded)= -2020
    invDistPerCycle (rounded)= -0.000495049505
    Commutation offset = -499
    Input Gain Specified = 1.000

    REPORT 300
    ------
    0 Position = -1203 PhaseAngle = 0.320000
    1 Position = -2075 PhaseAngle = 0.758000
    2 Position = -1305 PhaseAngle = 0.348000
    3 Position = -572 PhaseAngle = -0.019000
    4 Position = 59 PhaseAngle = -0.341000
    5 Position = 711 PhaseAngle = -0.659000
    6 Position = 1698 PhaseAngle = -1.150000
    7 Position = 2373 PhaseAngle = -1.492000
    Counts per rev = -872
    Counts per cycle = -1991
    Counts per cycle (rounded)= -1990
    invDistPerCycle (rounded)= -0.000502512563
    Commutation offset = -603
    Input Gain Specified = 1.000

    REPORT 300
    ------
    0 Position = -1558 PhaseAngle = 0.312000
    1 Position = -2169 PhaseAngle = 0.618000
    2 Position = -1599 PhaseAngle = 0.306000
    3 Position = -976 PhaseAngle = -0.005000
    4 Position = -230 PhaseAngle = -0.384000
    5 Position = 639 PhaseAngle = -0.814000
    6 Position = 1332 PhaseAngle = -1.155000
    7 Position = 2203 PhaseAngle = -1.593000
    Counts per rev = -611
    Counts per cycle = -1997
    Counts per cycle (rounded)= -2000
    invDistPerCycle (rounded)= -0.000500000000
    Commutation offset = -424
    Input Gain Specified = 1.000

    REPORT 3000
    ------
    0 Position = -5487 PhaseAngle = 3.175000
    1 Position = -11759 PhaseAngle = 6.311000
    2 Position = -5637 PhaseAngle = 3.221000
    3 Position = 449 PhaseAngle = 0.178000
    4 Position = 7486 PhaseAngle = -3.343000
    5 Position = 13712 PhaseAngle = -6.453000
    6 Position = 20001 PhaseAngle = -9.593000
    7 Position = 26456 PhaseAngle = -12.824000
    Counts per rev = -6272
    Counts per cycle = -2000
    Counts per cycle (rounded)= -2000
    invDistPerCycle (rounded)= -0.000500000000
    Commutation offset = -1032
    Input Gain Specified = 1.000

    REPORT 3000
    ------
    0 Position = -5921 PhaseAngle = 3.164000
    1 Position = -12030 PhaseAngle = 6.222000
    2 Position = -6008 PhaseAngle = 3.179000
    3 Position = 68 PhaseAngle = 0.139000
    4 Position = 6657 PhaseAngle = -3.146000
    5 Position = 13187 PhaseAngle = -6.421000
    6 Position = 19345 PhaseAngle = -9.494000
    7 Position = 25530 PhaseAngle = -12.586000
    Counts per rev = -6109
    Counts per cycle = -1998
    Counts per cycle (rounded)= -2000
    invDistPerCycle (rounded)= -0.000500000000
    Commutation offset = -901
    Input Gain Specified = 1.000

  5. #5
    Join Date
    May 2006
    Posts
    4047
    Hi Bill,

    So the motor phase rotates properly but the index signal is all wrong for some reason.

    It almost looks like the hall sensor signals which occur ~ every 1/3 phase cycle. Maybe there is some cross talk or something?

    You really shouldn't print things within the AutoPhaseFind.c loop because that will change the timing and possibly even block execution which might cause the program to miss the index pulse. But that wouldn't explain catching extra index pulses.

    Here is a little program that just prints "Index" (and blinks a KFLOP LED) every time the Index pulse is detected. Change the bit number to whatever you are using if not 68.

    Code:
    #include "KMotionDef.h"
    
    main()
    {
        for (;;)
        {
            if (ReadBit(68))
            {
                SetBit(46);
                printf("Index\n");  // send message to console
                Delay_sec(0.5);
                ClearBit(46);
            }
        }
    }
    Then just rotate the motor by hand. Check if the index pulse happens at exactly one place in a rotation.

    Regards
    TK
    http://dynomotion.com

  6. #6
    Join Date
    Oct 2006
    Posts
    735
    Ok.. Tried the code, and long as I don't spin it to fast it picks it up and lights the LED every time it passes in either direction.

    Spinning around the same speed the find program rotates it, the LED lights no problem.

    I am reading bit 68, which have the diffA+ connected to that with the 180 ohm resistor from diffA+ (bit 68) to the diffA- . I have tried it with out the resistor connected in the past with the find program and results are the same.

    b.

  7. #7
    Join Date
    May 2006
    Posts
    4047
    Hi Bill,

    That sounds like it is working correctly.

    Maybe there is only noise when the motor is energized?

    You might run that little program in another thread at the same time as the AutoPhaseFind program to check for flashes at the wrong spots. It isn't a perfect test because the two programs look at the Index at slightly different times so say a 1us glitch might be seen by one program and not the other. But if it does sometime flash the LED at the wrong spot it will prove there is noise.

    You might do a sanity check that something is really coming in the input and causing the program to reverse by disconnecting the input. It should then rotate forever.

    Do you have a scope? Strange a differential input would be so susceptible to noise. Are the cables shielded? Is the motor body earth grounded?

    You might try like a 0.1~.5uF ceramic filter capacitor across the 180ohm termination resistor. That should filter glitches less than ~20us out.

    Regards
    TK
    http://dynomotion.com

  8. #8
    Join Date
    Oct 2006
    Posts
    735
    I want to say, it would spin for ever with no connection (tried in the past but will give it another look to confirm)

    I unfortunately don't have access to a scope just now. But also do the .1uf cap trick all the time.

    Thanks.

  9. #9
    Join Date
    May 2006
    Posts
    4047
    Oh, something that may help watching by eye would be to slow the rotation way down by increasing the delay between incrementing the phase angle:

    Delay_sec(0.001); // wait a millisecond

    Regards
    TK
    http://dynomotion.com

  10. #10
    Join Date
    Oct 2006
    Posts
    735
    As you suspected, blinks at random while rotating/energized... Also the servo gets pretty hot sitting there after a while, was going to ask you about that. The fet temp has not gone over 25c reported though

    Will look what it does with the cap added across the resistor.

    Far as the setup, this is just on the bench at this point. So from the connector to servo I have, about 3" of pololu wires to my breakout, about 3" from there to the servos plug and then the servo connector cable is maybe 8" worth.

    . The servo basicly just has 3 connect for power in.

    There is a ground wire connected for the encoders.

    2 other connections called DRAIN x3, P DRAIN and DRAIN 1x E DRAIN are 2 connections which I'm not sure what they are, tempted to put them to ground though

    Guessing e drain is the encoder drain? I have connected P drain to ground (seeing it is a larger clear wire, which looks like a main ground cable and nothing improved.

    b.

  11. #11
    Join Date
    May 2006
    Posts
    4047
    Hi Ben,

    Actually I attached the motor/encoder spec you sent me a while ago and I don't see that the Index signal is a differential signal. How did you wire it? I also assume you supplied +5V.

    Also the servo gets pretty hot sitting there after a while, was going to ask you about that.
    You can reduce the amplitude the the coils are driven while phase rotating by changing this definition:

    #define AMPLITUDE 10 // Set how hard to drive the coils pwm counts

    regards
    TK
    http://dynomotion.com

  12. #12
    Join Date
    Oct 2006
    Posts
    735
    Ok.. Cap does not do anything,



    once the program is finished and you can rotate the servo again, the residual mag or what ever does make it dificult to rotate, even with the power supply off it is dificult to rotate for a long while, during that time rotating it manually also causes the random blink. Connected another servo (of same make/model) with identical results.

    ... anyone else using Teknic Hudson servos out there? Figured these are pretty common (used by several places making CNC machines)

    b.

  13. #13
    Join Date
    Oct 2006
    Posts
    735
    Yes that is the servo type..
    And have run amplitude 10 think that was the default. currently it might be higher but I was not rotating right before because my phases were not all connected right before. Will lower it back down and see if that helps.


    I have the differentals
    A to diffA+_0 pin 15
    A~ to DiffA-_0 Pin 16
    B to diffB+_0 pin 17
    B~ to DiffB-_0 pin 18

    Then i skip diff A & B 1 (which in theory I would connect to another servo soon)

    And have signal I connected to pin 23 diffA+_2 which should be bit 68 with a 180ohm to the DifdA- pin 24 and also included .1uf from 23 to 24 to try

    b

  14. #14
    Join Date
    Oct 2006
    Posts
    735
    5v and ground is supplied from the 47 and 49 pins of the snap

  15. #15
    Join Date
    Oct 2006
    Posts
    735
    Lowered the phase to 10 and 8, just makes the rotation strength pretty weak and slower. But still blinkey blink on the I index detector..

    So It is not a differential signal on the I (knew that) so guessing I should just connect to one of the opto's or other IO .. So where to connect, is a series resistor to reduce current or voltage from the I signal needed or other..

    Thanks.

    b.






    Guess just let me know which one and I'll be through this stage..

  16. #16
    Join Date
    May 2006
    Posts
    4047
    Hi Ben,

    I'm sure that is the problem. You can not connect a single ended signal up to a differential input. A differential signal must have the complementary signal (I~) driven in the opposite manner to work properly. With it left floating the results will be unpredictable. I'm surprised this motor has differential output on A and B but not I.

    So just connect I up to one of SnapAmps single ended inputs. Like SnapAmp IO0 (SnapAmp JP7 pin 1) this will be IO 80 in the KFLOP C program. SnapAmp has 5V tolerant inputs so you can connect it directly. Place your 180 ohm termination resistor from the input to SnapAmp GND. Hopefully the encoder's single end output can drive a 180 ohm load. I don't see any specification.

    Regards
    TK
    http://dynomotion.com

  17. #17
    Join Date
    Oct 2006
    Posts
    735
    Ok. was thinking about this before but thought perhaps the resistor to A- help the differential.

    Will go play now and let ya know. I can get a different size resistor as well. Just don't have any 150's handy (a size you mentioned in the past.) Have 120's though.

    .

  18. #18
    Join Date
    Oct 2006
    Posts
    735
    Ok Connected I signal to pin 1 and 180ohm to Snap ground, changed the detection code in thread 2 to io bit 80 as well as the find code to 80

    Still get the same results (random blink ish on rotation) Tried with the ground removed and with cap parallel with resistor with same results...

    Hmmm

    b.

  19. #19
    Join Date
    Oct 2006
    Posts
    735
    Here are my find report numbers with the ignore at 300.. Running it alone with out all the extra prints and the other thread running (blinking the LED)

    I want to say it looks like it is doing this correctly now. Rotates one way then the other for a couple turns

    REPORT 300
    ------
    0 Position = -486 PhaseAngle = 0.724000
    1 Position = -8487 PhaseAngle = 4.724000
    2 Position = -6280 PhaseAngle = 3.444000
    3 Position = -4262 PhaseAngle = 2.431000
    4 Position = -2554 PhaseAngle = 1.567000
    5 Position = 3983 PhaseAngle = -1.683000
    6 Position = 5446 PhaseAngle = -2.433000
    7 Position = 7703 PhaseAngle = -3.553000
    Counts per rev = -8001
    Counts per cycle = -2000
    Counts per cycle (rounded)= -2000
    invDistPerCycle (rounded)= -0.000500000000
    Commutation offset = 332
    Input Gain Specified = 1.000

    REPORT 300
    ------
    0 Position = -197 PhaseAngle = 0.727000
    1 Position = -2259 PhaseAngle = 1.759000
    2 Position = -1956 PhaseAngle = 1.436000
    3 Position = 6 PhaseAngle = 0.444000
    4 Position = 2277 PhaseAngle = -0.683000
    5 Position = 4043 PhaseAngle = -1.572000
    6 Position = 5743 PhaseAngle = -2.433000
    7 Position = 10047 PhaseAngle = -4.569000
    Counts per rev = -2062
    Counts per cycle = -1998
    Counts per cycle (rounded)= -2000
    invDistPerCycle (rounded)= -0.000500000000
    Commutation offset = -695
    Input Gain Specified = 1.000

    REPORT 300
    ------
    0 Position = -228 PhaseAngle = 0.724000
    1 Position = -2263 PhaseAngle = 1.737000
    2 Position = 3696 PhaseAngle = -1.433000
    3 Position = 5972 PhaseAngle = -2.562000
    4 Position = 9985 PhaseAngle = -4.567000
    5 Position = 11696 PhaseAngle = -5.433000
    6 Position = 14263 PhaseAngle = -6.697000
    7 Position = 16013 PhaseAngle = -7.575000
    Counts per rev = -2035
    Counts per cycle = -2009
    Counts per cycle (rounded)= -2010
    invDistPerCycle (rounded)= -0.000497512438
    Commutation offset = 197
    Input Gain Specified = 1.000

    REPORT 300
    ------
    0 Position = -4228 PhaseAngle = 0.719000
    1 Position = -8241 PhaseAngle = 2.724000
    2 Position = -4315 PhaseAngle = 0.566000
    3 Position = 3683 PhaseAngle = -3.433000
    4 Position = 6228 PhaseAngle = -4.686000
    5 Position = 7976 PhaseAngle = -5.564000
    6 Position = 9947 PhaseAngle = -6.556000
    7 Position = 11683 PhaseAngle = -7.433000
    Counts per rev = -4013
    Counts per cycle = -2001
    Counts per cycle (rounded)= -2000
    invDistPerCycle (rounded)= -0.000500000000
    Commutation offset = -790
    Input Gain Specified = 1.000

  20. #20
    Join Date
    May 2006
    Posts
    4047
    Hi Bill,

    I'm afraid it still is not correct at all.

    The positions are the encoder position where the index pulse was observed. If there are 4000 counts per rev then the difference between the position should all be +/-4000 counts (within maybe 2 or 3 counts depending on the accuracy of the index).

    The computed commutation offsets should all be very similar.

    There are a few cases where it looks like it is close to being correct but mostly it makes no sense.

    The program was written to find 2 index pulses in the forward direction and 2 in the reverse direction. Looks like you modified it to do a few more.

    If it is physically rotating the correct amount then the Index is probably working. The problem would then be in the encoder counting.

    Check the encoder by manually moving it around and observe the position on the Axis Screen. It should make sense. That is a full rotation should always change by 4000 (or whatever). Moving back to the same spot should always be the same encoder position.

    I see there is an option for that encoder to either have the differential outputs for A and B or not. Maybe yours doesn't have the differential option? It would be easy to tell with a scope or voltmeter. Do the A~ and B~ signals toggle properly from at least 3V to less than 0.4V? And in a complementary manner than the positive signals?

    Regards
    TK
    http://dynomotion.com

Page 1 of 2 12

Similar Threads

  1. Snap Grid
    By harlen.shaw in forum BobCad-Cam
    Replies: 2
    Last Post: 10-07-2011, 12:41 AM
  2. Snap Grid
    By harlen.shaw in forum BobCad-Cam
    Replies: 2
    Last Post: 10-05-2011, 03:55 PM
  3. Snap on Dimension
    By keith20mm in forum Dolphin CAD/CAM
    Replies: 3
    Last Post: 10-13-2009, 05:48 PM
  4. Snap-On consumables
    By Captain Midnigh in forum Waterjet General Topics
    Replies: 2
    Last Post: 01-06-2007, 08:22 AM
  5. Brushless DC servos VS. Brushless R/C motors
    By sp1nm0nkey in forum Servo Motors / Drives
    Replies: 1
    Last Post: 03-07-2006, 04:37 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •