Welcome! Log In Create A New Profile

Advanced

Using pwm from servo signal to drive speed controller

Posted by jtoombs 
Using pwm from servo signal to drive speed controller
February 28, 2014 12:27AM
So the topic pretty much says it all. I have a brushless motor for a cnc spindle for light milling and I want to control it from the firmware. Can I just plug in the signal pin of my speed controller into the signal on the servo port and control it using existing code? Or do I need to set up my own case in the marlin main file?

Oh yeah by the way I'm using marlin.
Re: Using pwm from servo signal to drive speed controller
February 28, 2014 09:28AM
You may need to do some conditioning on the signal. The PWM output on Marlin could be the softPWM with a 7Hz period and a variable duty cycle, or a hardware fast PWM with a 30KHz or so, with 0/+5V ouput. If your speed controller can take that signal directly, then you can hook it. If not, you might need to filter the PWM into an analog signal and amplify it to match your speed controller's input.
Re: Using pwm from servo signal to drive speed controller
February 28, 2014 12:27PM
Thans for the reply Dave.

I read that most speed controllers receive a 50 Hz pulse rate. Could I change the pulse width in the servo.cpp file to make it pulse how I needed it and then just use the M280 command to send it a signal?
Re: Using pwm from servo signal to drive speed controller
February 28, 2014 05:07PM
I'm sorry, I didn't notice that you clearly said 'servo'--I was thinking about heaters and fans. If you are using the Servo.cpp stuff, it looks like it sets up its own timers and prescalers, so any adjustments you make there to match your own needs would probably be OK on the Marlin side. I don't know what control system your speed controller takes--if it takes 5V it should work, but if it takes 4-20mA, or some other voltage, it's a harder problem.

Something like [www.bodine-electric.com] that takes a 0-5V analog signal should work with 7Hz, 50Hz, or 30kHz PWM with an appropriate RC filter (this controller looks like it has a 15Kohm*47uF=0.7s RC filter built in).

I don't have experience with the servo code, so no guarantees.
Re: Using pwm from servo signal to drive speed controller
March 03, 2014 10:43PM
Re: Using pwm from servo signal to drive speed controller
March 03, 2014 11:45PM
Thanks for the link. It's too bad I'm using ramps otherwise that would be a great option for my situation. Do you have any idea how they work?
Re: Using pwm from servo signal to drive speed controller
March 04, 2014 11:03PM
I don't. I stumbled across it on RC groups [www.rcgroups.com] I did try to contact the guy a few weeks ago to get one for my foam cutting CNC with Mach3 but he never replied. If I can ever get my hands on one we will find out what's insidegrinning smiley
Re: Using pwm from servo signal to drive speed controller
March 05, 2014 08:39AM
Hey, I also have an rcgroups account! My cnc will also be used for cutting foam designs for new airplanes if I can ever finish it completely. It isn't totally necessary that I have the speed controller controlled by my ramps board but I dont want to have to plug in my receiver and turn on my transmitter every time I want to use my cnc. So I'll keep trying to mess around with the firmware. Bill do you know how to activate a servo port on a ramps board??? I can't even tell if they are sending a signal at all...
Re: Using pwm from servo signal to drive speed controller
March 08, 2014 09:48AM
Ok I have an update. I figured out how to control the ESC just using an arduino uno and some code that I changed from how I found it online. Now all I need to do is put the code in the firmware under a new "M" case so I can control it from pronterface.
Re: Using pwm from servo signal to drive speed controller
March 09, 2014 12:17AM
SOLVED!!! I finally got it! I simply used the code in the M280 case in the Marlin_Main.cpp for my case. It was much easier than I thought it would be. I also made a case to detach the pin my speed control is on to stop the motor.



#if NUM_SERVOS > 0
    case 601:
        int servo_index;
        int servo_position;
        if (code_seen('P'))
          servo_index = code_value();
        if (code_seen('S')) {
          servo_position = code_value();
          if ((servo_index >= 0) && (servo_index < NUM_SERVOS)) {
		      servos[servo_index].attach(11); //11 is the set of servo pins closest to the reset button
                      servos[servo_index].writeMicroseconds(700); //MIN pulse for speed controller
                      delay(4000);
                      servos[servo_index].writeMicroseconds(2000); //MAX pulse for speed controller
                      delay(100);
                      servos[servo_index].writeMicroseconds(700);
                      delay(1000);
                      servos[servo_index].writeMicroseconds(servo_position);
                      
          }
    
      
    }
    break;
#endif
    
    case 602:

        if (code_seen('P'))
          servo_index = code_value();
        
          if ((servo_index >= 0) && (servo_index < NUM_SERVOS)) {
		      servos[servo_index].detach();
                      
                      
          }
    
      
    
    break;

Might not be the cleanest modification of the firmware but it works!!! And I'm proud that I was able to do it.

I hope this is used by some other Marlin user out there that wants to do the same thing as me.
Re: Using pwm from servo signal to drive speed controller
March 09, 2014 01:30AM
great Job man. that helps me out a bunch. This was something I had on my list of things to do. What motor are you using. I have some Hacker A-30's and 40's laying around. Hackers have larger bearings than most and may be better suited for this. Also you can get ER-11 collet chucks on Ebay for 10-20 bucks. Will need to find/make and adapter to go from the 5 or 6mm motor shaft to the shortened collet shank. Too bad they don't make shanks small enough that would substitute as the motor shaft too. I need to pull a motor apart and see if it has enough room to accommodate 8mm shaft and bearings.
PS I don't know how to use ramps for servo control but supposedly it can be done but if the Uno is working, fine. a completely separate system (almost) for the spindle may not be a bad idea

Edited 2 time(s). Last edit at 03/09/2014 01:35AM by Bill Clark.
Re: Using pwm from servo signal to drive speed controller
March 09, 2014 11:03AM
Hey Bill, that code I provided in my last post was actually in the marlin firmware for my ramps board. I only used the uno to test the min and max writeMicroseconds for my specific motor and speed controller. You simply plug in the esc using only the ground and signal wires into the spot where the servo goes on the board. If you have any more questions about coding I would be glad to help.

Now for the motor. Since I am only using my cnc for light foam milling I simply replaced the shaft of one of my smaller motors with a 3 mm end mill. It works really well.
Re: Using pwm from servo signal to drive speed controller
March 09, 2014 02:00PM
Thanks. I'm sure I will have a question once I implement it.
I forgot you where cutting foam only. here's some of my foam. These were cut by hand though sad smiley [www.rcgroups.com]

Edited 1 time(s). Last edit at 03/09/2014 02:11PM by Bill Clark.
Re: Using pwm from servo signal to drive speed controller
March 09, 2014 04:44PM
Those planes look very high quality. Are they totally homemade? Paint and everything?

I'm hoping that I can cut balsa ribs for some planes too. That would be cool.
Re: Using pwm from servo signal to drive speed controller
March 09, 2014 06:06PM
Yes, everything was hand made or machined/molded, etc. Made paint mask and used cheap water based acrylics. I like the foam because I can design/sctratchbuild in a reasonable amount of time and the foam just flies so good because of light loading. Between the composite landing gear, pulley controls and other stuff I have around 100hrs in the 2 planes. What types of designs are you working on? scale, aerobatic, or exploring new frontiers?
Re: Using pwm from servo signal to drive speed controller
March 09, 2014 09:48PM
I'm hoping to do some scale type designs. Maybe old biplanes... I like how they fly. Also I want to design a vertical takeoff and landing plane with the help of my machine. I don't have that big of a cutting area so I don't know what I'll be able to accomplish but sometime in the future I kind want to switch over to 3d printing. The frame isn't really that strong but we'll see if I can make some upgrades to it.
Re: Using pwm from servo signal to drive speed controller
March 09, 2014 10:15PM
Ahhh, biplanes. If you scroll down through my blog here [www.rcgroups.com] you will see the 1929 4E Stearman (a few entries) I was part of the restoration on. I think if your machine is rigid enough for routing you should be good for 3D printing. Looks like you have some great projects in mind. Have fun
Sorry, only registered users may post in this forum.

Click here to login