There are two libraries listed in mbed:
Also, there is one at URL https://mbed.org/users/johnmc/code/Freescale-Cup-with-FRDM-KL25Z
Of these three, the first one does not have a sample main.cpp. The latter two do.
Which library should I be using because I have seen posts where bugs have been found in these and I am not sure what to be using.
Solved! Go to Solution.
Actually, after reading about servos in general, the above is true to a point. Not all servos are at exactly 90 or 0, depending on your referent at 1.5mS. And the extremes are not necessarily symmetric about the center 1.5mS.
The linkage in the TFC car prevents ever getting close to the extremes. It's also possible to use a different centered pulse width if the servo horn is adjusted for it.
Ok. Thanks. They may be the same; as a new user, it is confusing what source to use since there are different creation dates.
One more question on the main.cpp example. I noticed the max values for the servo were well beyond the range of the servo on my car. I assume each car is different in this regard right?
I think it buzzes because you may just connect your board and servo with 3.3V power(e.x., just connect your FRDM board with a PC). Since, the power of servo should be 4.8V or 6V, it buzzes because of low power.
Another thing I want to mention here is the relation between duty cycle and position. Once time, I found another thread which talked about this, but it's wrong. The TFC code seems like just use range from -45 degrees to 45 degrees (assume the center is 0 degree). That means duty cycle from 5% to 10%. However, the servo has a 180 degree range with the following relation:
Degree Duty Cycle Positive Pulse Time
0 2.5% 0.5ms
45 5% 1ms
90 7.5% 1.5ms
135 10% 2ms
180 12.5% 2.5ms
That should be useful if you want to develop your own servo and motor driver.
Did you power up the FRDM board without the steering horn on the servo? I found that what I thought was center was not, then I found the math error in the servo part of the library.
The horn should stay off the servo until you get the board working and it centers the servo.
No, I did not power up at first. I had to take off the horn and re-adjust everything last night. But even after I fixed everything, I am seeing my steering limits reached with just about +/- 0.3 on the servo calls.
At the top of the TFC.cpp file, there are defines that set the limits of the servo in terms of pulse width.
If you look back in the history here (I can't find it at the moment), I described how I used the buttons and an oscilloscope to generate the official center at 1.5mS, connect the steering linkage, and then find the extremes of the linkage in terms of pulse time. After getting those times, I plugged them back into the defines at the top of TFC.cpp. Once that's done, -1.0 to 1.0 goes from steering limit to steering limit with no servo buzzing.
Here are the final defines I ended up with:
#define FTM1_CLK_PRESCALE 6// Prescale Selector value - see comments in Status Control (SC) section for more details
#define SERVO_DEFAULT_PERIOD (float)(.020) // Desired Frequency of PWM Signal - Here 50Hz => 20ms period
// use these to dial in servo steering to your particular servo
#define SERVO_MIN_PULSE_WIDTH_DEFAULT (float)(.00115) // The number here should be be *pulse width* in seconds to move servo to its left limit
#define SERVO_MAX_PULSE_WIDTH_DEFAULT (float)(.00185) // The number here should be be *pulse width* in seconds to move servo to its left limit
ok. Thx David. I see the code in TFC.cpp now. It turns out I was using a main.cpp from a different library. When I looked at the library that John says I need to use, it does not have all the +/- hard coded 0.7 limits.