SRVCTL - Sets period required to handle a servo motor, - Provides a APIs to move the servo motor in order to change car direction.

Dependents:   frdm_MasterVehicle

Committer:
JalilChavez
Date:
Tue Oct 14 03:52:35 2014 +0000
Revision:
0:b0455b6a805a
controller of servo motor;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
JalilChavez 0:b0455b6a805a 1 #include "srvctl.h"
JalilChavez 0:b0455b6a805a 2
JalilChavez 0:b0455b6a805a 3 /**********************************************************************************
JalilChavez 0:b0455b6a805a 4 * Object declaration
JalilChavez 0:b0455b6a805a 5 ***********************************************************************************/
JalilChavez 0:b0455b6a805a 6 PwmOut SRVCTL__xServo(PTD0);
JalilChavez 0:b0455b6a805a 7
JalilChavez 0:b0455b6a805a 8 void SRVCTL_vInit(void)
JalilChavez 0:b0455b6a805a 9 {
JalilChavez 0:b0455b6a805a 10 /* Set the period required to move the servomotor */
JalilChavez 0:b0455b6a805a 11 SRVCTL__xServo.period_ms(SERVO_PERIOD);
JalilChavez 0:b0455b6a805a 12 }
JalilChavez 0:b0455b6a805a 13
JalilChavez 0:b0455b6a805a 14 void SRVCTL_vSetPosition( uint16_t u16PosVal, const uint16_t u16MaxVal )
JalilChavez 0:b0455b6a805a 15 {
JalilChavez 0:b0455b6a805a 16 uint16_t u16PulseWidth = MIDDLE_POINT;
JalilChavez 0:b0455b6a805a 17 /* Adapt value to write into pwm channel */
JalilChavez 0:b0455b6a805a 18 u16PulseWidth = START_POS + ( (FINAL_POS - START_POS) / u16MaxVal ) * (u16PosVal);
JalilChavez 0:b0455b6a805a 19 /* Set duty cycle */
JalilChavez 0:b0455b6a805a 20 SRVCTL__xServo. pulsewidth_us(u16PulseWidth);
JalilChavez 0:b0455b6a805a 21 }