Which mbed library should I be using for TFC?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Which mbed library should I be using for TFC?

Jump to solution
2,005 Views
jefff
NXP Employee
NXP Employee

There are two libraries listed in mbed:

Capture.JPG.jpg

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.

0 Kudos
1 Solution
1,607 Views
admin
Specialist II

Use the library by Eli Hughes.  He is making updates and bug fixes. I will delete mine so there is no duplication.

View solution in original post

0 Kudos
12 Replies
1,607 Views
david_dicarlo
NXP Employee
NXP Employee

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.

0 Kudos
1,607 Views
wang-bodong
Contributor I

Exactly. I powered the servo first and set it to use 90 degree as the center, then assembly the gear and put it to chassis. :smileyhappy:

0 Kudos
1,607 Views
admin
Specialist II

I deleted mine so there would be no more ambiguity.

0 Kudos
1,608 Views
admin
Specialist II

Use the library by Eli Hughes.  He is making updates and bug fixes. I will delete mine so there is no duplication.

0 Kudos
1,607 Views
jefff
NXP Employee
NXP Employee

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?

0 Kudos
1,607 Views
admin
Specialist II

It's hard to get it perfectly centered.  You likely no operate the full range of the servo.  Mine hits hard mechanical stops at at about 70%

0 Kudos
1,607 Views
jefff
NXP Employee
NXP Employee

ok. Thx. I was just concerned since 30% is much different than 70%. I thought maybe I had a bad servo - it does buzz sometimes.

0 Kudos
1,607 Views
wang-bodong
Contributor I

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.

0 Kudos
1,607 Views
david_dicarlo
NXP Employee
NXP Employee

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.

0 Kudos
1,607 Views
jefff
NXP Employee
NXP Employee

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.

0 Kudos
1,607 Views
david_dicarlo
NXP Employee
NXP Employee

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

0 Kudos
1,607 Views
jefff
NXP Employee
NXP Employee

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.

0 Kudos