16 #define clockwise 319488 //319488 -- starting point 17 #define cclockwise 292096 //292096 -- ending point 18 #define TIMER4B_PRESCALER 50 21 volatile int overflow;
22 volatile int rise_time;
23 volatile int fall_time;
26 volatile float servo_angle;
36 unsigned int pulse_period = period * 16000;
37 unsigned int match = ((period-1.5)*16000);
39 SYSCTL_RCGCTIMER_R |= SYSCTL_RCGCTIMER_R1;
40 TIMER1_CTL_R &= ~TIMER_CTL_TBEN;
42 TIMER1_TBMR_R &= ~0x4;
43 TIMER1_CFG_R |= TIMER_CFG_16_BIT;
44 TIMER1_TBPR_R |= pulse_period>>16;
45 TIMER1_TBILR_R |= pulse_period & 0xFFFF;
46 TIMER1_TBPMR_R |= (match>>16);
47 TIMER1_TBMATCHR_R |= match&0xFFFF;
48 TIMER1_CTL_R |= TIMER_CTL_TBEN;
57 SYSCTL_RCGCTIMER_R |= SYSCTL_RCGCTIMER_R4;
60 TIMER4_CTL_R &= ~(TIMER_CTL_TBEN);
61 TIMER4_CFG_R |= TIMER_CFG_16_BIT;
63 TIMER4_TBMR_R |= TIMER_TBMR_TBMR_PERIOD;
65 TIMER4_TBPR_R |= TIMER4B_PRESCALER - 1;
67 TIMER4_TBILR_R = (int)(16000000/(TIMER4B_PRESCALER * 5));
70 TIMER4_ICR_R = ( TIMER_ICR_TBTOCINT);
71 TIMER4_IMR_R |= ( TIMER_IMR_TBTOIM);
83 TIMER4_CTL_R |= (TIMER_CTL_TBEN);
91 SYSCTL_RCGCGPIO_R|= SYSCTL_RCGCGPIO_R1;
92 GPIO_PORTB_PCTL_R |= GPIO_PCTL_PB5_T1CCP1;
93 GPIO_PORTB_DEN_R &= ~0x20;
94 GPIO_PORTB_DIR_R|= 0x20;
95 GPIO_PORTB_AFSEL_R|=0x20;
96 GPIO_PORTB_DEN_R |= 0x20;
107 TIMER1_TBMATCHR_R = (match & 0xFFFF);
108 TIMER1_TBPMR_R = (match >> 16);
118 double slope = (cclockwise- clockwise)/(180.0);
124 unsigned int match = slope*(degrees) + clockwise;
127 timer_waitMillis(50);
129 servo_angle = degrees;
void match_set(int match)
sets match value
void servo_setAngle(double degrees)
sets the servo angle
the main code for the robot to interact with the user
void timer_init()
initializes the timer for the servo
void clock_timer_init(void)
intializes the clock timer
void servo_init()
initializes the servo motor