Need help setting PWM input

General discussion of the MCP motion controller product line
larry
Posts: 5
Joined: Fri Mar 29, 2019 9:17 am

Need help setting PWM input

Postby larry » Fri Mar 29, 2019 9:48 am

Hi,

I have the MCP236 controller, and I would like to control the motor torque (current) using a PWM input signal.
I have a microcontroller (nucleo STM32F103) that is generating a PWM signal at 1khz (1ms period).
In the motion studio, I have tried setting the lowpass anywhere from 2-10. However, I am unsure how to set the min, center, and max values. No matter what values I set, it doesn't seem to work properly.
I send test values of 0.1, 0.5, and 0.9 (duty cycle). I press the set button to calibrate the min, center and max values.
However, the command output (is this the value the controller reads?) does not change accordingly to the input.

Can I please get some help setting up the PWM?
Thanks,
Larry

User avatar
Basicmicro Support
Posts: 1132
Joined: Thu Feb 26, 2015 9:45 pm

Re: Need help setting PWM input

Postby Basicmicro Support » Fri Mar 29, 2019 10:14 am

The pulse clock is 84mhz. Min would be 0(or near zero). Max would be 84mhz*1ms = 84000. Center depends on how you want to use it. For controlling a motor I would set it to 42000. Assuming the pulse amplidtude is high enough(needs to be around 3v or higher) you should see valid readings based on the duty cycle of the pulse after setting the above. In general you shouldnt need to adjust the low pass setting for a PWM signal unless your PWM generation source is particularly noisy.

Note that when duty gets too low(near 0) or too high(near 84000 in this case) the MCP wont be able to read them. I beleive we spec the minimum pulse width in the datasheet.

larry
Posts: 5
Joined: Fri Mar 29, 2019 9:17 am

Re: Need help setting PWM input

Postby larry » Sat Mar 30, 2019 9:56 pm

Hi,

Thanks for the reply.
Using the values 0, 42000, and 84000 I got the command to read a value that looks good.
However, now I am having an issue getting the value to do anything. The mode options are: "position", "percent", "instant velocity", and "average velocity". None of these control the motor current.
And even when I select the position mode, it doesn't work properly:
I select mode 'position', min is -32767, max is 32767, and the check box for control motor 1 is selected.
I send pwm value of 0.1, 0.5, 0.9. When sending 0.5, the motor doesn't move to the middle. It does move to the edges with 0.1 and 0.9.
Furthermore, if it sometimes stops responding to the commands to move, and just doesn't move. I don't think it it timing out, since I have that set to 1000 ms, and my PWM signal has a duty cycle of 1ms.

How can I make the PWM input control the motor current?

Thanks,
Larry

User avatar
Basicmicro Support
Posts: 1132
Joined: Thu Feb 26, 2015 9:45 pm

Re: Need help setting PWM input

Postby Basicmicro Support » Mon Apr 01, 2019 9:31 am

1. Make sure the Command value range when you move through your full PWM range is -32767 to +32767
2. Check the Control motor# check box appropriate for your setup(eg to select which motor will be controlled by that input).

Timeout should be set to a larger value than your update rate. The value is in milliseconds so 1000(1 second) should be plenty.

This setup doesnt control motor position. It controls motor POWER. A center PWM will stop the motor. If a lower PWM duty is sent the motor will move in reverse(at different speeds depening on how low and what the load is) and if the PWM is higher than the center duty the motor will move forward.

This is just to confirm the PWM input is working. Based on your description is sounds like it is.

Note that if you are using a linear actuator when it moves all the way to the ends the actuator may have a builtin cutout that prevents damaging the actuator.

You are confusing current control with position control . It is not the same thing. Also you are not actually using current control, but voltage control(but they both result in similar actions). Neither voltage control or current control will give you position control. Just forward,reverse and stop like a car). For position control you must have an encoder on your motor/actuator for position feedback.

larry
Posts: 5
Joined: Fri Mar 29, 2019 9:17 am

Re: Need help setting PWM input

Postby larry » Mon Apr 01, 2019 1:41 pm

Hi,

I figured out a solution to my problem. I have to disable the encoder for the motor, for it to be 'current/voltage' control. I had an encoder connected to the motor controller, and had MCP configured to use it. This is not very intuitive and not explained anywhere in your manual.

In the PWM settings, there is a resistance and inductance setting which I configured. Since this is configured, does that mean that MCP is doing closed loop current control? Or do I have to do some other non-intuitive actions in the UI?

A motor can be modeled as a resistor, inductor, and a back emf voltage. This is a first order differential equation. Setting the voltage will make the current exponentially go towards a certain value. Having closed loop current control allows you to reach this value faster, and have disturbance rejection.

User avatar
Basicmicro Support
Posts: 1132
Joined: Thu Feb 26, 2015 9:45 pm

Re: Need help setting PWM input

Postby Basicmicro Support » Tue Apr 02, 2019 10:11 am

Ok. I think I know the problem.

1. You have setup the motor to use the PID controller with encoders. It doesnt actually matter that you have the encoder "attached" to the motor. It matters that you have setup values in the PID settings for that motor.

2. You have setup another input to control the motor(eg a PWM input.

Because of the above the motor will try to use Velocity/Position control when you send a PWM signal to the motor control input. You can disable this by simple changing the Encoder channel defined for that particular motor to not use an I/O input(eg the drop down for the motor encoder in General Settings).

Alternatively you can zero the PID settings for that motor which will also cause the controller to go back to Duty control mode.

When you set the R and L settings the motor will use Current Control mode(directly when not setup for PID control or indirectly when setup for PID control).

One thing to keep in mind when using current control(not with a velocity or position control PID), if the load is incapable of loading the motor down enough to cause the motor to draw the current requested the motor will end up accelerating to maximum speed. This does NOT happen with voltage control. So yes there are some advantages to current control but ther is also at least one fairly bad disadvantage.

Also note that if your are using PID control for Velocity and/or Position control as long as the PID is tuned well you will get the same performance out of the motor whether you are using voltage or current control on the motor. Basically the motor has absolute limits on what it can do. If the PID is tuned well those limits will be reached whether you are using current or voltage control so the motor specifications become the limiting factor on what it can do, not the control method.

Keep in mind the voltage being sent to the motor isnt changing(eg it outputs basically the main battery voltage). Only the time percentage it is being sent is changing. The current rises based on the L/R time constant over the pulse period. If the controller was outputing an actual variable voltage then the current rise time would be more like what you are describing(eg slower current rise at lower voltages). The current rise time is actually modeled as exponential decay(eg very fast rise initial with a tappering off asymtotically to the tager current for the given resistance/voltage).


Return to “General Discussion”

Who is online

Users browsing this forum: No registered users and 0 guests