Sign in to follow this  
Followers 0
Nolan

Software PWM vs. Servo Library

9 posts in this topic

I am using an MSP430fr5969. The board only has one hardware pwm available and it located on P1.2. 

 

For my application, I need to generate two different pwm signals to control two different motors. One of those is a servo, the other is a linear actuator but it is controlled through a motor speed controller that uses a pwm input (replicating that of an RC receiver). 

 

Can I use the servo library and attach a servo to any pin or does that pin have to have hardware pwm? I looked through the Servo.cpp file and it seems to be doing software serial.

 

When i run servo examples, and hook the pin up to an oscilloscope I do not get nice square waves being generated as an output. Currently I am using pin 9, the defualt for the servo libraries.

 

Thanks,

Nolan

Share this post


Link to post
Share on other sites

If I am not mistaken the servo library does use software PWM.

You could make hardware PWM though I am not sure it would be able to get down to 50Hz at full clock speed (at 16Mhz), I am not familiar with the MSP430 timers. Give it a try, as abecedarian said, the board has plenty of PWM outputs.

abecedarian likes this

Share this post


Link to post
Share on other sites

Where does it say that? I only see the one pin labeled PWM (pin 19). 

 

Will the servo library work on a motor controller that uses pwm but is not a 0-180 servo?

Find the purple things.

 

LaunchPad-with-MSP430FR5969.jpg

Share this post


Link to post
Share on other sites

Find the purple things.

 

LaunchPad-with-MSP430FR5969.jpg

Oh, ok. So you are referring to software pwm as well. Maybe I have an error in my pwm values somewhere else. I tried using analogWrite() but it was not generating results on my motors. When i used a rc receiver the motor preformed fine. 

Share this post


Link to post
Share on other sites

The purple things should be fine with analog outputs, a.k.a. PWM.

 

Maybe I should have asked you first, your board shows in the Energia list and you have selected that?

Share this post


Link to post
Share on other sites

The purple things should be fine with analog outputs, a.k.a. PWM.

 

Maybe I should have asked you first, your board shows in the Energia list and you have selected that?

 

Yes, I can upload code to the board fine. I have used the servo sweep example in the past. It moves the servo back and forth but it is very jumpy.

 

As for the motor controller (https://www.pololu.com/product/1373/specs) I am trying to connect the RC control pin on the motor controller to the output of an analogWrite() pin on the MSP430 board. The controller will not even allow me to run because it determines it has a fault of the pwm signal coming it. The error is that the pwm signal has to large of a range (it is jumping between 30 and 3604. This is with me only using one value in the analogWrite() function and not varying it at all in the code. 

Share this post


Link to post
Share on other sites

Servos need their PWM not only to have a given duty cycle, but they also need a specified frequency (typically 50hz or 100hz). This fairly easy to do via the Timer system, and is much easier to debug without the abstractions of the AnalogWrite libraries. (IOW, coding against the registers is easier here)

Just make sure you test each step of the timing with your scope. Make sure your source clock is the frequency you think it is, then make sure the CCR has the right frequency, and then confirm your duty cycle. (Sounds like a lot of work, but is much faster one step at a time rather than writing it all at once and wondering where in the chain something went wrong.)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0