Complete the program below to have a robot move away from a light source. The ro
ID: 2081336 • Letter: C
Question
Complete the program below to have a robot move away from a light source. The robot has two wheels, similar to the robot used in lab, and has a light sensor on each side. See figure below Motor Control Assume that you are programming Timer 1 module A (for left motor) and Timer1 module B (for right motor) to generate PWM waveforms to control the speed of each wheel's motor (note, connect Timer 1 to Port B). The speed of the motor is proportional to the percentage of time the PWM signal is high (i.e. PWM duty cycle). Note: Your PWM wave must have a period of 1.4ms Note the system clock is 16 MHz Light Sensors: The light sensors are connected to Channel 4 (left sensor) and 7 (right sensor) of the ADC as single channel inputs (i.e. not different Robot behavior: The Robot should move away from the light in the following way. Where "Speed of motor" is the fraction of the motor's maximum speed. Speed of left motor Intensity of left sensor (Intensity of left sensor Intensity of right sensor) Speed of right motor Intensity of right sensor (Intensity of left sensor Intensity of right sensor) Turn away from light Front Robot BackExplanation / Answer
void init_TIMER1_A_B ( )
{
unsigned int pulse_period = 16000; //1*0.001*16*1000000
unsigned int pulse_width = pulse_period/2;
SYSCTL_RCGCTIMER_R |= SYSCTL_RCGCTIMER_R1; //sysclk for Timer1
//TIMER A
TIMER1_CTL_R &= ~TIMER_CTL_TAEN; //disable Timer1A
TIMER1_CFG_R |= TIMER_CFG_16_BIT; //set to 16 bit
TIMER1_TAMR_R = 0x0000000A; //set periodic and PWM mode
TIMER1_TAILR_R = pulse_period & 0xFFFF; //lower 16 bits of interval
TIMER1_TAPR_R = pulse_period >> 16; //set 8 bit of interval
TIMER1_TAMATCHR_R = pulse_period – pulse_width; //50% duty cycle
TIMER1_TAPMR_R = (pulse_period – pulse_width) >> 16;
TIMER1_CTL_R |= TIMER_CTL_TAEN; //enable Timer 1A
//TIMER B
TIMER1_CTL_R &= ~TIMER_CTL_TBEN; //disable Timer1B
TIMER1_CFG_R |= TIMER_CFG_16_BIT; //set to 16 bit
TIMER1_TBMR_R = 0x0000000A; //set periodic and PWM mode
TIMER1_TBILR_R = pulse_period & 0xFFFF; //lower 16 bits of interval
TIMER1_TBPR_R = pulse_period >> 16; //set 8 bit of interval
TIMER1_TBMATCHR_R = pulse_period – pulse_width; //50% duty cycle
TIMER1_TBPMR_R = (pulse_period – pulse_width) >> 16;
TIMER1_CTL_R |= TIMER_CTL_TBEN; //enable Timer 1B
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.